1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
4 |
|
5 | exports.__esModule = true;
|
6 | exports.default = void 0;
|
7 |
|
8 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectWithoutPropertiesLoose"));
|
9 |
|
10 | var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inheritsLoose"));
|
11 |
|
12 | var _react = _interopRequireDefault(require("react"));
|
13 |
|
14 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
15 |
|
16 | var _uncontrollable = _interopRequireDefault(require("uncontrollable"));
|
17 |
|
18 | var TAB = 'tab';
|
19 | var PANE = 'pane';
|
20 |
|
21 | var idPropType = _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]);
|
22 |
|
23 | var propTypes = {
|
24 | |
25 |
|
26 |
|
27 |
|
28 | id: function id(props) {
|
29 | var error = null;
|
30 |
|
31 | if (!props.generateChildId) {
|
32 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
33 | args[_key - 1] = arguments[_key];
|
34 | }
|
35 |
|
36 | error = idPropType.apply(void 0, [props].concat(args));
|
37 |
|
38 | if (!error && !props.id) {
|
39 | error = new Error('In order to properly initialize Tabs in a way that is accessible ' + 'to assistive technologies (such as screen readers) an `id` or a ' + '`generateChildId` prop to TabContainer is required');
|
40 | }
|
41 | }
|
42 |
|
43 | return error;
|
44 | },
|
45 |
|
46 | |
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | generateChildId: _propTypes.default.func,
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 | onSelect: _propTypes.default.func,
|
65 |
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 | activeKey: _propTypes.default.any
|
72 | };
|
73 | var childContextTypes = {
|
74 | $bs_tabContainer: _propTypes.default.shape({
|
75 | activeKey: _propTypes.default.any,
|
76 | onSelect: _propTypes.default.func.isRequired,
|
77 | getTabId: _propTypes.default.func.isRequired,
|
78 | getPaneId: _propTypes.default.func.isRequired
|
79 | })
|
80 | };
|
81 |
|
82 | var TabContainer =
|
83 |
|
84 | function (_React$Component) {
|
85 | (0, _inheritsLoose2.default)(TabContainer, _React$Component);
|
86 |
|
87 | function TabContainer() {
|
88 | return _React$Component.apply(this, arguments) || this;
|
89 | }
|
90 |
|
91 | var _proto = TabContainer.prototype;
|
92 |
|
93 | _proto.getChildContext = function getChildContext() {
|
94 | var _this$props = this.props,
|
95 | activeKey = _this$props.activeKey,
|
96 | onSelect = _this$props.onSelect,
|
97 | generateChildId = _this$props.generateChildId,
|
98 | id = _this$props.id;
|
99 |
|
100 | var getId = generateChildId || function (key, type) {
|
101 | return id ? id + "-" + type + "-" + key : null;
|
102 | };
|
103 |
|
104 | return {
|
105 | $bs_tabContainer: {
|
106 | activeKey: activeKey,
|
107 | onSelect: onSelect,
|
108 | getTabId: function getTabId(key) {
|
109 | return getId(key, TAB);
|
110 | },
|
111 | getPaneId: function getPaneId(key) {
|
112 | return getId(key, PANE);
|
113 | }
|
114 | }
|
115 | };
|
116 | };
|
117 |
|
118 | _proto.render = function render() {
|
119 | var _this$props2 = this.props,
|
120 | children = _this$props2.children,
|
121 | props = (0, _objectWithoutPropertiesLoose2.default)(_this$props2, ["children"]);
|
122 | delete props.generateChildId;
|
123 | delete props.onSelect;
|
124 | delete props.activeKey;
|
125 | return _react.default.cloneElement(_react.default.Children.only(children), props);
|
126 | };
|
127 |
|
128 | return TabContainer;
|
129 | }(_react.default.Component);
|
130 |
|
131 | TabContainer.propTypes = propTypes;
|
132 | TabContainer.childContextTypes = childContextTypes;
|
133 |
|
134 | var _default = (0, _uncontrollable.default)(TabContainer, {
|
135 | activeKey: 'onSelect'
|
136 | });
|
137 |
|
138 | exports.default = _default;
|
139 | module.exports = exports["default"]; |
\ | No newline at end of file |