UNPKG

1.67 kBJavaScriptView Raw
1import React, { useMemo } from 'react';
2import { useUncontrolled } from 'uncontrollable';
3import TabContext from './TabContext';
4import SelectableContext from './SelectableContext';
5
6var TabContainer = function TabContainer(props) {
7 var _useUncontrolled = useUncontrolled(props, {
8 activeKey: 'onSelect'
9 }),
10 id = _useUncontrolled.id,
11 generateCustomChildId = _useUncontrolled.generateChildId,
12 onSelect = _useUncontrolled.onSelect,
13 activeKey = _useUncontrolled.activeKey,
14 transition = _useUncontrolled.transition,
15 mountOnEnter = _useUncontrolled.mountOnEnter,
16 unmountOnExit = _useUncontrolled.unmountOnExit,
17 children = _useUncontrolled.children;
18
19 var generateChildId = useMemo(function () {
20 return generateCustomChildId || function (key, type) {
21 return id ? id + "-" + type + "-" + key : null;
22 };
23 }, [id, generateCustomChildId]);
24 var tabContext = useMemo(function () {
25 return {
26 onSelect: onSelect,
27 activeKey: activeKey,
28 transition: transition,
29 mountOnEnter: mountOnEnter || false,
30 unmountOnExit: unmountOnExit || false,
31 getControlledId: function getControlledId(key) {
32 return generateChildId(key, 'tabpane');
33 },
34 getControllerId: function getControllerId(key) {
35 return generateChildId(key, 'tab');
36 }
37 };
38 }, [onSelect, activeKey, transition, mountOnEnter, unmountOnExit, generateChildId]);
39 return /*#__PURE__*/React.createElement(TabContext.Provider, {
40 value: tabContext
41 }, /*#__PURE__*/React.createElement(SelectableContext.Provider, {
42 value: onSelect || null
43 }, children));
44};
45
46export default TabContainer;
\No newline at end of file