UNPKG

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