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