1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import { withStyles } from '@material-ui/core/styles';
|
7 | import AddIcon from '../internal/svg-icons/Add';
|
8 | export const styles = theme => ({
|
9 |
|
10 | root: {
|
11 | height: 24
|
12 | },
|
13 |
|
14 |
|
15 | icon: {
|
16 | transition: theme.transitions.create(['transform', 'opacity'], {
|
17 | duration: theme.transitions.duration.short
|
18 | })
|
19 | },
|
20 |
|
21 |
|
22 | iconOpen: {
|
23 | transform: 'rotate(45deg)'
|
24 | },
|
25 |
|
26 |
|
27 | iconWithOpenIconOpen: {
|
28 | opacity: 0
|
29 | },
|
30 |
|
31 |
|
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 |
|
42 | openIconOpen: {
|
43 | transform: 'rotate(0deg)',
|
44 | opacity: 1
|
45 | }
|
46 | });
|
47 | const SpeedDialIcon = 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 ( React.isValidElement(icon)) {
|
62 | return React.cloneElement(icon, {
|
63 | className: newClassName
|
64 | });
|
65 | }
|
66 |
|
67 | return icon;
|
68 | }
|
69 |
|
70 | return React.createElement("span", _extends({
|
71 | className: clsx(classes.root, className),
|
72 | ref: ref
|
73 | }, other), openIconProp ? formatIcon(openIconProp, openIconClassName) : null, iconProp ? formatIcon(iconProp, iconClassName) : React.createElement(AddIcon, {
|
74 | className: iconClassName
|
75 | }));
|
76 | });
|
77 | process.env.NODE_ENV !== "production" ? SpeedDialIcon.propTypes = {
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 | classes: PropTypes.object,
|
88 |
|
89 | |
90 |
|
91 |
|
92 | className: PropTypes.string,
|
93 |
|
94 | |
95 |
|
96 |
|
97 | icon: PropTypes.node,
|
98 |
|
99 | |
100 |
|
101 |
|
102 |
|
103 | open: PropTypes.bool,
|
104 |
|
105 | |
106 |
|
107 |
|
108 | openIcon: PropTypes.node
|
109 | } : void 0;
|
110 | SpeedDialIcon.muiName = 'SpeedDialIcon';
|
111 | export default withStyles(styles, {
|
112 | name: 'MuiSpeedDialIcon'
|
113 | })(SpeedDialIcon); |
\ | No newline at end of file |