1 | import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
|
4 | import classNames from 'classnames';
|
5 | import React, { cloneElement } from 'react';
|
6 | import elementType from 'prop-types-extra/lib/elementType';
|
7 | import ListGroupItem from './ListGroupItem';
|
8 | import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
|
9 | import ValidComponentChildren from './utils/ValidComponentChildren';
|
10 | var propTypes = {
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | componentClass: elementType
|
18 | };
|
19 |
|
20 | function getDefaultComponent(children) {
|
21 | if (!children) {
|
22 |
|
23 | return 'div';
|
24 | }
|
25 |
|
26 | if (ValidComponentChildren.some(children, function (child) {
|
27 | return child.type !== ListGroupItem || child.props.href || child.props.onClick;
|
28 | })) {
|
29 | return 'div';
|
30 | }
|
31 |
|
32 | return 'ul';
|
33 | }
|
34 |
|
35 | var ListGroup =
|
36 |
|
37 | function (_React$Component) {
|
38 | _inheritsLoose(ListGroup, _React$Component);
|
39 |
|
40 | function ListGroup() {
|
41 | return _React$Component.apply(this, arguments) || this;
|
42 | }
|
43 |
|
44 | var _proto = ListGroup.prototype;
|
45 |
|
46 | _proto.render = function render() {
|
47 | var _this$props = this.props,
|
48 | children = _this$props.children,
|
49 | _this$props$component = _this$props.componentClass,
|
50 | Component = _this$props$component === void 0 ? getDefaultComponent(children) : _this$props$component,
|
51 | className = _this$props.className,
|
52 | props = _objectWithoutPropertiesLoose(_this$props, ["children", "componentClass", "className"]);
|
53 |
|
54 | var _splitBsProps = splitBsProps(props),
|
55 | bsProps = _splitBsProps[0],
|
56 | elementProps = _splitBsProps[1];
|
57 |
|
58 | var classes = getClassSet(bsProps);
|
59 | var useListItem = Component === 'ul' && ValidComponentChildren.every(children, function (child) {
|
60 | return child.type === ListGroupItem;
|
61 | });
|
62 | return React.createElement(Component, _extends({}, elementProps, {
|
63 | className: classNames(className, classes)
|
64 | }), useListItem ? ValidComponentChildren.map(children, function (child) {
|
65 | return cloneElement(child, {
|
66 | listItem: true
|
67 | });
|
68 | }) : children);
|
69 | };
|
70 |
|
71 | return ListGroup;
|
72 | }(React.Component);
|
73 |
|
74 | ListGroup.propTypes = propTypes;
|
75 | export default bsClass('list-group', ListGroup); |
\ | No newline at end of file |