1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import { styled } from "../zero-styled/index.js";
|
8 | import memoTheme from "../utils/memoTheme.js";
|
9 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
10 | import AddIcon from "../internal/svg-icons/Add.js";
|
11 | import speedDialIconClasses, { getSpeedDialIconUtilityClass } from "./speedDialIconClasses.js";
|
12 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13 | const useUtilityClasses = ownerState => {
|
14 | const {
|
15 | classes,
|
16 | open,
|
17 | openIcon
|
18 | } = ownerState;
|
19 | const slots = {
|
20 | root: ['root'],
|
21 | icon: ['icon', open && 'iconOpen', openIcon && open && 'iconWithOpenIconOpen'],
|
22 | openIcon: ['openIcon', open && 'openIconOpen']
|
23 | };
|
24 | return composeClasses(slots, getSpeedDialIconUtilityClass, classes);
|
25 | };
|
26 | const SpeedDialIconRoot = styled('span', {
|
27 | name: 'MuiSpeedDialIcon',
|
28 | slot: 'Root',
|
29 | overridesResolver: (props, styles) => {
|
30 | const {
|
31 | ownerState
|
32 | } = props;
|
33 | return [{
|
34 | [`& .${speedDialIconClasses.icon}`]: styles.icon
|
35 | }, {
|
36 | [`& .${speedDialIconClasses.icon}`]: ownerState.open && styles.iconOpen
|
37 | }, {
|
38 | [`& .${speedDialIconClasses.icon}`]: ownerState.open && ownerState.openIcon && styles.iconWithOpenIconOpen
|
39 | }, {
|
40 | [`& .${speedDialIconClasses.openIcon}`]: styles.openIcon
|
41 | }, {
|
42 | [`& .${speedDialIconClasses.openIcon}`]: ownerState.open && styles.openIconOpen
|
43 | }, styles.root];
|
44 | }
|
45 | })(memoTheme(({
|
46 | theme
|
47 | }) => ({
|
48 | height: 24,
|
49 | [`& .${speedDialIconClasses.icon}`]: {
|
50 | transition: theme.transitions.create(['transform', 'opacity'], {
|
51 | duration: theme.transitions.duration.short
|
52 | })
|
53 | },
|
54 | [`& .${speedDialIconClasses.openIcon}`]: {
|
55 | position: 'absolute',
|
56 | transition: theme.transitions.create(['transform', 'opacity'], {
|
57 | duration: theme.transitions.duration.short
|
58 | }),
|
59 | opacity: 0,
|
60 | transform: 'rotate(-45deg)'
|
61 | },
|
62 | variants: [{
|
63 | props: ({
|
64 | ownerState
|
65 | }) => ownerState.open,
|
66 | style: {
|
67 | [`& .${speedDialIconClasses.icon}`]: {
|
68 | transform: 'rotate(45deg)'
|
69 | }
|
70 | }
|
71 | }, {
|
72 | props: ({
|
73 | ownerState
|
74 | }) => ownerState.open && ownerState.openIcon,
|
75 | style: {
|
76 | [`& .${speedDialIconClasses.icon}`]: {
|
77 | opacity: 0
|
78 | }
|
79 | }
|
80 | }, {
|
81 | props: ({
|
82 | ownerState
|
83 | }) => ownerState.open,
|
84 | style: {
|
85 | [`& .${speedDialIconClasses.openIcon}`]: {
|
86 | transform: 'rotate(0deg)',
|
87 | opacity: 1
|
88 | }
|
89 | }
|
90 | }]
|
91 | })));
|
92 | const SpeedDialIcon = React.forwardRef(function SpeedDialIcon(inProps, ref) {
|
93 | const props = useDefaultProps({
|
94 | props: inProps,
|
95 | name: 'MuiSpeedDialIcon'
|
96 | });
|
97 | const {
|
98 | className,
|
99 | icon: iconProp,
|
100 | open,
|
101 | openIcon: openIconProp,
|
102 | ...other
|
103 | } = props;
|
104 | const ownerState = props;
|
105 | const classes = useUtilityClasses(ownerState);
|
106 | function formatIcon(icon, newClassName) {
|
107 | if (React.isValidElement(icon)) {
|
108 | return React.cloneElement(icon, {
|
109 | className: newClassName
|
110 | });
|
111 | }
|
112 | return icon;
|
113 | }
|
114 | return _jsxs(SpeedDialIconRoot, {
|
115 | className: clsx(classes.root, className),
|
116 | ref: ref,
|
117 | ownerState: ownerState,
|
118 | ...other,
|
119 | children: [openIconProp ? formatIcon(openIconProp, classes.openIcon) : null, iconProp ? formatIcon(iconProp, classes.icon) : _jsx(AddIcon, {
|
120 | className: classes.icon
|
121 | })]
|
122 | });
|
123 | });
|
124 | process.env.NODE_ENV !== "production" ? SpeedDialIcon.propTypes = {
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | |
130 |
|
131 |
|
132 | classes: PropTypes.object,
|
133 | |
134 |
|
135 |
|
136 | className: PropTypes.string,
|
137 | |
138 |
|
139 |
|
140 | icon: PropTypes.node,
|
141 | |
142 |
|
143 |
|
144 |
|
145 | open: PropTypes.bool,
|
146 | |
147 |
|
148 |
|
149 | openIcon: PropTypes.node,
|
150 | |
151 |
|
152 |
|
153 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
154 | } : void 0;
|
155 | SpeedDialIcon.muiName = 'SpeedDialIcon';
|
156 | export default SpeedDialIcon; |
\ | No newline at end of file |