1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import ButtonBase from "../ButtonBase/index.js";
|
8 | import capitalize from "../utils/capitalize.js";
|
9 | import fabClasses, { getFabUtilityClass } from "./fabClasses.js";
|
10 | import rootShouldForwardProp from "../styles/rootShouldForwardProp.js";
|
11 | import { styled } from "../zero-styled/index.js";
|
12 | import memoTheme from "../utils/memoTheme.js";
|
13 | import createSimplePaletteValueFilter from "../utils/createSimplePaletteValueFilter.js";
|
14 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
15 | import { jsx as _jsx } from "react/jsx-runtime";
|
16 | const 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 |
|
30 | ...composedClasses
|
31 | };
|
32 | };
|
33 | const 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 |
|
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']))
|
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 |
|
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 | })));
|
163 | const Fab = 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 _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 | });
|
203 | process.env.NODE_ENV !== "production" ? Fab.propTypes = {
|
204 |
|
205 |
|
206 |
|
207 |
|
208 | |
209 |
|
210 |
|
211 | children: PropTypes.node,
|
212 | |
213 |
|
214 |
|
215 | classes: PropTypes.object,
|
216 | |
217 |
|
218 |
|
219 | className: PropTypes.string,
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | color: PropTypes .oneOfType([PropTypes.oneOf(['default', 'error', 'info', 'inherit', 'primary', 'secondary', 'success', 'warning']), PropTypes.string]),
|
227 | |
228 |
|
229 |
|
230 |
|
231 | component: PropTypes.elementType,
|
232 | |
233 |
|
234 |
|
235 |
|
236 | disabled: PropTypes.bool,
|
237 | |
238 |
|
239 |
|
240 |
|
241 | disableFocusRipple: PropTypes.bool,
|
242 | |
243 |
|
244 |
|
245 | disableRipple: PropTypes.bool,
|
246 | |
247 |
|
248 |
|
249 | focusVisibleClassName: PropTypes.string,
|
250 | |
251 |
|
252 |
|
253 |
|
254 | href: PropTypes.string,
|
255 | |
256 |
|
257 |
|
258 |
|
259 |
|
260 | size: PropTypes .oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
|
261 | |
262 |
|
263 |
|
264 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
265 | |
266 |
|
267 |
|
268 |
|
269 | variant: PropTypes .oneOfType([PropTypes.oneOf(['circular', 'extended']), PropTypes.string])
|
270 | } : void 0;
|
271 | export default Fab; |
\ | No newline at end of file |