UNPKG

3.42 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import { withStyles } from '@material-ui/core/styles';
7import AddIcon from '../internal/svg-icons/Add';
8export const styles = theme => ({
9 /* Styles applied to the root element. */
10 root: {
11 height: 24
12 },
13
14 /* Styles applied to the icon component. */
15 icon: {
16 transition: theme.transitions.create(['transform', 'opacity'], {
17 duration: theme.transitions.duration.short
18 })
19 },
20
21 /* Styles applied to the icon component if `open={true}`. */
22 iconOpen: {
23 transform: 'rotate(45deg)'
24 },
25
26 /* Styles applied to the icon when and `openIcon` is provided and if `open={true}`. */
27 iconWithOpenIconOpen: {
28 opacity: 0
29 },
30
31 /* Styles applied to the `openIcon` if provided. */
32 openIcon: {
33 position: 'absolute',
34 transition: theme.transitions.create(['transform', 'opacity'], {
35 duration: theme.transitions.duration.short
36 }),
37 opacity: 0,
38 transform: 'rotate(-45deg)'
39 },
40
41 /* Styles applied to the `openIcon` if provided and if `open={true}`. */
42 openIconOpen: {
43 transform: 'rotate(0deg)',
44 opacity: 1
45 }
46});
47const SpeedDialIcon = /*#__PURE__*/React.forwardRef(function SpeedDialIcon(props, ref) {
48 const {
49 className,
50 classes,
51 icon: iconProp,
52 open,
53 openIcon: openIconProp
54 } = props,
55 other = _objectWithoutPropertiesLoose(props, ["className", "classes", "icon", "open", "openIcon"]);
56
57 const iconClassName = clsx(classes.icon, open && [classes.iconOpen, openIconProp && classes.iconWithOpenIconOpen]);
58 const openIconClassName = clsx(classes.openIcon, open && classes.openIconOpen);
59
60 function formatIcon(icon, newClassName) {
61 if ( /*#__PURE__*/React.isValidElement(icon)) {
62 return /*#__PURE__*/React.cloneElement(icon, {
63 className: newClassName
64 });
65 }
66
67 return icon;
68 }
69
70 return /*#__PURE__*/React.createElement("span", _extends({
71 className: clsx(classes.root, className),
72 ref: ref
73 }, other), openIconProp ? formatIcon(openIconProp, openIconClassName) : null, iconProp ? formatIcon(iconProp, iconClassName) : /*#__PURE__*/React.createElement(AddIcon, {
74 className: iconClassName
75 }));
76});
77process.env.NODE_ENV !== "production" ? SpeedDialIcon.propTypes = {
78 // ----------------------------- Warning --------------------------------
79 // | These PropTypes are generated from the TypeScript type definitions |
80 // | To update them edit the d.ts file and run "yarn proptypes" |
81 // ----------------------------------------------------------------------
82
83 /**
84 * Override or extend the styles applied to the component.
85 * See [CSS API](#css) below for more details.
86 */
87 classes: PropTypes.object,
88
89 /**
90 * @ignore
91 */
92 className: PropTypes.string,
93
94 /**
95 * The icon to display in the SpeedDial Floating Action Button.
96 */
97 icon: PropTypes.node,
98
99 /**
100 * @ignore
101 * If `true`, the SpeedDial is open.
102 */
103 open: PropTypes.bool,
104
105 /**
106 * The icon to display in the SpeedDial Floating Action Button when the SpeedDial is open.
107 */
108 openIcon: PropTypes.node
109} : void 0;
110SpeedDialIcon.muiName = 'SpeedDialIcon';
111export default withStyles(styles, {
112 name: 'MuiSpeedDialIcon'
113})(SpeedDialIcon);
\No newline at end of file