1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["action", "children", "disabled", "onChange", "onClick", "onFocus", "slotProps", "slots", "value"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
9 | import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
10 | import { getTabUtilityClass } from './tabClasses';
|
11 | import { useTab } from '../useTab';
|
12 | import { useSlotProps } from '../utils';
|
13 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
14 | import { jsx as _jsx } from "react/jsx-runtime";
|
15 | const useUtilityClasses = ownerState => {
|
16 | const {
|
17 | selected,
|
18 | disabled
|
19 | } = ownerState;
|
20 | const slots = {
|
21 | root: ['root', selected && 'selected', disabled && 'disabled']
|
22 | };
|
23 | return composeClasses(slots, useClassNamesOverride(getTabUtilityClass));
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | const Tab = React.forwardRef(function Tab(props, forwardedRef) {
|
36 | var _slots$root;
|
37 | const {
|
38 | children,
|
39 | disabled = false,
|
40 | slotProps = {},
|
41 | slots = {},
|
42 | value
|
43 | } = props,
|
44 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
45 | const tabRef = React.useRef();
|
46 | const handleRef = useForkRef(tabRef, forwardedRef);
|
47 | const {
|
48 | active,
|
49 | highlighted,
|
50 | selected,
|
51 | getRootProps
|
52 | } = useTab(_extends({}, props, {
|
53 | rootRef: handleRef,
|
54 | value
|
55 | }));
|
56 | const ownerState = _extends({}, props, {
|
57 | active,
|
58 | disabled,
|
59 | highlighted,
|
60 | selected
|
61 | });
|
62 | const classes = useUtilityClasses(ownerState);
|
63 | const TabRoot = (_slots$root = slots.root) != null ? _slots$root : 'button';
|
64 | const tabRootProps = useSlotProps({
|
65 | elementType: TabRoot,
|
66 | getSlotProps: getRootProps,
|
67 | externalSlotProps: slotProps.root,
|
68 | externalForwardedProps: other,
|
69 | additionalProps: {
|
70 | ref: forwardedRef
|
71 | },
|
72 | ownerState,
|
73 | className: classes.root
|
74 | });
|
75 | return _jsx(TabRoot, _extends({}, tabRootProps, {
|
76 | children: children
|
77 | }));
|
78 | });
|
79 | process.env.NODE_ENV !== "production" ? Tab.propTypes = {
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | |
85 |
|
86 |
|
87 | action: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
88 | current: PropTypes.shape({
|
89 | focusVisible: PropTypes.func.isRequired
|
90 | })
|
91 | })]),
|
92 | |
93 |
|
94 |
|
95 | children: PropTypes.node,
|
96 | |
97 |
|
98 |
|
99 |
|
100 | disabled: PropTypes.bool,
|
101 | |
102 |
|
103 |
|
104 | onChange: PropTypes.func,
|
105 | |
106 |
|
107 |
|
108 |
|
109 | slotProps: PropTypes.shape({
|
110 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
111 | }),
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | slots: PropTypes.shape({
|
118 | root: PropTypes.elementType
|
119 | }),
|
120 | |
121 |
|
122 |
|
123 | value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
124 | } : void 0;
|
125 | export { Tab }; |
\ | No newline at end of file |