1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import * as React from 'react';
|
5 | import { unstable_useControlled as useControlled } from '@mui/utils';
|
6 | import { useCompoundParent } from '../useCompound';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function useTabs(parameters) {
|
18 | const {
|
19 | value: valueProp,
|
20 | defaultValue,
|
21 | onChange,
|
22 | orientation = 'horizontal',
|
23 | direction = 'ltr',
|
24 | selectionFollowsFocus = false
|
25 | } = parameters;
|
26 | const [value, setValue] = useControlled({
|
27 | controlled: valueProp,
|
28 | default: defaultValue,
|
29 | name: 'Tabs',
|
30 | state: 'value'
|
31 | });
|
32 | const onSelected = React.useCallback((event, newValue) => {
|
33 | setValue(newValue);
|
34 | onChange == null || onChange(event, newValue);
|
35 | }, [onChange, setValue]);
|
36 | const {
|
37 | subitems: tabPanels,
|
38 | contextValue: compoundComponentContextValue
|
39 | } = useCompoundParent();
|
40 | const tabIdLookup = React.useRef(() => undefined);
|
41 | const getTabPanelId = React.useCallback(tabValue => {
|
42 | var _tabPanels$get;
|
43 | return (_tabPanels$get = tabPanels.get(tabValue)) == null ? void 0 : _tabPanels$get.id;
|
44 | }, [tabPanels]);
|
45 | const getTabId = React.useCallback(tabPanelId => {
|
46 | return tabIdLookup.current(tabPanelId);
|
47 | }, []);
|
48 | const registerTabIdLookup = React.useCallback(lookupFunction => {
|
49 | tabIdLookup.current = lookupFunction;
|
50 | }, []);
|
51 | return {
|
52 | contextValue: _extends({
|
53 | direction,
|
54 | getTabId,
|
55 | getTabPanelId,
|
56 | onSelected,
|
57 | orientation,
|
58 | registerTabIdLookup,
|
59 | selectionFollowsFocus,
|
60 | value
|
61 | }, compoundComponentContextValue)
|
62 | };
|
63 | }
|
64 | export { useTabs }; |
\ | No newline at end of file |