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