1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = void 0;
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 | var React = _interopRequireWildcard(require("react"));
|
10 | var _utils = require("@mui/utils");
|
11 | var _Tabs = require("../Tabs");
|
12 | var _useCompoundItem = require("../utils/useCompoundItem");
|
13 | var _useList = require("../useList");
|
14 | var _useButton = _interopRequireDefault(require("../useButton"));
|
15 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
16 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17 | function tabValueGenerator(otherTabValues) {
|
18 | return otherTabValues.size;
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function useTab(parameters) {
|
32 | const {
|
33 | value: valueParam,
|
34 | rootRef: externalRef,
|
35 | disabled = false,
|
36 | id: idParam
|
37 | } = parameters;
|
38 | const tabRef = React.useRef(null);
|
39 | const id = (0, _utils.unstable_useId)(idParam);
|
40 | const {
|
41 | value: selectedValue,
|
42 | selectionFollowsFocus,
|
43 | getTabPanelId
|
44 | } = (0, _Tabs.useTabsContext)();
|
45 | const tabMetadata = React.useMemo(() => ({
|
46 | disabled,
|
47 | ref: tabRef,
|
48 | id
|
49 | }), [disabled, tabRef, id]);
|
50 | const {
|
51 | id: value,
|
52 | index,
|
53 | totalItemCount: totalTabsCount
|
54 | } = (0, _useCompoundItem.useCompoundItem)(valueParam != null ? valueParam : tabValueGenerator, tabMetadata);
|
55 | const {
|
56 | getRootProps: getTabProps,
|
57 | rootRef: listItemRefHandler,
|
58 | highlighted,
|
59 | selected
|
60 | } = (0, _useList.useListItem)({
|
61 | item: value
|
62 | });
|
63 | const {
|
64 | getRootProps: getButtonProps,
|
65 | rootRef: buttonRefHandler,
|
66 | active,
|
67 | focusVisible,
|
68 | setFocusVisible
|
69 | } = (0, _useButton.default)({
|
70 | disabled,
|
71 | focusableWhenDisabled: !selectionFollowsFocus,
|
72 | type: 'button'
|
73 | });
|
74 | const handleRef = (0, _utils.unstable_useForkRef)(tabRef, externalRef, listItemRefHandler, buttonRefHandler);
|
75 | const tabPanelId = value !== undefined ? getTabPanelId(value) : undefined;
|
76 | const getRootProps = (otherHandlers = {}) => {
|
77 | const resolvedTabProps = (0, _extends2.default)({}, otherHandlers, getTabProps(otherHandlers));
|
78 | const resolvedButtonProps = (0, _extends2.default)({}, resolvedTabProps, getButtonProps(resolvedTabProps));
|
79 | return (0, _extends2.default)({}, resolvedButtonProps, {
|
80 | role: 'tab',
|
81 | 'aria-controls': tabPanelId,
|
82 | 'aria-selected': selected,
|
83 | id,
|
84 | ref: handleRef
|
85 | });
|
86 | };
|
87 | return {
|
88 | getRootProps,
|
89 | active,
|
90 | focusVisible,
|
91 | highlighted,
|
92 | index,
|
93 | rootRef: handleRef,
|
94 |
|
95 |
|
96 | selected: selected || value === selectedValue,
|
97 | setFocusVisible,
|
98 | totalTabsCount
|
99 | };
|
100 | }
|
101 | var _default = useTab;
|
102 | exports.default = _default; |
\ | No newline at end of file |