1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime-corejs2/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
6 |
|
7 | exports.__esModule = true;
|
8 | exports.default = void 0;
|
9 |
|
10 | var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/extends"));
|
11 |
|
12 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectWithoutPropertiesLoose"));
|
13 |
|
14 | var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inheritsLoose"));
|
15 |
|
16 | var _classnames = _interopRequireDefault(require("classnames"));
|
17 |
|
18 | var _react = _interopRequireWildcard(require("react"));
|
19 |
|
20 | var _elementType = _interopRequireDefault(require("prop-types-extra/lib/elementType"));
|
21 |
|
22 | var _ListGroupItem = _interopRequireDefault(require("./ListGroupItem"));
|
23 |
|
24 | var _bootstrapUtils = require("./utils/bootstrapUtils");
|
25 |
|
26 | var _ValidComponentChildren = _interopRequireDefault(require("./utils/ValidComponentChildren"));
|
27 |
|
28 | var propTypes = {
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | componentClass: _elementType.default
|
36 | };
|
37 |
|
38 | function getDefaultComponent(children) {
|
39 | if (!children) {
|
40 |
|
41 | return 'div';
|
42 | }
|
43 |
|
44 | if (_ValidComponentChildren.default.some(children, function (child) {
|
45 | return child.type !== _ListGroupItem.default || child.props.href || child.props.onClick;
|
46 | })) {
|
47 | return 'div';
|
48 | }
|
49 |
|
50 | return 'ul';
|
51 | }
|
52 |
|
53 | var ListGroup =
|
54 |
|
55 | function (_React$Component) {
|
56 | (0, _inheritsLoose2.default)(ListGroup, _React$Component);
|
57 |
|
58 | function ListGroup() {
|
59 | return _React$Component.apply(this, arguments) || this;
|
60 | }
|
61 |
|
62 | var _proto = ListGroup.prototype;
|
63 |
|
64 | _proto.render = function render() {
|
65 | var _this$props = this.props,
|
66 | children = _this$props.children,
|
67 | _this$props$component = _this$props.componentClass,
|
68 | Component = _this$props$component === void 0 ? getDefaultComponent(children) : _this$props$component,
|
69 | className = _this$props.className,
|
70 | props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["children", "componentClass", "className"]);
|
71 |
|
72 | var _splitBsProps = (0, _bootstrapUtils.splitBsProps)(props),
|
73 | bsProps = _splitBsProps[0],
|
74 | elementProps = _splitBsProps[1];
|
75 |
|
76 | var classes = (0, _bootstrapUtils.getClassSet)(bsProps);
|
77 |
|
78 | var useListItem = Component === 'ul' && _ValidComponentChildren.default.every(children, function (child) {
|
79 | return child.type === _ListGroupItem.default;
|
80 | });
|
81 |
|
82 | return _react.default.createElement(Component, (0, _extends2.default)({}, elementProps, {
|
83 | className: (0, _classnames.default)(className, classes)
|
84 | }), useListItem ? _ValidComponentChildren.default.map(children, function (child) {
|
85 | return (0, _react.cloneElement)(child, {
|
86 | listItem: true
|
87 | });
|
88 | }) : children);
|
89 | };
|
90 |
|
91 | return ListGroup;
|
92 | }(_react.default.Component);
|
93 |
|
94 | ListGroup.propTypes = propTypes;
|
95 |
|
96 | var _default = (0, _bootstrapUtils.bsClass)('list-group', ListGroup);
|
97 |
|
98 | exports.default = _default;
|
99 | module.exports = exports["default"]; |
\ | No newline at end of file |