1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | var _excluded = ["id", "onSelect", "transition", "mountOnEnter", "unmountOnExit", "children", "activeKey"];
|
4 | import React from 'react';
|
5 | import requiredForA11y from 'prop-types-extra/lib/isRequiredForA11y';
|
6 | import { useUncontrolled } from 'uncontrollable';
|
7 | import Nav from './Nav';
|
8 | import NavLink from './NavLink';
|
9 | import NavItem from './NavItem';
|
10 | import TabContainer from './TabContainer';
|
11 | import TabContent from './TabContent';
|
12 | import TabPane from './TabPane';
|
13 | import { forEach, map } from './ElementChildren';
|
14 | var defaultProps = {
|
15 | variant: 'tabs',
|
16 | mountOnEnter: false,
|
17 | unmountOnExit: false
|
18 | };
|
19 |
|
20 | function getDefaultActiveKey(children) {
|
21 | var defaultActiveKey;
|
22 | forEach(children, function (child) {
|
23 | if (defaultActiveKey == null) {
|
24 | defaultActiveKey = child.props.eventKey;
|
25 | }
|
26 | });
|
27 | return defaultActiveKey;
|
28 | }
|
29 |
|
30 | function renderTab(child) {
|
31 | var _child$props = child.props,
|
32 | title = _child$props.title,
|
33 | eventKey = _child$props.eventKey,
|
34 | disabled = _child$props.disabled,
|
35 | tabClassName = _child$props.tabClassName,
|
36 | id = _child$props.id;
|
37 |
|
38 | if (title == null) {
|
39 | return null;
|
40 | }
|
41 |
|
42 | return React.createElement(NavItem, {
|
43 | as: NavLink,
|
44 | eventKey: eventKey,
|
45 | disabled: disabled,
|
46 | id: id,
|
47 | className: tabClassName
|
48 | }, title);
|
49 | }
|
50 |
|
51 | var Tabs = function Tabs(props) {
|
52 | var _useUncontrolled = useUncontrolled(props, {
|
53 | activeKey: 'onSelect'
|
54 | }),
|
55 | id = _useUncontrolled.id,
|
56 | onSelect = _useUncontrolled.onSelect,
|
57 | transition = _useUncontrolled.transition,
|
58 | mountOnEnter = _useUncontrolled.mountOnEnter,
|
59 | unmountOnExit = _useUncontrolled.unmountOnExit,
|
60 | children = _useUncontrolled.children,
|
61 | _useUncontrolled$acti = _useUncontrolled.activeKey,
|
62 | activeKey = _useUncontrolled$acti === void 0 ? getDefaultActiveKey(children) : _useUncontrolled$acti,
|
63 | controlledProps = _objectWithoutPropertiesLoose(_useUncontrolled, _excluded);
|
64 |
|
65 | return React.createElement(TabContainer, {
|
66 | id: id,
|
67 | activeKey: activeKey,
|
68 | onSelect: onSelect,
|
69 | transition: transition,
|
70 | mountOnEnter: mountOnEnter,
|
71 | unmountOnExit: unmountOnExit
|
72 | }, React.createElement(Nav, _extends({}, controlledProps, {
|
73 | role: "tablist",
|
74 | as: "nav"
|
75 | }), map(children, renderTab)), React.createElement(TabContent, null, map(children, function (child) {
|
76 | var childProps = _extends({}, child.props);
|
77 |
|
78 | delete childProps.title;
|
79 | delete childProps.disabled;
|
80 | delete childProps.tabClassName;
|
81 | return React.createElement(TabPane, childProps);
|
82 | })));
|
83 | };
|
84 |
|
85 | Tabs.defaultProps = defaultProps;
|
86 | Tabs.displayName = 'Tabs';
|
87 | export default Tabs; |
\ | No newline at end of file |