UNPKG

9.17 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3import _extends from "@babel/runtime/helpers/esm/extends";
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import ButtonBase from '../ButtonBase';
9import capitalize from '../utils/capitalize';
10import useThemeProps from '../styles/useThemeProps';
11import styled from '../styles/styled';
12import unsupportedProp from '../utils/unsupportedProp';
13import tabClasses, { getTabUtilityClass } from './tabClasses';
14import { jsxs as _jsxs } from "react/jsx-runtime";
15
16var 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
32var 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});
98var Tab = /*#__PURE__*/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 && /*#__PURE__*/React.isValidElement(iconProp) ? /*#__PURE__*/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 /*#__PURE__*/_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' ? /*#__PURE__*/_jsxs(React.Fragment, {
177 children: [icon, label]
178 }) : /*#__PURE__*/_jsxs(React.Fragment, {
179 children: [label, icon]
180 }), indicator]
181 }));
182});
183process.env.NODE_ENV !== "production" ? Tab.propTypes
184/* remove-proptypes */
185= {
186 // ----------------------------- Warning --------------------------------
187 // | These PropTypes are generated from the TypeScript type definitions |
188 // | To update them edit the d.ts file and run "yarn proptypes" |
189 // ----------------------------------------------------------------------
190
191 /**
192 * This prop isn't supported.
193 * Use the `component` prop if you need to change the children structure.
194 */
195 children: unsupportedProp,
196
197 /**
198 * Override or extend the styles applied to the component.
199 */
200 classes: PropTypes.object,
201
202 /**
203 * @ignore
204 */
205 className: PropTypes.string,
206
207 /**
208 * If `true`, the component is disabled.
209 * @default false
210 */
211 disabled: PropTypes.bool,
212
213 /**
214 * If `true`, the keyboard focus ripple is disabled.
215 * @default false
216 */
217 disableFocusRipple: PropTypes.bool,
218
219 /**
220 * If `true`, the ripple effect is disabled.
221 *
222 * ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
223 * to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
224 * @default false
225 */
226 disableRipple: PropTypes.bool,
227
228 /**
229 * The icon to display.
230 */
231 icon: PropTypes.oneOfType([PropTypes.element, PropTypes.string]),
232
233 /**
234 * The position of the icon relative to the label.
235 * @default 'top'
236 */
237 iconPosition: PropTypes.oneOf(['bottom', 'end', 'start', 'top']),
238
239 /**
240 * The label element.
241 */
242 label: PropTypes.node,
243
244 /**
245 * @ignore
246 */
247 onChange: PropTypes.func,
248
249 /**
250 * @ignore
251 */
252 onClick: PropTypes.func,
253
254 /**
255 * @ignore
256 */
257 onFocus: PropTypes.func,
258
259 /**
260 * The system prop that allows defining system overrides as well as additional CSS styles.
261 */
262 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
263
264 /**
265 * You can provide your own value. Otherwise, we fallback to the child position index.
266 */
267 value: PropTypes.any,
268
269 /**
270 * Tab labels appear in a single row.
271 * They can use a second line if needed.
272 * @default false
273 */
274 wrapped: PropTypes.bool
275} : void 0;
276export default Tab;
\No newline at end of file