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