1 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
2 | import _extends from 'babel-runtime/helpers/extends';
|
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 PropTypes from 'prop-types';
|
8 | import React, { cloneElement } from 'react';
|
9 | import uncontrollable from 'uncontrollable';
|
10 |
|
11 | import { bsClass, getClassSet, splitBsPropsAndOmit } from './utils/bootstrapUtils';
|
12 | import ValidComponentChildren from './utils/ValidComponentChildren';
|
13 | import { generatedId } from './utils/PropTypes';
|
14 |
|
15 | var propTypes = {
|
16 | accordion: PropTypes.bool,
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | activeKey: PropTypes.any,
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 | onSelect: PropTypes.func,
|
31 |
|
32 | |
33 |
|
34 |
|
35 | role: PropTypes.string,
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | generateChildId: PropTypes.func,
|
48 |
|
49 | |
50 |
|
51 |
|
52 |
|
53 | id: generatedId('PanelGroup')
|
54 | };
|
55 |
|
56 | var defaultProps = {
|
57 | accordion: false
|
58 | };
|
59 |
|
60 | var childContextTypes = {
|
61 | $bs_panelGroup: PropTypes.shape({
|
62 | getId: PropTypes.func,
|
63 | headerRole: PropTypes.string,
|
64 | panelRole: PropTypes.string,
|
65 | activeKey: PropTypes.any,
|
66 | onToggle: PropTypes.func
|
67 | })
|
68 | };
|
69 |
|
70 | var PanelGroup = function (_React$Component) {
|
71 | _inherits(PanelGroup, _React$Component);
|
72 |
|
73 | function PanelGroup(props, context) {
|
74 | _classCallCheck(this, PanelGroup);
|
75 |
|
76 | var _this = _possibleConstructorReturn(this, _React$Component.call(this, props, context));
|
77 |
|
78 | _this.handleSelect = _this.handleSelect.bind(_this);
|
79 | return _this;
|
80 | }
|
81 |
|
82 | PanelGroup.prototype.getChildContext = function getChildContext() {
|
83 | var _props = this.props,
|
84 | activeKey = _props.activeKey,
|
85 | accordion = _props.accordion,
|
86 | generateChildId = _props.generateChildId,
|
87 | id = _props.id;
|
88 |
|
89 | var getId = null;
|
90 |
|
91 | if (accordion) {
|
92 | getId = generateChildId || function (key, type) {
|
93 | return id ? id + '-' + type + '-' + key : null;
|
94 | };
|
95 | }
|
96 |
|
97 | return {
|
98 | $bs_panelGroup: _extends({
|
99 | getId: getId,
|
100 | headerRole: 'tab',
|
101 | panelRole: 'tabpanel'
|
102 | }, accordion && {
|
103 | activeKey: activeKey,
|
104 | onToggle: this.handleSelect
|
105 | })
|
106 | };
|
107 | };
|
108 |
|
109 | PanelGroup.prototype.handleSelect = function handleSelect(key, expanded, e) {
|
110 | if (expanded) {
|
111 | this.props.onSelect(key, e);
|
112 | }
|
113 | };
|
114 |
|
115 | PanelGroup.prototype.render = function render() {
|
116 | var _props2 = this.props,
|
117 | accordion = _props2.accordion,
|
118 | className = _props2.className,
|
119 | children = _props2.children,
|
120 | props = _objectWithoutProperties(_props2, ['accordion', 'className', 'children']);
|
121 |
|
122 | var _splitBsPropsAndOmit = splitBsPropsAndOmit(props, ['onSelect', 'activeKey']),
|
123 | bsProps = _splitBsPropsAndOmit[0],
|
124 | elementProps = _splitBsPropsAndOmit[1];
|
125 |
|
126 | if (accordion) {
|
127 | elementProps.role = elementProps.role || 'tablist';
|
128 | }
|
129 |
|
130 | var classes = getClassSet(bsProps);
|
131 |
|
132 | return React.createElement(
|
133 | 'div',
|
134 | _extends({}, elementProps, { className: classNames(className, classes) }),
|
135 | ValidComponentChildren.map(children, function (child) {
|
136 | return cloneElement(child, {
|
137 | bsStyle: child.props.bsStyle || bsProps.bsStyle
|
138 | });
|
139 | })
|
140 | );
|
141 | };
|
142 |
|
143 | return PanelGroup;
|
144 | }(React.Component);
|
145 |
|
146 | PanelGroup.propTypes = propTypes;
|
147 | PanelGroup.defaultProps = defaultProps;
|
148 | PanelGroup.childContextTypes = childContextTypes;
|
149 |
|
150 | export default uncontrollable(bsClass('panel-group', PanelGroup), {
|
151 | activeKey: 'onSelect'
|
152 | }); |
\ | No newline at end of file |