1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 |
|
5 | var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
|
6 |
|
7 | var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
|
8 |
|
9 | var _extends2 = require('babel-runtime/helpers/extends');
|
10 |
|
11 | var _extends3 = _interopRequireDefault(_extends2);
|
12 |
|
13 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
14 |
|
15 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
16 |
|
17 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
18 |
|
19 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
20 |
|
21 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
22 |
|
23 | var _inherits3 = _interopRequireDefault(_inherits2);
|
24 |
|
25 | var _classnames = require('classnames');
|
26 |
|
27 | var _classnames2 = _interopRequireDefault(_classnames);
|
28 |
|
29 | var _propTypes = require('prop-types');
|
30 |
|
31 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
32 |
|
33 | var _react = require('react');
|
34 |
|
35 | var _react2 = _interopRequireDefault(_react);
|
36 |
|
37 | var _uncontrollable = require('uncontrollable');
|
38 |
|
39 | var _uncontrollable2 = _interopRequireDefault(_uncontrollable);
|
40 |
|
41 | var _bootstrapUtils = require('./utils/bootstrapUtils');
|
42 |
|
43 | var _ValidComponentChildren = require('./utils/ValidComponentChildren');
|
44 |
|
45 | var _ValidComponentChildren2 = _interopRequireDefault(_ValidComponentChildren);
|
46 |
|
47 | var _PropTypes = require('./utils/PropTypes');
|
48 |
|
49 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
50 |
|
51 | var propTypes = {
|
52 | accordion: _propTypes2.default.bool,
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | activeKey: _propTypes2.default.any,
|
60 |
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 | onSelect: _propTypes2.default.func,
|
67 |
|
68 | |
69 |
|
70 |
|
71 | role: _propTypes2.default.string,
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | generateChildId: _propTypes2.default.func,
|
84 |
|
85 | |
86 |
|
87 |
|
88 |
|
89 | id: (0, _PropTypes.generatedId)('PanelGroup')
|
90 | };
|
91 |
|
92 | var defaultProps = {
|
93 | accordion: false
|
94 | };
|
95 |
|
96 | var childContextTypes = {
|
97 | $bs_panelGroup: _propTypes2.default.shape({
|
98 | getId: _propTypes2.default.func,
|
99 | headerRole: _propTypes2.default.string,
|
100 | panelRole: _propTypes2.default.string,
|
101 | activeKey: _propTypes2.default.any,
|
102 | onToggle: _propTypes2.default.func
|
103 | })
|
104 | };
|
105 |
|
106 | var PanelGroup = function (_React$Component) {
|
107 | (0, _inherits3.default)(PanelGroup, _React$Component);
|
108 |
|
109 | function PanelGroup(props, context) {
|
110 | (0, _classCallCheck3.default)(this, PanelGroup);
|
111 |
|
112 | var _this = (0, _possibleConstructorReturn3.default)(this, _React$Component.call(this, props, context));
|
113 |
|
114 | _this.handleSelect = _this.handleSelect.bind(_this);
|
115 | return _this;
|
116 | }
|
117 |
|
118 | PanelGroup.prototype.getChildContext = function getChildContext() {
|
119 | var _props = this.props,
|
120 | activeKey = _props.activeKey,
|
121 | accordion = _props.accordion,
|
122 | generateChildId = _props.generateChildId,
|
123 | id = _props.id;
|
124 |
|
125 | var getId = null;
|
126 |
|
127 | if (accordion) {
|
128 | getId = generateChildId || function (key, type) {
|
129 | return id ? id + '-' + type + '-' + key : null;
|
130 | };
|
131 | }
|
132 |
|
133 | return {
|
134 | $bs_panelGroup: (0, _extends3.default)({
|
135 | getId: getId,
|
136 | headerRole: 'tab',
|
137 | panelRole: 'tabpanel'
|
138 | }, accordion && {
|
139 | activeKey: activeKey,
|
140 | onToggle: this.handleSelect
|
141 | })
|
142 | };
|
143 | };
|
144 |
|
145 | PanelGroup.prototype.handleSelect = function handleSelect(key, expanded, e) {
|
146 | if (expanded) {
|
147 | this.props.onSelect(key, e);
|
148 | }
|
149 | };
|
150 |
|
151 | PanelGroup.prototype.render = function render() {
|
152 | var _props2 = this.props,
|
153 | accordion = _props2.accordion,
|
154 | className = _props2.className,
|
155 | children = _props2.children,
|
156 | props = (0, _objectWithoutProperties3.default)(_props2, ['accordion', 'className', 'children']);
|
157 |
|
158 | var _splitBsPropsAndOmit = (0, _bootstrapUtils.splitBsPropsAndOmit)(props, ['onSelect', 'activeKey']),
|
159 | bsProps = _splitBsPropsAndOmit[0],
|
160 | elementProps = _splitBsPropsAndOmit[1];
|
161 |
|
162 | if (accordion) {
|
163 | elementProps.role = elementProps.role || 'tablist';
|
164 | }
|
165 |
|
166 | var classes = (0, _bootstrapUtils.getClassSet)(bsProps);
|
167 |
|
168 | return _react2.default.createElement(
|
169 | 'div',
|
170 | (0, _extends3.default)({}, elementProps, { className: (0, _classnames2.default)(className, classes) }),
|
171 | _ValidComponentChildren2.default.map(children, function (child) {
|
172 | return (0, _react.cloneElement)(child, {
|
173 | bsStyle: child.props.bsStyle || bsProps.bsStyle
|
174 | });
|
175 | })
|
176 | );
|
177 | };
|
178 |
|
179 | return PanelGroup;
|
180 | }(_react2.default.Component);
|
181 |
|
182 | PanelGroup.propTypes = propTypes;
|
183 | PanelGroup.defaultProps = defaultProps;
|
184 | PanelGroup.childContextTypes = childContextTypes;
|
185 |
|
186 | exports.default = (0, _uncontrollable2.default)((0, _bootstrapUtils.bsClass)('panel-group', PanelGroup), {
|
187 | activeKey: 'onSelect'
|
188 | });
|
189 | module.exports = exports['default']; |
\ | No newline at end of file |