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 _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
10 |
|
11 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
12 |
|
13 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
14 |
|
15 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
16 |
|
17 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
18 |
|
19 | var _inherits3 = _interopRequireDefault(_inherits2);
|
20 |
|
21 | var _react = require('react');
|
22 |
|
23 | var _react2 = _interopRequireDefault(_react);
|
24 |
|
25 | var _propTypes = require('prop-types');
|
26 |
|
27 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
28 |
|
29 | var _uncontrollable = require('uncontrollable');
|
30 |
|
31 | var _uncontrollable2 = _interopRequireDefault(_uncontrollable);
|
32 |
|
33 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
34 |
|
35 | var TAB = 'tab';
|
36 | var PANE = 'pane';
|
37 |
|
38 | var idPropType = _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]);
|
39 |
|
40 | var propTypes = {
|
41 | |
42 |
|
43 |
|
44 |
|
45 | id: function id(props) {
|
46 | var error = null;
|
47 |
|
48 | if (!props.generateChildId) {
|
49 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
50 | args[_key - 1] = arguments[_key];
|
51 | }
|
52 |
|
53 | error = idPropType.apply(undefined, [props].concat(args));
|
54 |
|
55 | if (!error && !props.id) {
|
56 | 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');
|
57 | }
|
58 | }
|
59 |
|
60 | return error;
|
61 | },
|
62 |
|
63 |
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | generateChildId: _propTypes2.default.func,
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 | onSelect: _propTypes2.default.func,
|
83 |
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 | activeKey: _propTypes2.default.any
|
90 | };
|
91 |
|
92 | var childContextTypes = {
|
93 | $bs_tabContainer: _propTypes2.default.shape({
|
94 | activeKey: _propTypes2.default.any,
|
95 | onSelect: _propTypes2.default.func.isRequired,
|
96 | getTabId: _propTypes2.default.func.isRequired,
|
97 | getPaneId: _propTypes2.default.func.isRequired
|
98 | })
|
99 | };
|
100 |
|
101 | var TabContainer = function (_React$Component) {
|
102 | (0, _inherits3.default)(TabContainer, _React$Component);
|
103 |
|
104 | function TabContainer() {
|
105 | (0, _classCallCheck3.default)(this, TabContainer);
|
106 | return (0, _possibleConstructorReturn3.default)(this, _React$Component.apply(this, arguments));
|
107 | }
|
108 |
|
109 | TabContainer.prototype.getChildContext = function getChildContext() {
|
110 | var _props = this.props,
|
111 | activeKey = _props.activeKey,
|
112 | onSelect = _props.onSelect,
|
113 | generateChildId = _props.generateChildId,
|
114 | id = _props.id;
|
115 |
|
116 |
|
117 | var getId = generateChildId || function (key, type) {
|
118 | return id ? id + '-' + type + '-' + key : null;
|
119 | };
|
120 |
|
121 | return {
|
122 | $bs_tabContainer: {
|
123 | activeKey: activeKey,
|
124 | onSelect: onSelect,
|
125 | getTabId: function getTabId(key) {
|
126 | return getId(key, TAB);
|
127 | },
|
128 | getPaneId: function getPaneId(key) {
|
129 | return getId(key, PANE);
|
130 | }
|
131 | }
|
132 | };
|
133 | };
|
134 |
|
135 | TabContainer.prototype.render = function render() {
|
136 | var _props2 = this.props,
|
137 | children = _props2.children,
|
138 | props = (0, _objectWithoutProperties3.default)(_props2, ['children']);
|
139 |
|
140 |
|
141 | delete props.generateChildId;
|
142 | delete props.onSelect;
|
143 | delete props.activeKey;
|
144 |
|
145 | return _react2.default.cloneElement(_react2.default.Children.only(children), props);
|
146 | };
|
147 |
|
148 | return TabContainer;
|
149 | }(_react2.default.Component);
|
150 |
|
151 | TabContainer.propTypes = propTypes;
|
152 | TabContainer.childContextTypes = childContextTypes;
|
153 |
|
154 | exports.default = (0, _uncontrollable2.default)(TabContainer, { activeKey: 'onSelect' });
|
155 | module.exports = exports['default']; |
\ | No newline at end of file |