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 | const {
|
37 | children,
|
38 | disabled = false,
|
39 | slotProps = {},
|
40 | slots = {},
|
41 | value
|
42 | } = props,
|
43 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
44 | const tabRef = React.useRef();
|
45 | const handleRef = useForkRef(tabRef, forwardedRef);
|
46 | const {
|
47 | active,
|
48 | highlighted,
|
49 | selected,
|
50 | getRootProps
|
51 | } = useTab(_extends({}, props, {
|
52 | rootRef: handleRef,
|
53 | value
|
54 | }));
|
55 | const ownerState = _extends({}, props, {
|
56 | active,
|
57 | disabled,
|
58 | highlighted,
|
59 | selected
|
60 | });
|
61 | const classes = useUtilityClasses(ownerState);
|
62 | const TabRoot = slots.root ?? 'button';
|
63 | const tabRootProps = useSlotProps({
|
64 | elementType: TabRoot,
|
65 | getSlotProps: getRootProps,
|
66 | externalSlotProps: slotProps.root,
|
67 | externalForwardedProps: other,
|
68 | additionalProps: {
|
69 | ref: forwardedRef
|
70 | },
|
71 | ownerState,
|
72 | className: classes.root
|
73 | });
|
74 | return _jsx(TabRoot, _extends({}, tabRootProps, {
|
75 | children: children
|
76 | }));
|
77 | });
|
78 | process.env.NODE_ENV !== "production" ? Tab.propTypes = {
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | |
84 |
|
85 |
|
86 | action: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
87 | current: PropTypes.shape({
|
88 | focusVisible: PropTypes.func.isRequired
|
89 | })
|
90 | })]),
|
91 | |
92 |
|
93 |
|
94 | children: PropTypes.node,
|
95 | |
96 |
|
97 |
|
98 |
|
99 | disabled: PropTypes.bool,
|
100 | |
101 |
|
102 |
|
103 | onChange: PropTypes.func,
|
104 | |
105 |
|
106 |
|
107 |
|
108 | slotProps: PropTypes.shape({
|
109 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
110 | }),
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 | slots: PropTypes.shape({
|
117 | root: PropTypes.elementType
|
118 | }),
|
119 | |
120 |
|
121 |
|
122 | value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
123 | } : void 0;
|
124 | export { Tab }; |
\ | No newline at end of file |