1 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
2 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
3 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
4 | import _inherits from 'babel-runtime/helpers/inherits';
|
5 | import React from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import uncontrollable from 'uncontrollable';
|
8 |
|
9 | var TAB = 'tab';
|
10 | var PANE = 'pane';
|
11 |
|
12 | var idPropType = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
|
13 |
|
14 | var propTypes = {
|
15 | |
16 |
|
17 |
|
18 |
|
19 | id: function id(props) {
|
20 | var error = null;
|
21 |
|
22 | if (!props.generateChildId) {
|
23 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
24 | args[_key - 1] = arguments[_key];
|
25 | }
|
26 |
|
27 | error = idPropType.apply(undefined, [props].concat(args));
|
28 |
|
29 | if (!error && !props.id) {
|
30 | 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');
|
31 | }
|
32 | }
|
33 |
|
34 | return error;
|
35 | },
|
36 |
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | generateChildId: PropTypes.func,
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | onSelect: PropTypes.func,
|
57 |
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 | activeKey: PropTypes.any
|
64 | };
|
65 |
|
66 | var childContextTypes = {
|
67 | $bs_tabContainer: PropTypes.shape({
|
68 | activeKey: PropTypes.any,
|
69 | onSelect: PropTypes.func.isRequired,
|
70 | getTabId: PropTypes.func.isRequired,
|
71 | getPaneId: PropTypes.func.isRequired
|
72 | })
|
73 | };
|
74 |
|
75 | var TabContainer = function (_React$Component) {
|
76 | _inherits(TabContainer, _React$Component);
|
77 |
|
78 | function TabContainer() {
|
79 | _classCallCheck(this, TabContainer);
|
80 |
|
81 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
82 | }
|
83 |
|
84 | TabContainer.prototype.getChildContext = function getChildContext() {
|
85 | var _props = this.props,
|
86 | activeKey = _props.activeKey,
|
87 | onSelect = _props.onSelect,
|
88 | generateChildId = _props.generateChildId,
|
89 | id = _props.id;
|
90 |
|
91 |
|
92 | var getId = generateChildId || function (key, type) {
|
93 | return id ? id + '-' + type + '-' + key : null;
|
94 | };
|
95 |
|
96 | return {
|
97 | $bs_tabContainer: {
|
98 | activeKey: activeKey,
|
99 | onSelect: onSelect,
|
100 | getTabId: function getTabId(key) {
|
101 | return getId(key, TAB);
|
102 | },
|
103 | getPaneId: function getPaneId(key) {
|
104 | return getId(key, PANE);
|
105 | }
|
106 | }
|
107 | };
|
108 | };
|
109 |
|
110 | TabContainer.prototype.render = function render() {
|
111 | var _props2 = this.props,
|
112 | children = _props2.children,
|
113 | props = _objectWithoutProperties(_props2, ['children']);
|
114 |
|
115 | delete props.generateChildId;
|
116 | delete props.onSelect;
|
117 | delete props.activeKey;
|
118 |
|
119 | return React.cloneElement(React.Children.only(children), props);
|
120 | };
|
121 |
|
122 | return TabContainer;
|
123 | }(React.Component);
|
124 |
|
125 | TabContainer.propTypes = propTypes;
|
126 | TabContainer.childContextTypes = childContextTypes;
|
127 |
|
128 | export default uncontrollable(TabContainer, { activeKey: 'onSelect' }); |
\ | No newline at end of file |