UNPKG

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