1 | import * as React from 'react';
|
2 | import * as PropTypes from 'prop-types';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var Context = React.createContext(null);
|
8 |
|
9 | if (process.env.NODE_ENV !== 'production') {
|
10 | Context.displayName = 'TabContext';
|
11 | }
|
12 |
|
13 | function useUniquePrefix() {
|
14 | var _React$useState = React.useState(null),
|
15 | id = _React$useState[0],
|
16 | setId = _React$useState[1];
|
17 |
|
18 | React.useEffect(function () {
|
19 | setId("mui-p-".concat(Math.round(Math.random() * 1e5)));
|
20 | }, []);
|
21 | return id;
|
22 | }
|
23 |
|
24 | export default function TabContext(props) {
|
25 | var children = props.children,
|
26 | value = props.value;
|
27 | var idPrefix = useUniquePrefix();
|
28 | var context = React.useMemo(function () {
|
29 | return {
|
30 | idPrefix: idPrefix,
|
31 | value: value
|
32 | };
|
33 | }, [idPrefix, value]);
|
34 | return React.createElement(Context.Provider, {
|
35 | value: context
|
36 | }, children);
|
37 | }
|
38 | process.env.NODE_ENV !== "production" ? TabContext.propTypes = {
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | |
45 |
|
46 |
|
47 | children: PropTypes.node,
|
48 |
|
49 | |
50 |
|
51 |
|
52 | value: PropTypes.string.isRequired
|
53 | } : void 0;
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | export function useTabContext() {
|
59 | return React.useContext(Context);
|
60 | }
|
61 | export function getPanelId(context, value) {
|
62 | var idPrefix = context.idPrefix;
|
63 |
|
64 | if (idPrefix === null) {
|
65 | return null;
|
66 | }
|
67 |
|
68 | return "".concat(context.idPrefix, "-P-").concat(value);
|
69 | }
|
70 | export function getTabId(context, value) {
|
71 | var idPrefix = context.idPrefix;
|
72 |
|
73 | if (idPrefix === null) {
|
74 | return null;
|
75 | }
|
76 |
|
77 | return "".concat(context.idPrefix, "-T-").concat(value);
|
78 | } |
\ | No newline at end of file |