1 | import * as React from 'react';
|
2 | import { useUncontrolled } from 'uncontrollable';
|
3 | import BaseTabs from '@restart/ui/Tabs';
|
4 | import Nav from './Nav';
|
5 | import NavLink from './NavLink';
|
6 | import NavItem from './NavItem';
|
7 | import TabContent from './TabContent';
|
8 | import TabPane from './TabPane';
|
9 | import { forEach, map } from './ElementChildren';
|
10 | import getTabTransitionComponent from './getTabTransitionComponent';
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
13 | function getDefaultActiveKey(children) {
|
14 | let defaultActiveKey;
|
15 | forEach(children, child => {
|
16 | if (defaultActiveKey == null) {
|
17 | defaultActiveKey = child.props.eventKey;
|
18 | }
|
19 | });
|
20 | return defaultActiveKey;
|
21 | }
|
22 | function renderTab(child) {
|
23 | const {
|
24 | title,
|
25 | eventKey,
|
26 | disabled,
|
27 | tabClassName,
|
28 | tabAttrs,
|
29 | id
|
30 | } = child.props;
|
31 | if (title == null) {
|
32 | return null;
|
33 | }
|
34 | return _jsx(NavItem, {
|
35 | as: "li",
|
36 | role: "presentation",
|
37 | children: _jsx(NavLink, {
|
38 | as: "button",
|
39 | type: "button",
|
40 | eventKey: eventKey,
|
41 | disabled: disabled,
|
42 | id: id,
|
43 | className: tabClassName,
|
44 | ...tabAttrs,
|
45 | children: title
|
46 | })
|
47 | });
|
48 | }
|
49 | const Tabs = props => {
|
50 | const {
|
51 | id,
|
52 | onSelect,
|
53 | transition,
|
54 | mountOnEnter = false,
|
55 | unmountOnExit = false,
|
56 | variant = 'tabs',
|
57 | children,
|
58 | activeKey = getDefaultActiveKey(children),
|
59 | ...controlledProps
|
60 | } = useUncontrolled(props, {
|
61 | activeKey: 'onSelect'
|
62 | });
|
63 | return _jsxs(BaseTabs, {
|
64 | id: id,
|
65 | activeKey: activeKey,
|
66 | onSelect: onSelect,
|
67 | transition: getTabTransitionComponent(transition),
|
68 | mountOnEnter: mountOnEnter,
|
69 | unmountOnExit: unmountOnExit,
|
70 | children: [_jsx(Nav, {
|
71 | ...controlledProps,
|
72 | role: "tablist",
|
73 | as: "ul",
|
74 | variant: variant,
|
75 | children: map(children, renderTab)
|
76 | }), _jsx(TabContent, {
|
77 | children: map(children, child => {
|
78 | const childProps = {
|
79 | ...child.props
|
80 | };
|
81 | delete childProps.title;
|
82 | delete childProps.disabled;
|
83 | delete childProps.tabClassName;
|
84 | delete childProps.tabAttrs;
|
85 | return _jsx(TabPane, {
|
86 | ...childProps
|
87 | });
|
88 | })
|
89 | })]
|
90 | });
|
91 | };
|
92 | Tabs.displayName = 'Tabs';
|
93 | export default Tabs; |
\ | No newline at end of file |