UNPKG

1.36 kBJavaScriptView Raw
1import * as React from 'react';
2import TabsContext from '../Tabs/TabsContext';
3import { CompoundComponentContext } from '../utils/useCompound';
4import { jsx as _jsx } from "react/jsx-runtime";
5/**
6 * Sets up the contexts for the underlying Tab and TabPanel components.
7 *
8 * @ignore - do not document.
9 */
10export default function TabsProvider(props) {
11 const {
12 value: valueProp,
13 children
14 } = props;
15 const {
16 direction,
17 getItemIndex,
18 onSelected,
19 orientation,
20 registerItem,
21 registerTabIdLookup,
22 selectionFollowsFocus,
23 totalSubitemCount,
24 value,
25 getTabId,
26 getTabPanelId
27 } = valueProp;
28 const compoundComponentContextValue = React.useMemo(() => ({
29 getItemIndex,
30 registerItem,
31 totalSubitemCount
32 }), [registerItem, getItemIndex, totalSubitemCount]);
33 const tabsContextValue = React.useMemo(() => ({
34 direction,
35 getTabId,
36 getTabPanelId,
37 onSelected,
38 orientation,
39 registerTabIdLookup,
40 selectionFollowsFocus,
41 value
42 }), [direction, getTabId, getTabPanelId, onSelected, orientation, registerTabIdLookup, selectionFollowsFocus, value]);
43 return /*#__PURE__*/_jsx(CompoundComponentContext.Provider, {
44 value: compoundComponentContextValue,
45 children: /*#__PURE__*/_jsx(TabsContext.Provider, {
46 value: tabsContextValue,
47 children: children
48 })
49 });
50}
\No newline at end of file