UNPKG

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