UNPKG

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