UNPKG

3.3 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime-corejs2/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
6
7exports.__esModule = true;
8exports.default = void 0;
9
10var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/extends"));
11
12var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectWithoutPropertiesLoose"));
13
14var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inheritsLoose"));
15
16var _classnames = _interopRequireDefault(require("classnames"));
17
18var _react = _interopRequireWildcard(require("react"));
19
20var _elementType = _interopRequireDefault(require("prop-types-extra/lib/elementType"));
21
22var _ListGroupItem = _interopRequireDefault(require("./ListGroupItem"));
23
24var _bootstrapUtils = require("./utils/bootstrapUtils");
25
26var _ValidComponentChildren = _interopRequireDefault(require("./utils/ValidComponentChildren"));
27
28var propTypes = {
29 /**
30 * You can use a custom element type for this component.
31 *
32 * If not specified, it will be treated as `'li'` if every child is a
33 * non-actionable `<ListGroupItem>`, and `'div'` otherwise.
34 */
35 componentClass: _elementType.default
36};
37
38function getDefaultComponent(children) {
39 if (!children) {
40 // FIXME: This is the old behavior. Is this right?
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
53var ListGroup =
54/*#__PURE__*/
55function (_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
94ListGroup.propTypes = propTypes;
95
96var _default = (0, _bootstrapUtils.bsClass)('list-group', ListGroup);
97
98exports.default = _default;
99module.exports = exports["default"];
\No newline at end of file