1 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import { unstable_composeClasses as composeClasses } from '@mui/base';
|
8 | import ButtonBase from '../ButtonBase';
|
9 | import capitalize from '../utils/capitalize';
|
10 | import useThemeProps from '../styles/useThemeProps';
|
11 | import styled from '../styles/styled';
|
12 | import unsupportedProp from '../utils/unsupportedProp';
|
13 | import tabClasses, { getTabUtilityClass } from './tabClasses';
|
14 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
15 |
|
16 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
17 | var classes = ownerState.classes,
|
18 | textColor = ownerState.textColor,
|
19 | fullWidth = ownerState.fullWidth,
|
20 | wrapped = ownerState.wrapped,
|
21 | icon = ownerState.icon,
|
22 | label = ownerState.label,
|
23 | selected = ownerState.selected,
|
24 | disabled = ownerState.disabled;
|
25 | var slots = {
|
26 | root: ['root', icon && label && 'labelIcon', "textColor".concat(capitalize(textColor)), fullWidth && 'fullWidth', wrapped && 'wrapped', selected && 'selected', disabled && 'disabled'],
|
27 | iconWrapper: ['iconWrapper']
|
28 | };
|
29 | return composeClasses(slots, getTabUtilityClass, classes);
|
30 | };
|
31 |
|
32 | var TabRoot = styled(ButtonBase, {
|
33 | name: 'MuiTab',
|
34 | slot: 'Root',
|
35 | overridesResolver: function overridesResolver(props, styles) {
|
36 | var ownerState = props.ownerState;
|
37 | return [styles.root, ownerState.label && ownerState.icon && styles.labelIcon, styles["textColor".concat(capitalize(ownerState.textColor))], ownerState.fullWidth && styles.fullWidth, ownerState.wrapped && styles.wrapped];
|
38 | }
|
39 | })(function (_ref) {
|
40 | var _ref3, _ref4, _ref5;
|
41 |
|
42 | var theme = _ref.theme,
|
43 | ownerState = _ref.ownerState;
|
44 | return _extends({}, theme.typography.button, {
|
45 | maxWidth: 360,
|
46 | minWidth: 90,
|
47 | position: 'relative',
|
48 | minHeight: 48,
|
49 | flexShrink: 0,
|
50 | padding: '12px 16px',
|
51 | overflow: 'hidden',
|
52 | whiteSpace: 'normal',
|
53 | textAlign: 'center'
|
54 | }, ownerState.label && {
|
55 | flexDirection: ownerState.iconPosition === 'top' || ownerState.iconPosition === 'bottom' ? 'column' : 'row'
|
56 | }, {
|
57 | lineHeight: 1.25
|
58 | }, ownerState.icon && ownerState.label && _defineProperty({
|
59 | minHeight: 72,
|
60 | paddingTop: 9,
|
61 | paddingBottom: 9
|
62 | }, "& > .".concat(tabClasses.iconWrapper), _extends({}, ownerState.iconPosition === 'top' && {
|
63 | marginBottom: 6
|
64 | }, ownerState.iconPosition === 'bottom' && {
|
65 | marginTop: 6
|
66 | }, ownerState.iconPosition === 'start' && {
|
67 | marginRight: theme.spacing(1)
|
68 | }, ownerState.iconPosition === 'end' && {
|
69 | marginLeft: theme.spacing(1)
|
70 | })), ownerState.textColor === 'inherit' && (_ref3 = {
|
71 | color: 'inherit',
|
72 | opacity: 0.6
|
73 | }, _defineProperty(_ref3, "&.".concat(tabClasses.selected), {
|
74 | opacity: 1
|
75 | }), _defineProperty(_ref3, "&.".concat(tabClasses.disabled), {
|
76 | opacity: (theme.vars || theme).palette.action.disabledOpacity
|
77 | }), _ref3), ownerState.textColor === 'primary' && (_ref4 = {
|
78 | color: (theme.vars || theme).palette.text.secondary
|
79 | }, _defineProperty(_ref4, "&.".concat(tabClasses.selected), {
|
80 | color: (theme.vars || theme).palette.primary.main
|
81 | }), _defineProperty(_ref4, "&.".concat(tabClasses.disabled), {
|
82 | color: (theme.vars || theme).palette.text.disabled
|
83 | }), _ref4), ownerState.textColor === 'secondary' && (_ref5 = {
|
84 | color: (theme.vars || theme).palette.text.secondary
|
85 | }, _defineProperty(_ref5, "&.".concat(tabClasses.selected), {
|
86 | color: (theme.vars || theme).palette.secondary.main
|
87 | }), _defineProperty(_ref5, "&.".concat(tabClasses.disabled), {
|
88 | color: (theme.vars || theme).palette.text.disabled
|
89 | }), _ref5), ownerState.fullWidth && {
|
90 | flexShrink: 1,
|
91 | flexGrow: 1,
|
92 | flexBasis: 0,
|
93 | maxWidth: 'none'
|
94 | }, ownerState.wrapped && {
|
95 | fontSize: theme.typography.pxToRem(12)
|
96 | });
|
97 | });
|
98 | var Tab = React.forwardRef(function Tab(inProps, ref) {
|
99 | var props = useThemeProps({
|
100 | props: inProps,
|
101 | name: 'MuiTab'
|
102 | });
|
103 |
|
104 | var className = props.className,
|
105 | _props$disabled = props.disabled,
|
106 | disabled = _props$disabled === void 0 ? false : _props$disabled,
|
107 | _props$disableFocusRi = props.disableFocusRipple,
|
108 | disableFocusRipple = _props$disableFocusRi === void 0 ? false : _props$disableFocusRi,
|
109 | fullWidth = props.fullWidth,
|
110 | iconProp = props.icon,
|
111 | _props$iconPosition = props.iconPosition,
|
112 | iconPosition = _props$iconPosition === void 0 ? 'top' : _props$iconPosition,
|
113 | indicator = props.indicator,
|
114 | label = props.label,
|
115 | onChange = props.onChange,
|
116 | onClick = props.onClick,
|
117 | onFocus = props.onFocus,
|
118 | selected = props.selected,
|
119 | selectionFollowsFocus = props.selectionFollowsFocus,
|
120 | _props$textColor = props.textColor,
|
121 | textColor = _props$textColor === void 0 ? 'inherit' : _props$textColor,
|
122 | value = props.value,
|
123 | _props$wrapped = props.wrapped,
|
124 | wrapped = _props$wrapped === void 0 ? false : _props$wrapped,
|
125 | other = _objectWithoutProperties(props, ["className", "disabled", "disableFocusRipple", "fullWidth", "icon", "iconPosition", "indicator", "label", "onChange", "onClick", "onFocus", "selected", "selectionFollowsFocus", "textColor", "value", "wrapped"]);
|
126 |
|
127 | var ownerState = _extends({}, props, {
|
128 | disabled: disabled,
|
129 | disableFocusRipple: disableFocusRipple,
|
130 | selected: selected,
|
131 | icon: !!iconProp,
|
132 | iconPosition: iconPosition,
|
133 | label: !!label,
|
134 | fullWidth: fullWidth,
|
135 | textColor: textColor,
|
136 | wrapped: wrapped
|
137 | });
|
138 |
|
139 | var classes = useUtilityClasses(ownerState);
|
140 | var icon = iconProp && label && React.isValidElement(iconProp) ? React.cloneElement(iconProp, {
|
141 | className: clsx(classes.iconWrapper, iconProp.props.className)
|
142 | }) : iconProp;
|
143 |
|
144 | var handleClick = function handleClick(event) {
|
145 | if (!selected && onChange) {
|
146 | onChange(event, value);
|
147 | }
|
148 |
|
149 | if (onClick) {
|
150 | onClick(event);
|
151 | }
|
152 | };
|
153 |
|
154 | var handleFocus = function handleFocus(event) {
|
155 | if (selectionFollowsFocus && !selected && onChange) {
|
156 | onChange(event, value);
|
157 | }
|
158 |
|
159 | if (onFocus) {
|
160 | onFocus(event);
|
161 | }
|
162 | };
|
163 |
|
164 | return _jsxs(TabRoot, _extends({
|
165 | focusRipple: !disableFocusRipple,
|
166 | className: clsx(classes.root, className),
|
167 | ref: ref,
|
168 | role: "tab",
|
169 | "aria-selected": selected,
|
170 | disabled: disabled,
|
171 | onClick: handleClick,
|
172 | onFocus: handleFocus,
|
173 | ownerState: ownerState,
|
174 | tabIndex: selected ? 0 : -1
|
175 | }, other, {
|
176 | children: [iconPosition === 'top' || iconPosition === 'start' ? _jsxs(React.Fragment, {
|
177 | children: [icon, label]
|
178 | }) : _jsxs(React.Fragment, {
|
179 | children: [label, icon]
|
180 | }), indicator]
|
181 | }));
|
182 | });
|
183 | process.env.NODE_ENV !== "production" ? Tab.propTypes
|
184 |
|
185 | = {
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | |
192 |
|
193 |
|
194 |
|
195 | children: unsupportedProp,
|
196 |
|
197 | |
198 |
|
199 |
|
200 | classes: PropTypes.object,
|
201 |
|
202 | |
203 |
|
204 |
|
205 | className: PropTypes.string,
|
206 |
|
207 | |
208 |
|
209 |
|
210 |
|
211 | disabled: PropTypes.bool,
|
212 |
|
213 | |
214 |
|
215 |
|
216 |
|
217 | disableFocusRipple: PropTypes.bool,
|
218 |
|
219 | |
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | disableRipple: PropTypes.bool,
|
227 |
|
228 | |
229 |
|
230 |
|
231 | icon: PropTypes.oneOfType([PropTypes.element, PropTypes.string]),
|
232 |
|
233 | |
234 |
|
235 |
|
236 |
|
237 | iconPosition: PropTypes.oneOf(['bottom', 'end', 'start', 'top']),
|
238 |
|
239 | |
240 |
|
241 |
|
242 | label: PropTypes.node,
|
243 |
|
244 | |
245 |
|
246 |
|
247 | onChange: PropTypes.func,
|
248 |
|
249 | |
250 |
|
251 |
|
252 | onClick: PropTypes.func,
|
253 |
|
254 | |
255 |
|
256 |
|
257 | onFocus: PropTypes.func,
|
258 |
|
259 | |
260 |
|
261 |
|
262 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
263 |
|
264 | |
265 |
|
266 |
|
267 | value: PropTypes.any,
|
268 |
|
269 | |
270 |
|
271 |
|
272 |
|
273 |
|
274 | wrapped: PropTypes.bool
|
275 | } : void 0;
|
276 | export default Tab; |
\ | No newline at end of file |