UNPKG

16.7 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _clsx = _interopRequireDefault(require("clsx"));
13var _resolveProps = _interopRequireDefault(require("@mui/utils/resolveProps"));
14var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
15var _colorManipulator = require("@mui/system/colorManipulator");
16var _rootShouldForwardProp = _interopRequireDefault(require("../styles/rootShouldForwardProp"));
17var _zeroStyled = require("../zero-styled");
18var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
19var _DefaultPropsProvider = require("../DefaultPropsProvider");
20var _ButtonBase = _interopRequireDefault(require("../ButtonBase"));
21var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
22var _createSimplePaletteValueFilter = _interopRequireDefault(require("../utils/createSimplePaletteValueFilter"));
23var _buttonClasses = _interopRequireWildcard(require("./buttonClasses"));
24var _ButtonGroupContext = _interopRequireDefault(require("../ButtonGroup/ButtonGroupContext"));
25var _ButtonGroupButtonContext = _interopRequireDefault(require("../ButtonGroup/ButtonGroupButtonContext"));
26var _jsxRuntime = require("react/jsx-runtime");
27const useUtilityClasses = ownerState => {
28 const {
29 color,
30 disableElevation,
31 fullWidth,
32 size,
33 variant,
34 classes
35 } = ownerState;
36 const slots = {
37 root: ['root', variant, `${variant}${(0, _capitalize.default)(color)}`, `size${(0, _capitalize.default)(size)}`, `${variant}Size${(0, _capitalize.default)(size)}`, `color${(0, _capitalize.default)(color)}`, disableElevation && 'disableElevation', fullWidth && 'fullWidth'],
38 label: ['label'],
39 startIcon: ['icon', 'startIcon', `iconSize${(0, _capitalize.default)(size)}`],
40 endIcon: ['icon', 'endIcon', `iconSize${(0, _capitalize.default)(size)}`]
41 };
42 const composedClasses = (0, _composeClasses.default)(slots, _buttonClasses.getButtonUtilityClass, classes);
43 return {
44 ...classes,
45 // forward the focused, disabled, etc. classes to the ButtonBase
46 ...composedClasses
47 };
48};
49const commonIconStyles = [{
50 props: {
51 size: 'small'
52 },
53 style: {
54 '& > *:nth-of-type(1)': {
55 fontSize: 18
56 }
57 }
58}, {
59 props: {
60 size: 'medium'
61 },
62 style: {
63 '& > *:nth-of-type(1)': {
64 fontSize: 20
65 }
66 }
67}, {
68 props: {
69 size: 'large'
70 },
71 style: {
72 '& > *:nth-of-type(1)': {
73 fontSize: 22
74 }
75 }
76}];
77const ButtonRoot = (0, _zeroStyled.styled)(_ButtonBase.default, {
78 shouldForwardProp: prop => (0, _rootShouldForwardProp.default)(prop) || prop === 'classes',
79 name: 'MuiButton',
80 slot: 'Root',
81 overridesResolver: (props, styles) => {
82 const {
83 ownerState
84 } = props;
85 return [styles.root, styles[ownerState.variant], styles[`${ownerState.variant}${(0, _capitalize.default)(ownerState.color)}`], styles[`size${(0, _capitalize.default)(ownerState.size)}`], styles[`${ownerState.variant}Size${(0, _capitalize.default)(ownerState.size)}`], ownerState.color === 'inherit' && styles.colorInherit, ownerState.disableElevation && styles.disableElevation, ownerState.fullWidth && styles.fullWidth];
86 }
87})((0, _memoTheme.default)(({
88 theme
89}) => {
90 const inheritContainedBackgroundColor = theme.palette.mode === 'light' ? theme.palette.grey[300] : theme.palette.grey[800];
91 const inheritContainedHoverBackgroundColor = theme.palette.mode === 'light' ? theme.palette.grey.A100 : theme.palette.grey[700];
92 return {
93 ...theme.typography.button,
94 minWidth: 64,
95 padding: '6px 16px',
96 border: 0,
97 borderRadius: (theme.vars || theme).shape.borderRadius,
98 transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color', 'color'], {
99 duration: theme.transitions.duration.short
100 }),
101 '&:hover': {
102 textDecoration: 'none'
103 },
104 [`&.${_buttonClasses.default.disabled}`]: {
105 color: (theme.vars || theme).palette.action.disabled
106 },
107 variants: [{
108 props: {
109 variant: 'contained'
110 },
111 style: {
112 color: `var(--variant-containedColor)`,
113 backgroundColor: `var(--variant-containedBg)`,
114 boxShadow: (theme.vars || theme).shadows[2],
115 '&:hover': {
116 boxShadow: (theme.vars || theme).shadows[4],
117 // Reset on touch devices, it doesn't add specificity
118 '@media (hover: none)': {
119 boxShadow: (theme.vars || theme).shadows[2]
120 }
121 },
122 '&:active': {
123 boxShadow: (theme.vars || theme).shadows[8]
124 },
125 [`&.${_buttonClasses.default.focusVisible}`]: {
126 boxShadow: (theme.vars || theme).shadows[6]
127 },
128 [`&.${_buttonClasses.default.disabled}`]: {
129 color: (theme.vars || theme).palette.action.disabled,
130 boxShadow: (theme.vars || theme).shadows[0],
131 backgroundColor: (theme.vars || theme).palette.action.disabledBackground
132 }
133 }
134 }, {
135 props: {
136 variant: 'outlined'
137 },
138 style: {
139 padding: '5px 15px',
140 border: '1px solid currentColor',
141 borderColor: `var(--variant-outlinedBorder, currentColor)`,
142 backgroundColor: `var(--variant-outlinedBg)`,
143 color: `var(--variant-outlinedColor)`,
144 [`&.${_buttonClasses.default.disabled}`]: {
145 border: `1px solid ${(theme.vars || theme).palette.action.disabledBackground}`
146 }
147 }
148 }, {
149 props: {
150 variant: 'text'
151 },
152 style: {
153 padding: '6px 8px',
154 color: `var(--variant-textColor)`,
155 backgroundColor: `var(--variant-textBg)`
156 }
157 }, ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
158 props: {
159 color
160 },
161 style: {
162 '--variant-textColor': (theme.vars || theme).palette[color].main,
163 '--variant-outlinedColor': (theme.vars || theme).palette[color].main,
164 '--variant-outlinedBorder': theme.vars ? `rgba(${theme.vars.palette[color].mainChannel} / 0.5)` : (0, _colorManipulator.alpha)(theme.palette[color].main, 0.5),
165 '--variant-containedColor': (theme.vars || theme).palette[color].contrastText,
166 '--variant-containedBg': (theme.vars || theme).palette[color].main,
167 '@media (hover: hover)': {
168 '&:hover': {
169 '--variant-containedBg': (theme.vars || theme).palette[color].dark,
170 '--variant-textBg': theme.vars ? `rgba(${theme.vars.palette[color].mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : (0, _colorManipulator.alpha)(theme.palette[color].main, theme.palette.action.hoverOpacity),
171 '--variant-outlinedBorder': (theme.vars || theme).palette[color].main,
172 '--variant-outlinedBg': theme.vars ? `rgba(${theme.vars.palette[color].mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : (0, _colorManipulator.alpha)(theme.palette[color].main, theme.palette.action.hoverOpacity)
173 }
174 }
175 }
176 })), {
177 props: {
178 color: 'inherit'
179 },
180 style: {
181 color: 'inherit',
182 borderColor: 'currentColor',
183 '--variant-containedBg': theme.vars ? theme.vars.palette.Button.inheritContainedBg : inheritContainedBackgroundColor,
184 '@media (hover: hover)': {
185 '&:hover': {
186 '--variant-containedBg': theme.vars ? theme.vars.palette.Button.inheritContainedHoverBg : inheritContainedHoverBackgroundColor,
187 '--variant-textBg': theme.vars ? `rgba(${theme.vars.palette.text.primaryChannel} / ${theme.vars.palette.action.hoverOpacity})` : (0, _colorManipulator.alpha)(theme.palette.text.primary, theme.palette.action.hoverOpacity),
188 '--variant-outlinedBg': theme.vars ? `rgba(${theme.vars.palette.text.primaryChannel} / ${theme.vars.palette.action.hoverOpacity})` : (0, _colorManipulator.alpha)(theme.palette.text.primary, theme.palette.action.hoverOpacity)
189 }
190 }
191 }
192 }, {
193 props: {
194 size: 'small',
195 variant: 'text'
196 },
197 style: {
198 padding: '4px 5px',
199 fontSize: theme.typography.pxToRem(13)
200 }
201 }, {
202 props: {
203 size: 'large',
204 variant: 'text'
205 },
206 style: {
207 padding: '8px 11px',
208 fontSize: theme.typography.pxToRem(15)
209 }
210 }, {
211 props: {
212 size: 'small',
213 variant: 'outlined'
214 },
215 style: {
216 padding: '3px 9px',
217 fontSize: theme.typography.pxToRem(13)
218 }
219 }, {
220 props: {
221 size: 'large',
222 variant: 'outlined'
223 },
224 style: {
225 padding: '7px 21px',
226 fontSize: theme.typography.pxToRem(15)
227 }
228 }, {
229 props: {
230 size: 'small',
231 variant: 'contained'
232 },
233 style: {
234 padding: '4px 10px',
235 fontSize: theme.typography.pxToRem(13)
236 }
237 }, {
238 props: {
239 size: 'large',
240 variant: 'contained'
241 },
242 style: {
243 padding: '8px 22px',
244 fontSize: theme.typography.pxToRem(15)
245 }
246 }, {
247 props: {
248 disableElevation: true
249 },
250 style: {
251 boxShadow: 'none',
252 '&:hover': {
253 boxShadow: 'none'
254 },
255 [`&.${_buttonClasses.default.focusVisible}`]: {
256 boxShadow: 'none'
257 },
258 '&:active': {
259 boxShadow: 'none'
260 },
261 [`&.${_buttonClasses.default.disabled}`]: {
262 boxShadow: 'none'
263 }
264 }
265 }, {
266 props: {
267 fullWidth: true
268 },
269 style: {
270 width: '100%'
271 }
272 }]
273 };
274}));
275const ButtonStartIcon = (0, _zeroStyled.styled)('span', {
276 name: 'MuiButton',
277 slot: 'StartIcon',
278 overridesResolver: (props, styles) => {
279 const {
280 ownerState
281 } = props;
282 return [styles.startIcon, styles[`iconSize${(0, _capitalize.default)(ownerState.size)}`]];
283 }
284})({
285 display: 'inherit',
286 marginRight: 8,
287 marginLeft: -4,
288 variants: [{
289 props: {
290 size: 'small'
291 },
292 style: {
293 marginLeft: -2
294 }
295 }, ...commonIconStyles]
296});
297const ButtonEndIcon = (0, _zeroStyled.styled)('span', {
298 name: 'MuiButton',
299 slot: 'EndIcon',
300 overridesResolver: (props, styles) => {
301 const {
302 ownerState
303 } = props;
304 return [styles.endIcon, styles[`iconSize${(0, _capitalize.default)(ownerState.size)}`]];
305 }
306})({
307 display: 'inherit',
308 marginRight: -4,
309 marginLeft: 8,
310 variants: [{
311 props: {
312 size: 'small'
313 },
314 style: {
315 marginRight: -2
316 }
317 }, ...commonIconStyles]
318});
319const Button = /*#__PURE__*/React.forwardRef(function Button(inProps, ref) {
320 // props priority: `inProps` > `contextProps` > `themeDefaultProps`
321 const contextProps = React.useContext(_ButtonGroupContext.default);
322 const buttonGroupButtonContextPositionClassName = React.useContext(_ButtonGroupButtonContext.default);
323 const resolvedProps = (0, _resolveProps.default)(contextProps, inProps);
324 const props = (0, _DefaultPropsProvider.useDefaultProps)({
325 props: resolvedProps,
326 name: 'MuiButton'
327 });
328 const {
329 children,
330 color = 'primary',
331 component = 'button',
332 className,
333 disabled = false,
334 disableElevation = false,
335 disableFocusRipple = false,
336 endIcon: endIconProp,
337 focusVisibleClassName,
338 fullWidth = false,
339 size = 'medium',
340 startIcon: startIconProp,
341 type,
342 variant = 'text',
343 ...other
344 } = props;
345 const ownerState = {
346 ...props,
347 color,
348 component,
349 disabled,
350 disableElevation,
351 disableFocusRipple,
352 fullWidth,
353 size,
354 type,
355 variant
356 };
357 const classes = useUtilityClasses(ownerState);
358 const startIcon = startIconProp && /*#__PURE__*/(0, _jsxRuntime.jsx)(ButtonStartIcon, {
359 className: classes.startIcon,
360 ownerState: ownerState,
361 children: startIconProp
362 });
363 const endIcon = endIconProp && /*#__PURE__*/(0, _jsxRuntime.jsx)(ButtonEndIcon, {
364 className: classes.endIcon,
365 ownerState: ownerState,
366 children: endIconProp
367 });
368 const positionClassName = buttonGroupButtonContextPositionClassName || '';
369 return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ButtonRoot, {
370 ownerState: ownerState,
371 className: (0, _clsx.default)(contextProps.className, classes.root, className, positionClassName),
372 component: component,
373 disabled: disabled,
374 focusRipple: !disableFocusRipple,
375 focusVisibleClassName: (0, _clsx.default)(classes.focusVisible, focusVisibleClassName),
376 ref: ref,
377 type: type,
378 ...other,
379 classes: classes,
380 children: [startIcon, children, endIcon]
381 });
382});
383process.env.NODE_ENV !== "production" ? Button.propTypes /* remove-proptypes */ = {
384 // ┌────────────────────────────── Warning ──────────────────────────────┐
385 // │ These PropTypes are generated from the TypeScript type definitions. │
386 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
387 // └─────────────────────────────────────────────────────────────────────┘
388 /**
389 * The content of the component.
390 */
391 children: _propTypes.default.node,
392 /**
393 * Override or extend the styles applied to the component.
394 */
395 classes: _propTypes.default.object,
396 /**
397 * @ignore
398 */
399 className: _propTypes.default.string,
400 /**
401 * The color of the component.
402 * It supports both default and custom theme colors, which can be added as shown in the
403 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
404 * @default 'primary'
405 */
406 color: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['inherit', 'primary', 'secondary', 'success', 'error', 'info', 'warning']), _propTypes.default.string]),
407 /**
408 * The component used for the root node.
409 * Either a string to use a HTML element or a component.
410 */
411 component: _propTypes.default.elementType,
412 /**
413 * If `true`, the component is disabled.
414 * @default false
415 */
416 disabled: _propTypes.default.bool,
417 /**
418 * If `true`, no elevation is used.
419 * @default false
420 */
421 disableElevation: _propTypes.default.bool,
422 /**
423 * If `true`, the keyboard focus ripple is disabled.
424 * @default false
425 */
426 disableFocusRipple: _propTypes.default.bool,
427 /**
428 * If `true`, the ripple effect is disabled.
429 *
430 * ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
431 * to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
432 * @default false
433 */
434 disableRipple: _propTypes.default.bool,
435 /**
436 * Element placed after the children.
437 */
438 endIcon: _propTypes.default.node,
439 /**
440 * @ignore
441 */
442 focusVisibleClassName: _propTypes.default.string,
443 /**
444 * If `true`, the button will take up the full width of its container.
445 * @default false
446 */
447 fullWidth: _propTypes.default.bool,
448 /**
449 * The URL to link to when the button is clicked.
450 * If defined, an `a` element will be used as the root node.
451 */
452 href: _propTypes.default.string,
453 /**
454 * The size of the component.
455 * `small` is equivalent to the dense button styling.
456 * @default 'medium'
457 */
458 size: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['small', 'medium', 'large']), _propTypes.default.string]),
459 /**
460 * Element placed before the children.
461 */
462 startIcon: _propTypes.default.node,
463 /**
464 * The system prop that allows defining system overrides as well as additional CSS styles.
465 */
466 sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
467 /**
468 * @ignore
469 */
470 type: _propTypes.default.oneOfType([_propTypes.default.oneOf(['button', 'reset', 'submit']), _propTypes.default.string]),
471 /**
472 * The variant to use.
473 * @default 'text'
474 */
475 variant: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['contained', 'outlined', 'text']), _propTypes.default.string])
476} : void 0;
477var _default = exports.default = Button;
\No newline at end of file