1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('prop-types'), require('react')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', 'prop-types', 'react'], factory) :
|
4 | (factory((global.ReactTabs = {}),global.PropTypes,global.React));
|
5 | }(this, (function (exports,PropTypes,React) { 'use strict';
|
6 |
|
7 | PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
|
8 | var React__default = 'default' in React ? React['default'] : React;
|
9 |
|
10 | function isTab(el) {
|
11 | return el.type && el.type.tabsRole === 'Tab';
|
12 | }
|
13 | function isTabPanel(el) {
|
14 | return el.type && el.type.tabsRole === 'TabPanel';
|
15 | }
|
16 | function isTabList(el) {
|
17 | return el.type && el.type.tabsRole === 'TabList';
|
18 | }
|
19 |
|
20 | function _typeof(obj) {
|
21 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
22 | var _typeof = _typeof = function (obj) {
|
23 | return typeof obj;
|
24 | };
|
25 | } else {
|
26 | var _typeof = _typeof = function (obj) {
|
27 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
28 | };
|
29 | }
|
30 |
|
31 | return _typeof(obj);
|
32 | }
|
33 |
|
34 | var _typeof = _typeof;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function _extends() {
|
56 | var _extends = _extends = Object.assign || function (target) {
|
57 | for (var i = 1; i < arguments.length; i++) {
|
58 | var source = arguments[i];
|
59 |
|
60 | for (var key in source) {
|
61 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
62 | target[key] = source[key];
|
63 | }
|
64 | }
|
65 | }
|
66 |
|
67 | return target;
|
68 | };
|
69 |
|
70 | return _extends.apply(this, arguments);
|
71 | }
|
72 |
|
73 | var _extends = _extends;
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | function _inheritsLoose(subClass, superClass) {
|
80 | subClass.prototype = Object.create(superClass.prototype);
|
81 | subClass.prototype.constructor = subClass;
|
82 | subClass.__proto__ = superClass;
|
83 | }
|
84 |
|
85 | var inheritsLoose = _inheritsLoose;
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | function _objectWithoutProperties(source, excluded) {
|
96 | if (source == null) return {};
|
97 | var target = {};
|
98 | var sourceKeys = Object.keys(source);
|
99 | var key, i;
|
100 |
|
101 | for (i = 0; i < sourceKeys.length; i++) {
|
102 | key = sourceKeys[i];
|
103 | if (excluded.indexOf(key) >= 0) continue;
|
104 | target[key] = source[key];
|
105 | }
|
106 |
|
107 | if (Object.getOwnPropertySymbols) {
|
108 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
109 |
|
110 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
111 | key = sourceSymbolKeys[i];
|
112 | if (excluded.indexOf(key) >= 0) continue;
|
113 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
114 | target[key] = source[key];
|
115 | }
|
116 | }
|
117 |
|
118 | return target;
|
119 | }
|
120 |
|
121 | var objectWithoutProperties = _objectWithoutProperties;
|
122 |
|
123 | function isTabChild(child) {
|
124 | return isTab(child) || isTabList(child) || isTabPanel(child);
|
125 | }
|
126 |
|
127 | function deepMap(children, callback) {
|
128 | return React.Children.map(children, function (child) {
|
129 |
|
130 |
|
131 | if (child === null) return null;
|
132 |
|
133 | if (isTabChild(child)) {
|
134 | return callback(child);
|
135 | }
|
136 |
|
137 | if (child.props && child.props.children && _typeof(child.props.children) === 'object') {
|
138 |
|
139 | return React.cloneElement(child, _extends({}, child.props, {
|
140 | children: deepMap(child.props.children, callback)
|
141 | }));
|
142 | }
|
143 |
|
144 | return child;
|
145 | });
|
146 | }
|
147 | function deepForEach(children, callback) {
|
148 | return React.Children.forEach(children, function (child) {
|
149 |
|
150 |
|
151 | if (child === null) return;
|
152 |
|
153 | if (isTab(child) || isTabPanel(child)) {
|
154 | callback(child);
|
155 | } else if (child.props && child.props.children && _typeof(child.props.children) === 'object') {
|
156 | if (isTabList(child)) callback(child);
|
157 | deepForEach(child.props.children, callback);
|
158 | }
|
159 | });
|
160 | }
|
161 |
|
162 | function childrenPropType(props, propName, componentName) {
|
163 | var error;
|
164 | var tabsCount = 0;
|
165 | var panelsCount = 0;
|
166 | var tabListFound = false;
|
167 | var listTabs = [];
|
168 | var children = props[propName];
|
169 | deepForEach(children, function (child) {
|
170 | if (isTabList(child)) {
|
171 | if (child.props && child.props.children && _typeof(child.props.children) === 'object') {
|
172 | deepForEach(child.props.children, function (listChild) {
|
173 | return listTabs.push(listChild);
|
174 | });
|
175 | }
|
176 |
|
177 | if (tabListFound) {
|
178 | error = new Error("Found multiple 'TabList' components inside 'Tabs'. Only one is allowed.");
|
179 | }
|
180 |
|
181 | tabListFound = true;
|
182 | }
|
183 |
|
184 | if (isTab(child)) {
|
185 | if (!tabListFound || listTabs.indexOf(child) === -1) {
|
186 | error = new Error("Found a 'Tab' component outside of the 'TabList' component. 'Tab' components have to be inside the 'TabList' component.");
|
187 | }
|
188 |
|
189 | tabsCount++;
|
190 | } else if (isTabPanel(child)) {
|
191 | panelsCount++;
|
192 | }
|
193 | });
|
194 |
|
195 | if (!error && tabsCount !== panelsCount) {
|
196 | error = new Error("There should be an equal number of 'Tab' and 'TabPanel' in `" + componentName + "`." + ("Received " + tabsCount + " 'Tab' and " + panelsCount + " 'TabPanel'."));
|
197 | }
|
198 |
|
199 | return error;
|
200 | }
|
201 | function onSelectPropType(props, propName, componentName, location, propFullName) {
|
202 | var prop = props[propName];
|
203 | var name = propFullName || propName;
|
204 | var error = null;
|
205 |
|
206 | if (prop && typeof prop !== 'function') {
|
207 | error = new Error("Invalid " + location + " `" + name + "` of type `" + _typeof(prop) + "` supplied to `" + componentName + "`, expected `function`.");
|
208 | } else if (props.selectedIndex != null && prop == null) {
|
209 | error = new Error("The " + location + " `" + name + "` is marked as required in `" + componentName + "`, but its value is `undefined` or `null`.\n`onSelect` is required when `selectedIndex` is also set. Not doing so will make the tabs not do anything, as `selectedIndex` indicates that you want to handle the selected tab yourself.\nIf you only want to set the inital tab replace `selectedIndex` with `defaultIndex`.");
|
210 | }
|
211 |
|
212 | return error;
|
213 | }
|
214 | function selectedIndexPropType(props, propName, componentName, location, propFullName) {
|
215 | var prop = props[propName];
|
216 | var name = propFullName || propName;
|
217 | var error = null;
|
218 |
|
219 | if (prop != null && typeof prop !== 'number') {
|
220 | error = new Error("Invalid " + location + " `" + name + "` of type `" + _typeof(prop) + "` supplied to `" + componentName + "`, expected `number`.");
|
221 | } else if (props.defaultIndex != null && prop != null) {
|
222 | return new Error("The " + location + " `" + name + "` cannot be used together with `defaultIndex` in `" + componentName + "`.\nEither remove `" + name + "` to let `" + componentName + "` handle the selected tab internally or remove `defaultIndex` to handle it yourself.");
|
223 | }
|
224 |
|
225 | return error;
|
226 | }
|
227 |
|
228 | function createCommonjsModule(fn, module) {
|
229 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
230 | }
|
231 |
|
232 | var classnames = createCommonjsModule(function (module) {
|
233 | |
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 | (function () {
|
241 | var hasOwn = {}.hasOwnProperty;
|
242 |
|
243 | function classNames() {
|
244 | var classes = [];
|
245 |
|
246 | for (var i = 0; i < arguments.length; i++) {
|
247 | var arg = arguments[i];
|
248 | if (!arg) continue;
|
249 | var argType = _typeof(arg);
|
250 |
|
251 | if (argType === 'string' || argType === 'number') {
|
252 | classes.push(arg);
|
253 | } else if (Array.isArray(arg)) {
|
254 | classes.push(classNames.apply(null, arg));
|
255 | } else if (argType === 'object') {
|
256 | for (var key in arg) {
|
257 | if (hasOwn.call(arg, key) && arg[key]) {
|
258 | classes.push(key);
|
259 | }
|
260 | }
|
261 | }
|
262 | }
|
263 |
|
264 | return classes.join(' ');
|
265 | }
|
266 |
|
267 | if ('object' !== 'undefined' && module.exports) {
|
268 | module.exports = classNames;
|
269 | } else if (typeof undefined === 'function' && _typeof(undefined.amd) === 'object' && undefined.amd) {
|
270 |
|
271 | undefined('classnames', [], function () {
|
272 | return classNames;
|
273 | });
|
274 | } else {
|
275 | window.classNames = classNames;
|
276 | }
|
277 | })();
|
278 | });
|
279 |
|
280 |
|
281 | var count = 0;
|
282 | function uuid() {
|
283 | return "react-tabs-" + count++;
|
284 | }
|
285 | function reset() {
|
286 | count = 0;
|
287 | }
|
288 |
|
289 | function getTabsCount(children) {
|
290 | var tabCount = 0;
|
291 | deepForEach(children, function (child) {
|
292 | if (isTab(child)) tabCount++;
|
293 | });
|
294 | return tabCount;
|
295 | }
|
296 | function getPanelsCount(children) {
|
297 | var panelCount = 0;
|
298 | deepForEach(children, function (child) {
|
299 | if (isTabPanel(child)) panelCount++;
|
300 | });
|
301 | return panelCount;
|
302 | }
|
303 |
|
304 | function isTabNode(node) {
|
305 | return 'getAttribute' in node && node.getAttribute('role') === 'tab';
|
306 | }
|
307 |
|
308 |
|
309 | function isTabDisabled(node) {
|
310 | return node.getAttribute('aria-disabled') === 'true';
|
311 | }
|
312 |
|
313 | var canUseActiveElement;
|
314 |
|
315 | try {
|
316 | canUseActiveElement = !!(typeof window !== 'undefined' && window.document && window.document.activeElement);
|
317 | } catch (e) {
|
318 |
|
319 |
|
320 |
|
321 |
|
322 | canUseActiveElement = false;
|
323 | }
|
324 |
|
325 | var UncontrolledTabs =
|
326 |
|
327 | function (_Component) {
|
328 | inheritsLoose(UncontrolledTabs, _Component);
|
329 |
|
330 | function UncontrolledTabs() {
|
331 | var _temp, _this;
|
332 |
|
333 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
334 | args[_key] = arguments[_key];
|
335 | }
|
336 |
|
337 | return (_temp = _this = _Component.call.apply(_Component, [this].concat(args)) || this, _this.tabNodes = [], _this.handleKeyDown = function (e) {
|
338 | if (_this.isTabFromContainer(e.target)) {
|
339 | var index = _this.props.selectedIndex;
|
340 | var preventDefault = false;
|
341 | var useSelectedIndex = false;
|
342 |
|
343 | if (e.keyCode === 32 || e.keyCode === 13) {
|
344 | preventDefault = true;
|
345 | useSelectedIndex = false;
|
346 |
|
347 | _this.handleClick(e);
|
348 | }
|
349 |
|
350 | if (e.keyCode === 37 || e.keyCode === 38) {
|
351 |
|
352 | index = _this.getPrevTab(index);
|
353 | preventDefault = true;
|
354 | useSelectedIndex = true;
|
355 | } else if (e.keyCode === 39 || e.keyCode === 40) {
|
356 |
|
357 | index = _this.getNextTab(index);
|
358 | preventDefault = true;
|
359 | useSelectedIndex = true;
|
360 | }
|
361 |
|
362 |
|
363 | if (preventDefault) {
|
364 | e.preventDefault();
|
365 | }
|
366 |
|
367 |
|
368 | if (useSelectedIndex) {
|
369 | _this.setSelected(index, e);
|
370 | }
|
371 | }
|
372 | }, _this.handleClick = function (e) {
|
373 | var node = e.target;
|
374 |
|
375 | do {
|
376 | if (_this.isTabFromContainer(node)) {
|
377 | if (isTabDisabled(node)) {
|
378 | return;
|
379 | }
|
380 |
|
381 | var index = [].slice.call(node.parentNode.children).filter(isTabNode).indexOf(node);
|
382 |
|
383 | _this.setSelected(index, e);
|
384 |
|
385 | return;
|
386 | }
|
387 | } while ((node = node.parentNode) !== null);
|
388 | }, _temp) || _this;
|
389 | }
|
390 |
|
391 | var _proto = UncontrolledTabs.prototype;
|
392 |
|
393 | _proto.setSelected = function setSelected(index, event) {
|
394 |
|
395 | if (index < 0 || index >= this.getTabsCount()) return;
|
396 |
|
397 | this.props.onSelect(index, this.props.selectedIndex, event);
|
398 | };
|
399 |
|
400 | _proto.getNextTab = function getNextTab(index) {
|
401 | var count = this.getTabsCount();
|
402 |
|
403 | for (var i = index + 1; i < count; i++) {
|
404 | if (!isTabDisabled(this.getTab(i))) {
|
405 | return i;
|
406 | }
|
407 | }
|
408 |
|
409 |
|
410 | for (var _i = 0; _i < index; _i++) {
|
411 | if (!isTabDisabled(this.getTab(_i))) {
|
412 | return _i;
|
413 | }
|
414 | }
|
415 |
|
416 |
|
417 | return index;
|
418 | };
|
419 |
|
420 | _proto.getPrevTab = function getPrevTab(index) {
|
421 | var i = index;
|
422 |
|
423 | while (i--) {
|
424 | if (!isTabDisabled(this.getTab(i))) {
|
425 | return i;
|
426 | }
|
427 | }
|
428 |
|
429 |
|
430 | i = this.getTabsCount();
|
431 |
|
432 | while (i-- > index) {
|
433 | if (!isTabDisabled(this.getTab(i))) {
|
434 | return i;
|
435 | }
|
436 | }
|
437 |
|
438 |
|
439 | return index;
|
440 | };
|
441 |
|
442 | _proto.getTabsCount = function getTabsCount$$1() {
|
443 | return getTabsCount(this.props.children);
|
444 | };
|
445 |
|
446 | _proto.getPanelsCount = function getPanelsCount$$1() {
|
447 | return getPanelsCount(this.props.children);
|
448 | };
|
449 |
|
450 | _proto.getTab = function getTab(index) {
|
451 | return this.tabNodes["tabs-" + index];
|
452 | };
|
453 |
|
454 | _proto.getChildren = function getChildren() {
|
455 | var _this2 = this;
|
456 |
|
457 | var index = 0;
|
458 | var _props = this.props,
|
459 | children = _props.children,
|
460 | disabledTabClassName = _props.disabledTabClassName,
|
461 | focus = _props.focus,
|
462 | forceRenderTabPanel = _props.forceRenderTabPanel,
|
463 | selectedIndex = _props.selectedIndex,
|
464 | selectedTabClassName = _props.selectedTabClassName,
|
465 | selectedTabPanelClassName = _props.selectedTabPanelClassName;
|
466 | this.tabIds = this.tabIds || [];
|
467 | this.panelIds = this.panelIds || [];
|
468 | var diff = this.tabIds.length - this.getTabsCount();
|
469 |
|
470 |
|
471 |
|
472 | while (diff++ < 0) {
|
473 | this.tabIds.push(uuid());
|
474 | this.panelIds.push(uuid());
|
475 | } // Map children to dynamically setup refs
|
476 |
|
477 |
|
478 | return deepMap(children, function (child) {
|
479 | var result = child; // Clone TabList and Tab components to have refs
|
480 |
|
481 | if (isTabList(child)) {
|
482 | var listIndex = 0; // Figure out if the current focus in the DOM is set on a Tab
|
483 | // If it is we should keep the focus on the next selected tab
|
484 |
|
485 | var wasTabFocused = false;
|
486 |
|
487 | if (canUseActiveElement) {
|
488 | wasTabFocused = React__default.Children.toArray(child.props.children).filter(isTab).some(function (tab, i) {
|
489 | return document.activeElement === _this2.getTab(i);
|
490 | });
|
491 | }
|
492 |
|
493 | result = React.cloneElement(child, {
|
494 | children: deepMap(child.props.children, function (tab) {
|
495 | var key = "tabs-" + listIndex;
|
496 | var selected = selectedIndex === listIndex;
|
497 | var props = {
|
498 | tabRef: function tabRef(node) {
|
499 | _this2.tabNodes[key] = node;
|
500 | },
|
501 | id: _this2.tabIds[listIndex],
|
502 | panelId: _this2.panelIds[listIndex],
|
503 | selected: selected,
|
504 | focus: selected && (focus || wasTabFocused)
|
505 | };
|
506 | if (selectedTabClassName) props.selectedClassName = selectedTabClassName;
|
507 | if (disabledTabClassName) props.disabledClassName = disabledTabClassName;
|
508 | listIndex++;
|
509 | return React.cloneElement(tab, props);
|
510 | })
|
511 | });
|
512 | } else if (isTabPanel(child)) {
|
513 | var props = {
|
514 | id: _this2.panelIds[index],
|
515 | tabId: _this2.tabIds[index],
|
516 | selected: selectedIndex === index
|
517 | };
|
518 | if (forceRenderTabPanel) props.forceRender = forceRenderTabPanel;
|
519 | if (selectedTabPanelClassName) props.selectedClassName = selectedTabPanelClassName;
|
520 | index++;
|
521 | result = React.cloneElement(child, props);
|
522 | }
|
523 |
|
524 | return result;
|
525 | });
|
526 | };
|
527 |
|
528 | /**
|
529 | * Determine if a node from event.target is a Tab element for the current Tabs container.
|
530 | * If the clicked element is not a Tab, it returns false.
|
531 | * If it finds another Tabs container between the Tab and `this`, it returns false.
|
532 | */
|
533 | _proto.isTabFromContainer = function isTabFromContainer(node) {
|
534 | // return immediately if the clicked element is not a Tab.
|
535 | if (!isTabNode(node)) {
|
536 | return false;
|
537 | } // Check if the first occurrence of a Tabs container is `this` one.
|
538 |
|
539 |
|
540 | var nodeAncestor = node.parentElement;
|
541 |
|
542 | do {
|
543 | if (nodeAncestor === this.node) return true;else if (nodeAncestor.getAttribute('data-tabs')) break;
|
544 | nodeAncestor = nodeAncestor.parentElement;
|
545 | } while (nodeAncestor);
|
546 |
|
547 | return false;
|
548 | };
|
549 |
|
550 | _proto.render = function render() {
|
551 | var _this3 = this;
|
552 |
|
553 | // Delete all known props, so they don't get added to DOM
|
554 | var _props2 = this.props,
|
555 | children = _props2.children,
|
556 | className = _props2.className,
|
557 | disabledTabClassName = _props2.disabledTabClassName,
|
558 | domRef = _props2.domRef,
|
559 | focus = _props2.focus,
|
560 | forceRenderTabPanel = _props2.forceRenderTabPanel,
|
561 | onSelect = _props2.onSelect,
|
562 | selectedIndex = _props2.selectedIndex,
|
563 | selectedTabClassName = _props2.selectedTabClassName,
|
564 | selectedTabPanelClassName = _props2.selectedTabPanelClassName,
|
565 | attributes = objectWithoutProperties(_props2, ["children", "className", "disabledTabClassName", "domRef", "focus", "forceRenderTabPanel", "onSelect", "selectedIndex", "selectedTabClassName", "selectedTabPanelClassName"]);
|
566 | return React__default.createElement("div", _extends({}, attributes, {
|
567 | className: classnames(className),
|
568 | onClick: this.handleClick,
|
569 | onKeyDown: this.handleKeyDown,
|
570 | ref: function ref(node) {
|
571 | _this3.node = node;
|
572 | if (domRef) domRef(node);
|
573 | },
|
574 | "data-tabs": true
|
575 | }), this.getChildren());
|
576 | };
|
577 |
|
578 | return UncontrolledTabs;
|
579 | }(React.Component);
|
580 |
|
581 | UncontrolledTabs.defaultProps = {
|
582 | className: 'react-tabs',
|
583 | focus: false
|
584 | };
|
585 | UncontrolledTabs.propTypes = {
|
586 | children: childrenPropType,
|
587 | className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
588 | disabledTabClassName: PropTypes.string,
|
589 | domRef: PropTypes.func,
|
590 | focus: PropTypes.bool,
|
591 | forceRenderTabPanel: PropTypes.bool,
|
592 | onSelect: PropTypes.func.isRequired,
|
593 | selectedIndex: PropTypes.number.isRequired,
|
594 | selectedTabClassName: PropTypes.string,
|
595 | selectedTabPanelClassName: PropTypes.string
|
596 | };
|
597 |
|
598 | var Tabs =
|
599 | /*#__PURE__*/
|
600 | function (_Component) {
|
601 | inheritsLoose(Tabs, _Component);
|
602 |
|
603 | function Tabs(props) {
|
604 | var _this;
|
605 |
|
606 | _this = _Component.call(this, props) || this;
|
607 |
|
608 | _this.handleSelected = function (index, last, event) {
|
609 | // Call change event handler
|
610 | if (typeof _this.props.onSelect === 'function') {
|
611 | // Check if the change event handler cancels the tab change
|
612 | if (_this.props.onSelect(index, last, event) === false) return;
|
613 | }
|
614 |
|
615 | var state = {
|
616 | // Set focus if the change was triggered from the keyboard
|
617 | focus: event.type === 'keydown'
|
618 | };
|
619 |
|
620 | if (Tabs.inUncontrolledMode(_this.props)) {
|
621 | // Update selected index
|
622 | state.selectedIndex = index;
|
623 | }
|
624 |
|
625 | _this.setState(state);
|
626 | };
|
627 |
|
628 | _this.state = Tabs.copyPropsToState(_this.props, {}, _this.props.defaultFocus);
|
629 | return _this;
|
630 | }
|
631 |
|
632 | var _proto = Tabs.prototype;
|
633 |
|
634 | _proto.componentWillReceiveProps = function componentWillReceiveProps(newProps) {
|
635 | if ("development" !== 'production' && Tabs.inUncontrolledMode(newProps) !== Tabs.inUncontrolledMode(this.props)) {
|
636 | throw new Error("Switching between controlled mode (by using `selectedIndex`) and uncontrolled mode is not supported in `Tabs`.\nFor more information about controlled and uncontrolled mode of react-tabs see the README.");
|
637 | } // Use a transactional update to prevent race conditions
|
638 | // when reading the state in copyPropsToState
|
639 | // See https://github.com/reactjs/react-tabs/issues/51
|
640 |
|
641 |
|
642 | this.setState(function (state) {
|
643 | return Tabs.copyPropsToState(newProps, state);
|
644 | });
|
645 | };
|
646 |
|
647 | Tabs.inUncontrolledMode = function inUncontrolledMode(props) {
|
648 | return props.selectedIndex === null;
|
649 | };
|
650 |
|
651 | // preserve the existing selectedIndex from state.
|
652 | // If the state has not selectedIndex, default to the defaultIndex or 0
|
653 | Tabs.copyPropsToState = function copyPropsToState(props, state, focus) {
|
654 | if (focus === void 0) {
|
655 | focus = false;
|
656 | }
|
657 |
|
658 | var newState = {
|
659 | focus: focus
|
660 | };
|
661 |
|
662 | if (Tabs.inUncontrolledMode(props)) {
|
663 | var maxTabIndex = getTabsCount(props.children) - 1;
|
664 | var selectedIndex = null;
|
665 |
|
666 | if (state.selectedIndex != null) {
|
667 | selectedIndex = Math.min(state.selectedIndex, maxTabIndex);
|
668 | } else {
|
669 | selectedIndex = props.defaultIndex || 0;
|
670 | }
|
671 |
|
672 | newState.selectedIndex = selectedIndex;
|
673 | }
|
674 |
|
675 | return newState;
|
676 | };
|
677 |
|
678 | _proto.render = function render() {
|
679 | var _props = this.props,
|
680 | children = _props.children,
|
681 | defaultIndex = _props.defaultIndex,
|
682 | defaultFocus = _props.defaultFocus,
|
683 | props = objectWithoutProperties(_props, ["children", "defaultIndex", "defaultFocus"]);
|
684 | props.focus = this.state.focus;
|
685 | props.onSelect = this.handleSelected;
|
686 |
|
687 | if (this.state.selectedIndex != null) {
|
688 | props.selectedIndex = this.state.selectedIndex;
|
689 | }
|
690 |
|
691 | return React__default.createElement(UncontrolledTabs, props, children);
|
692 | };
|
693 |
|
694 | return Tabs;
|
695 | }(React.Component);
|
696 |
|
697 | Tabs.defaultProps = {
|
698 | defaultFocus: false,
|
699 | forceRenderTabPanel: false,
|
700 | selectedIndex: null,
|
701 | defaultIndex: null
|
702 | };
|
703 | Tabs.propTypes = {
|
704 | children: childrenPropType,
|
705 | className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
706 | defaultFocus: PropTypes.bool,
|
707 | defaultIndex: PropTypes.number,
|
708 | disabledTabClassName: PropTypes.string,
|
709 | domRef: PropTypes.func,
|
710 | forceRenderTabPanel: PropTypes.bool,
|
711 | onSelect: onSelectPropType,
|
712 | selectedIndex: selectedIndexPropType,
|
713 | selectedTabClassName: PropTypes.string,
|
714 | selectedTabPanelClassName: PropTypes.string
|
715 | };
|
716 | Tabs.tabsRole = 'Tabs';
|
717 |
|
718 | var TabList =
|
719 | /*#__PURE__*/
|
720 | function (_Component) {
|
721 | inheritsLoose(TabList, _Component);
|
722 |
|
723 | function TabList() {
|
724 | return _Component.apply(this, arguments) || this;
|
725 | }
|
726 |
|
727 | var _proto = TabList.prototype;
|
728 |
|
729 | _proto.render = function render() {
|
730 | var _props = this.props,
|
731 | children = _props.children,
|
732 | className = _props.className,
|
733 | attributes = objectWithoutProperties(_props, ["children", "className"]);
|
734 | return React__default.createElement("ul", _extends({}, attributes, {
|
735 | className: classnames(className),
|
736 | role: "tablist"
|
737 | }), children);
|
738 | };
|
739 |
|
740 | return TabList;
|
741 | }(React.Component);
|
742 |
|
743 | TabList.defaultProps = {
|
744 | className: 'react-tabs__tab-list'
|
745 | };
|
746 | TabList.propTypes = {
|
747 | children: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
748 | className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object])
|
749 | };
|
750 | TabList.tabsRole = 'TabList';
|
751 |
|
752 | var DEFAULT_CLASS = 'react-tabs__tab';
|
753 |
|
754 | var Tab =
|
755 | /*#__PURE__*/
|
756 | function (_Component) {
|
757 | inheritsLoose(Tab, _Component);
|
758 |
|
759 | function Tab() {
|
760 | return _Component.apply(this, arguments) || this;
|
761 | }
|
762 |
|
763 | var _proto = Tab.prototype;
|
764 |
|
765 | _proto.componentDidMount = function componentDidMount() {
|
766 | this.checkFocus();
|
767 | };
|
768 |
|
769 | _proto.componentDidUpdate = function componentDidUpdate() {
|
770 | this.checkFocus();
|
771 | };
|
772 |
|
773 | _proto.checkFocus = function checkFocus() {
|
774 | if (this.props.selected && this.props.focus) {
|
775 | this.node.focus();
|
776 | }
|
777 | };
|
778 |
|
779 | _proto.render = function render() {
|
780 | var _cx,
|
781 | _this = this;
|
782 |
|
783 | var _props = this.props,
|
784 | children = _props.children,
|
785 | className = _props.className,
|
786 | disabled = _props.disabled,
|
787 | disabledClassName = _props.disabledClassName,
|
788 | focus = _props.focus,
|
789 | id = _props.id,
|
790 | panelId = _props.panelId,
|
791 | selected = _props.selected,
|
792 | selectedClassName = _props.selectedClassName,
|
793 | tabIndex = _props.tabIndex,
|
794 | tabRef = _props.tabRef,
|
795 | attributes = objectWithoutProperties(_props, ["children", "className", "disabled", "disabledClassName", "focus", "id", "panelId", "selected", "selectedClassName", "tabIndex", "tabRef"]);
|
796 | return React__default.createElement("li", _extends({}, attributes, {
|
797 | className: classnames(className, (_cx = {}, _cx[selectedClassName] = selected, _cx[disabledClassName] = disabled, _cx)),
|
798 | ref: function ref(node) {
|
799 | _this.node = node;
|
800 | if (tabRef) tabRef(node);
|
801 | },
|
802 | role: "tab",
|
803 | id: id,
|
804 | "aria-selected": selected ? 'true' : 'false',
|
805 | "aria-disabled": disabled ? 'true' : 'false',
|
806 | "aria-controls": panelId,
|
807 | tabIndex: tabIndex || (selected ? '0' : null)
|
808 | }), children);
|
809 | };
|
810 |
|
811 | return Tab;
|
812 | }(React.Component);
|
813 |
|
814 | Tab.defaultProps = {
|
815 | className: DEFAULT_CLASS,
|
816 | disabledClassName: DEFAULT_CLASS + "--disabled",
|
817 | focus: false,
|
818 | id: null,
|
819 | panelId: null,
|
820 | selected: false,
|
821 | selectedClassName: DEFAULT_CLASS + "--selected"
|
822 | };
|
823 | Tab.propTypes = {
|
824 | children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
|
825 | className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
826 | disabled: PropTypes.bool,
|
827 | tabIndex: PropTypes.string,
|
828 | disabledClassName: PropTypes.string,
|
829 | focus: PropTypes.bool,
|
830 | // private
|
831 | id: PropTypes.string,
|
832 | // private
|
833 | panelId: PropTypes.string,
|
834 | // private
|
835 | selected: PropTypes.bool,
|
836 | // private
|
837 | selectedClassName: PropTypes.string,
|
838 | tabRef: PropTypes.func // private
|
839 |
|
840 | };
|
841 | Tab.tabsRole = 'Tab';
|
842 |
|
843 | var DEFAULT_CLASS$1 = 'react-tabs__tab-panel';
|
844 |
|
845 | var TabPanel =
|
846 | /*#__PURE__*/
|
847 | function (_Component) {
|
848 | inheritsLoose(TabPanel, _Component);
|
849 |
|
850 | function TabPanel() {
|
851 | return _Component.apply(this, arguments) || this;
|
852 | }
|
853 |
|
854 | var _proto = TabPanel.prototype;
|
855 |
|
856 | _proto.render = function render() {
|
857 | var _cx;
|
858 |
|
859 | var _props = this.props,
|
860 | children = _props.children,
|
861 | className = _props.className,
|
862 | forceRender = _props.forceRender,
|
863 | id = _props.id,
|
864 | selected = _props.selected,
|
865 | selectedClassName = _props.selectedClassName,
|
866 | tabId = _props.tabId,
|
867 | attributes = objectWithoutProperties(_props, ["children", "className", "forceRender", "id", "selected", "selectedClassName", "tabId"]);
|
868 | return React__default.createElement("div", _extends({}, attributes, {
|
869 | className: classnames(className, (_cx = {}, _cx[selectedClassName] = selected, _cx)),
|
870 | role: "tabpanel",
|
871 | id: id,
|
872 | "aria-labelledby": tabId
|
873 | }), forceRender || selected ? children : null);
|
874 | };
|
875 |
|
876 | return TabPanel;
|
877 | }(React.Component);
|
878 |
|
879 | TabPanel.defaultProps = {
|
880 | className: DEFAULT_CLASS$1,
|
881 | forceRender: false,
|
882 | selectedClassName: DEFAULT_CLASS$1 + "--selected"
|
883 | };
|
884 | TabPanel.propTypes = {
|
885 | children: PropTypes.node,
|
886 | className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
887 | forceRender: PropTypes.bool,
|
888 | id: PropTypes.string,
|
889 | // private
|
890 | selected: PropTypes.bool,
|
891 | // private
|
892 | selectedClassName: PropTypes.string,
|
893 | tabId: PropTypes.string // private
|
894 |
|
895 | };
|
896 | TabPanel.tabsRole = 'TabPanel';
|
897 |
|
898 | exports.Tab = Tab;
|
899 | exports.TabList = TabList;
|
900 | exports.TabPanel = TabPanel;
|
901 | exports.Tabs = Tabs;
|
902 | exports.resetIdCounter = reset;
|
903 |
|
904 | Object.defineProperty(exports, '__esModule', { value: true });
|
905 |
|
906 | })));
|
907 | //# sourceMappingURL=react-tabs.development.js.map
|
908 |
|
\ | No newline at end of file |