UNPKG

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