UNPKG

9.16 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5import _extends from "@babel/runtime/helpers/esm/extends";
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import clsx from 'clsx';
9import composeClasses from '@mui/utils/composeClasses';
10import ButtonBase from '../ButtonBase';
11import capitalize from '../utils/capitalize';
12import { useDefaultProps } from '../DefaultPropsProvider';
13import fabClasses, { getFabUtilityClass } from './fabClasses';
14import styled, { rootShouldForwardProp } from '../styles/styled';
15import { jsx as _jsx } from "react/jsx-runtime";
16var useUtilityClasses = function useUtilityClasses(ownerState) {
17 var color = ownerState.color,
18 variant = ownerState.variant,
19 classes = ownerState.classes,
20 size = ownerState.size;
21 var slots = {
22 root: ['root', variant, "size".concat(capitalize(size)), color === 'inherit' ? 'colorInherit' : color]
23 };
24 var composedClasses = composeClasses(slots, getFabUtilityClass, classes);
25 return _extends({}, classes, composedClasses);
26};
27var FabRoot = styled(ButtonBase, {
28 name: 'MuiFab',
29 slot: 'Root',
30 shouldForwardProp: function shouldForwardProp(prop) {
31 return rootShouldForwardProp(prop) || prop === 'classes';
32 },
33 overridesResolver: function overridesResolver(props, styles) {
34 var ownerState = props.ownerState;
35 return [styles.root, styles[ownerState.variant], styles["size".concat(capitalize(ownerState.size))], ownerState.color === 'inherit' && styles.colorInherit, styles[capitalize(ownerState.size)], styles[ownerState.color]];
36 }
37})(function (_ref) {
38 var _theme$palette$getCon, _theme$palette;
39 var theme = _ref.theme,
40 ownerState = _ref.ownerState;
41 return _extends({}, theme.typography.button, _defineProperty({
42 minHeight: 36,
43 transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], {
44 duration: theme.transitions.duration.short
45 }),
46 borderRadius: '50%',
47 padding: 0,
48 minWidth: 0,
49 width: 56,
50 height: 56,
51 zIndex: (theme.vars || theme).zIndex.fab,
52 boxShadow: (theme.vars || theme).shadows[6],
53 '&:active': {
54 boxShadow: (theme.vars || theme).shadows[12]
55 },
56 color: theme.vars ? theme.vars.palette.text.primary : (_theme$palette$getCon = (_theme$palette = theme.palette).getContrastText) == null ? void 0 : _theme$palette$getCon.call(_theme$palette, theme.palette.grey[300]),
57 backgroundColor: (theme.vars || theme).palette.grey[300],
58 '&:hover': {
59 backgroundColor: (theme.vars || theme).palette.grey.A100,
60 // Reset on touch devices, it doesn't add specificity
61 '@media (hover: none)': {
62 backgroundColor: (theme.vars || theme).palette.grey[300]
63 },
64 textDecoration: 'none'
65 }
66 }, "&.".concat(fabClasses.focusVisible), {
67 boxShadow: (theme.vars || theme).shadows[6]
68 }), ownerState.size === 'small' && {
69 width: 40,
70 height: 40
71 }, ownerState.size === 'medium' && {
72 width: 48,
73 height: 48
74 }, ownerState.variant === 'extended' && {
75 borderRadius: 48 / 2,
76 padding: '0 16px',
77 width: 'auto',
78 minHeight: 'auto',
79 minWidth: 48,
80 height: 48
81 }, ownerState.variant === 'extended' && ownerState.size === 'small' && {
82 width: 'auto',
83 padding: '0 8px',
84 borderRadius: 34 / 2,
85 minWidth: 34,
86 height: 34
87 }, ownerState.variant === 'extended' && ownerState.size === 'medium' && {
88 width: 'auto',
89 padding: '0 16px',
90 borderRadius: 40 / 2,
91 minWidth: 40,
92 height: 40
93 }, ownerState.color === 'inherit' && {
94 color: 'inherit'
95 });
96}, function (_ref2) {
97 var theme = _ref2.theme,
98 ownerState = _ref2.ownerState;
99 return _extends({}, ownerState.color !== 'inherit' && ownerState.color !== 'default' && (theme.vars || theme).palette[ownerState.color] != null && {
100 color: (theme.vars || theme).palette[ownerState.color].contrastText,
101 backgroundColor: (theme.vars || theme).palette[ownerState.color].main,
102 '&:hover': {
103 backgroundColor: (theme.vars || theme).palette[ownerState.color].dark,
104 // Reset on touch devices, it doesn't add specificity
105 '@media (hover: none)': {
106 backgroundColor: (theme.vars || theme).palette[ownerState.color].main
107 }
108 }
109 });
110}, function (_ref3) {
111 var theme = _ref3.theme;
112 return _defineProperty({}, "&.".concat(fabClasses.disabled), {
113 color: (theme.vars || theme).palette.action.disabled,
114 boxShadow: (theme.vars || theme).shadows[0],
115 backgroundColor: (theme.vars || theme).palette.action.disabledBackground
116 });
117});
118var Fab = /*#__PURE__*/React.forwardRef(function Fab(inProps, ref) {
119 var props = useDefaultProps({
120 props: inProps,
121 name: 'MuiFab'
122 });
123 var children = props.children,
124 className = props.className,
125 _props$color = props.color,
126 color = _props$color === void 0 ? 'default' : _props$color,
127 _props$component = props.component,
128 component = _props$component === void 0 ? 'button' : _props$component,
129 _props$disabled = props.disabled,
130 disabled = _props$disabled === void 0 ? false : _props$disabled,
131 _props$disableFocusRi = props.disableFocusRipple,
132 disableFocusRipple = _props$disableFocusRi === void 0 ? false : _props$disableFocusRi,
133 focusVisibleClassName = props.focusVisibleClassName,
134 _props$size = props.size,
135 size = _props$size === void 0 ? 'large' : _props$size,
136 _props$variant = props.variant,
137 variant = _props$variant === void 0 ? 'circular' : _props$variant,
138 other = _objectWithoutProperties(props, ["children", "className", "color", "component", "disabled", "disableFocusRipple", "focusVisibleClassName", "size", "variant"]);
139 var ownerState = _extends({}, props, {
140 color: color,
141 component: component,
142 disabled: disabled,
143 disableFocusRipple: disableFocusRipple,
144 size: size,
145 variant: variant
146 });
147 var classes = useUtilityClasses(ownerState);
148 return /*#__PURE__*/_jsx(FabRoot, _extends({
149 className: clsx(classes.root, className),
150 component: component,
151 disabled: disabled,
152 focusRipple: !disableFocusRipple,
153 focusVisibleClassName: clsx(classes.focusVisible, focusVisibleClassName),
154 ownerState: ownerState,
155 ref: ref
156 }, other, {
157 classes: classes,
158 children: children
159 }));
160});
161process.env.NODE_ENV !== "production" ? Fab.propTypes /* remove-proptypes */ = {
162 // ┌────────────────────────────── Warning ──────────────────────────────┐
163 // │ These PropTypes are generated from the TypeScript type definitions. │
164 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
165 // └─────────────────────────────────────────────────────────────────────┘
166 /**
167 * The content of the component.
168 */
169 children: PropTypes.node,
170 /**
171 * Override or extend the styles applied to the component.
172 */
173 classes: PropTypes.object,
174 /**
175 * @ignore
176 */
177 className: PropTypes.string,
178 /**
179 * The color of the component.
180 * It supports both default and custom theme colors, which can be added as shown in the
181 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
182 * @default 'default'
183 */
184 color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['default', 'error', 'info', 'inherit', 'primary', 'secondary', 'success', 'warning']), PropTypes.string]),
185 /**
186 * The component used for the root node.
187 * Either a string to use a HTML element or a component.
188 */
189 component: PropTypes.elementType,
190 /**
191 * If `true`, the component is disabled.
192 * @default false
193 */
194 disabled: PropTypes.bool,
195 /**
196 * If `true`, the keyboard focus ripple is disabled.
197 * @default false
198 */
199 disableFocusRipple: PropTypes.bool,
200 /**
201 * If `true`, the ripple effect is disabled.
202 */
203 disableRipple: PropTypes.bool,
204 /**
205 * @ignore
206 */
207 focusVisibleClassName: PropTypes.string,
208 /**
209 * The URL to link to when the button is clicked.
210 * If defined, an `a` element will be used as the root node.
211 */
212 href: PropTypes.string,
213 /**
214 * The size of the component.
215 * `small` is equivalent to the dense button styling.
216 * @default 'large'
217 */
218 size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
219 /**
220 * The system prop that allows defining system overrides as well as additional CSS styles.
221 */
222 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
223 /**
224 * The variant to use.
225 * @default 'circular'
226 */
227 variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['circular', 'extended']), PropTypes.string])
228} : void 0;
229export default Fab;
\No newline at end of file