UNPKG

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