UNPKG

3.76 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4
5var _extends2 = require('babel-runtime/helpers/extends');
6
7var _extends3 = _interopRequireDefault(_extends2);
8
9var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
10
11var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
12
13var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
14
15var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
16
17var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
18
19var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
20
21var _inherits2 = require('babel-runtime/helpers/inherits');
22
23var _inherits3 = _interopRequireDefault(_inherits2);
24
25var _classnames = require('classnames');
26
27var _classnames2 = _interopRequireDefault(_classnames);
28
29var _react = require('react');
30
31var _react2 = _interopRequireDefault(_react);
32
33var _elementType = require('prop-types-extra/lib/elementType');
34
35var _elementType2 = _interopRequireDefault(_elementType);
36
37var _ListGroupItem = require('./ListGroupItem');
38
39var _ListGroupItem2 = _interopRequireDefault(_ListGroupItem);
40
41var _bootstrapUtils = require('./utils/bootstrapUtils');
42
43var _ValidComponentChildren = require('./utils/ValidComponentChildren');
44
45var _ValidComponentChildren2 = _interopRequireDefault(_ValidComponentChildren);
46
47function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
48
49var propTypes = {
50 /**
51 * You can use a custom element type for this component.
52 *
53 * If not specified, it will be treated as `'li'` if every child is a
54 * non-actionable `<ListGroupItem>`, and `'div'` otherwise.
55 */
56 componentClass: _elementType2.default
57};
58
59function getDefaultComponent(children) {
60 if (!children) {
61 // FIXME: This is the old behavior. Is this right?
62 return 'div';
63 }
64
65 if (_ValidComponentChildren2.default.some(children, function (child) {
66 return child.type !== _ListGroupItem2.default || child.props.href || child.props.onClick;
67 })) {
68 return 'div';
69 }
70
71 return 'ul';
72}
73
74var ListGroup = function (_React$Component) {
75 (0, _inherits3.default)(ListGroup, _React$Component);
76
77 function ListGroup() {
78 (0, _classCallCheck3.default)(this, ListGroup);
79 return (0, _possibleConstructorReturn3.default)(this, _React$Component.apply(this, arguments));
80 }
81
82 ListGroup.prototype.render = function render() {
83 var _props = this.props,
84 children = _props.children,
85 _props$componentClass = _props.componentClass,
86 Component = _props$componentClass === undefined ? getDefaultComponent(children) : _props$componentClass,
87 className = _props.className,
88 props = (0, _objectWithoutProperties3.default)(_props, ['children', 'componentClass', 'className']);
89
90 var _splitBsProps = (0, _bootstrapUtils.splitBsProps)(props),
91 bsProps = _splitBsProps[0],
92 elementProps = _splitBsProps[1];
93
94 var classes = (0, _bootstrapUtils.getClassSet)(bsProps);
95
96 var useListItem = Component === 'ul' && _ValidComponentChildren2.default.every(children, function (child) {
97 return child.type === _ListGroupItem2.default;
98 });
99
100 return _react2.default.createElement(
101 Component,
102 (0, _extends3.default)({}, elementProps, { className: (0, _classnames2.default)(className, classes) }),
103 useListItem ? _ValidComponentChildren2.default.map(children, function (child) {
104 return (0, _react.cloneElement)(child, { listItem: true });
105 }) : children
106 );
107 };
108
109 return ListGroup;
110}(_react2.default.Component);
111
112ListGroup.propTypes = propTypes;
113
114exports.default = (0, _bootstrapUtils.bsClass)('list-group', ListGroup);
115module.exports = exports['default'];
\No newline at end of file