1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import * as React from 'react';
|
5 | import { unstable_useId as useId, unstable_useForkRef as useForkRef } from '@mui/utils';
|
6 | import { useTabsContext } from '../Tabs';
|
7 | import { useCompoundItem } from '../useCompound';
|
8 | function tabPanelValueGenerator(otherTabPanelValues) {
|
9 | return otherTabPanelValues.size;
|
10 | }
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function useTabPanel(parameters) {
|
23 | const {
|
24 | value: valueParam,
|
25 | id: idParam,
|
26 | rootRef: externalRef
|
27 | } = parameters;
|
28 | const context = useTabsContext();
|
29 | if (context === null) {
|
30 | throw new Error('No TabContext provided');
|
31 | }
|
32 | const {
|
33 | value: selectedTabValue,
|
34 | getTabId
|
35 | } = context;
|
36 | const id = useId(idParam);
|
37 | const ref = React.useRef(null);
|
38 | const handleRef = useForkRef(ref, externalRef);
|
39 | const metadata = React.useMemo(() => ({
|
40 | id,
|
41 | ref
|
42 | }), [id]);
|
43 | const {
|
44 | id: value
|
45 | } = useCompoundItem(valueParam ?? tabPanelValueGenerator, metadata);
|
46 | const hidden = value !== selectedTabValue;
|
47 | const correspondingTabId = value !== undefined ? getTabId(value) : undefined;
|
48 | const getRootProps = (externalProps = {}) => {
|
49 | return _extends({
|
50 | 'aria-labelledby': correspondingTabId ?? undefined,
|
51 | hidden,
|
52 | id: id ?? undefined
|
53 | }, externalProps, {
|
54 | ref: handleRef
|
55 | });
|
56 | };
|
57 | return {
|
58 | hidden,
|
59 | getRootProps,
|
60 | rootRef: handleRef
|
61 | };
|
62 | }
|
63 | export { useTabPanel }; |
\ | No newline at end of file |