UNPKG

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