1 | 'use client';
|
2 |
|
3 |
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import { emphasize } from '@mui/system/colorManipulator';
|
9 | import { styled } from "../zero-styled/index.js";
|
10 | import memoTheme from "../utils/memoTheme.js";
|
11 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
12 | import Fab from "../Fab/index.js";
|
13 | import Tooltip from "../Tooltip/index.js";
|
14 | import capitalize from "../utils/capitalize.js";
|
15 | import speedDialActionClasses, { getSpeedDialActionUtilityClass } from "./speedDialActionClasses.js";
|
16 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
17 | const useUtilityClasses = ownerState => {
|
18 | const {
|
19 | open,
|
20 | tooltipPlacement,
|
21 | classes
|
22 | } = ownerState;
|
23 | const slots = {
|
24 | fab: ['fab', !open && 'fabClosed'],
|
25 | staticTooltip: ['staticTooltip', `tooltipPlacement${capitalize(tooltipPlacement)}`, !open && 'staticTooltipClosed'],
|
26 | staticTooltipLabel: ['staticTooltipLabel']
|
27 | };
|
28 | return composeClasses(slots, getSpeedDialActionUtilityClass, classes);
|
29 | };
|
30 | const SpeedDialActionFab = styled(Fab, {
|
31 | name: 'MuiSpeedDialAction',
|
32 | slot: 'Fab',
|
33 | skipVariantsResolver: false,
|
34 | overridesResolver: (props, styles) => {
|
35 | const {
|
36 | ownerState
|
37 | } = props;
|
38 | return [styles.fab, !ownerState.open && styles.fabClosed];
|
39 | }
|
40 | })(memoTheme(({
|
41 | theme
|
42 | }) => ({
|
43 | margin: 8,
|
44 | color: (theme.vars || theme).palette.text.secondary,
|
45 | backgroundColor: (theme.vars || theme).palette.background.paper,
|
46 | '&:hover': {
|
47 | backgroundColor: theme.vars ? theme.vars.palette.SpeedDialAction.fabHoverBg : emphasize(theme.palette.background.paper, 0.15)
|
48 | },
|
49 | transition: `${theme.transitions.create('transform', {
|
50 | duration: theme.transitions.duration.shorter
|
51 | })}, opacity 0.8s`,
|
52 | opacity: 1,
|
53 | variants: [{
|
54 | props: ({
|
55 | ownerState
|
56 | }) => !ownerState.open,
|
57 | style: {
|
58 | opacity: 0,
|
59 | transform: 'scale(0)'
|
60 | }
|
61 | }]
|
62 | })));
|
63 | const SpeedDialActionStaticTooltip = styled('span', {
|
64 | name: 'MuiSpeedDialAction',
|
65 | slot: 'StaticTooltip',
|
66 | overridesResolver: (props, styles) => {
|
67 | const {
|
68 | ownerState
|
69 | } = props;
|
70 | return [styles.staticTooltip, !ownerState.open && styles.staticTooltipClosed, styles[`tooltipPlacement${capitalize(ownerState.tooltipPlacement)}`]];
|
71 | }
|
72 | })(memoTheme(({
|
73 | theme
|
74 | }) => ({
|
75 | position: 'relative',
|
76 | display: 'flex',
|
77 | alignItems: 'center',
|
78 | [`& .${speedDialActionClasses.staticTooltipLabel}`]: {
|
79 | transition: theme.transitions.create(['transform', 'opacity'], {
|
80 | duration: theme.transitions.duration.shorter
|
81 | }),
|
82 | opacity: 1
|
83 | },
|
84 | variants: [{
|
85 | props: ({
|
86 | ownerState
|
87 | }) => !ownerState.open,
|
88 | style: {
|
89 | [`& .${speedDialActionClasses.staticTooltipLabel}`]: {
|
90 | opacity: 0,
|
91 | transform: 'scale(0.5)'
|
92 | }
|
93 | }
|
94 | }, {
|
95 | props: {
|
96 | tooltipPlacement: 'left'
|
97 | },
|
98 | style: {
|
99 | [`& .${speedDialActionClasses.staticTooltipLabel}`]: {
|
100 | transformOrigin: '100% 50%',
|
101 | right: '100%',
|
102 | marginRight: 8
|
103 | }
|
104 | }
|
105 | }, {
|
106 | props: {
|
107 | tooltipPlacement: 'right'
|
108 | },
|
109 | style: {
|
110 | [`& .${speedDialActionClasses.staticTooltipLabel}`]: {
|
111 | transformOrigin: '0% 50%',
|
112 | left: '100%',
|
113 | marginLeft: 8
|
114 | }
|
115 | }
|
116 | }]
|
117 | })));
|
118 | const SpeedDialActionStaticTooltipLabel = styled('span', {
|
119 | name: 'MuiSpeedDialAction',
|
120 | slot: 'StaticTooltipLabel',
|
121 | overridesResolver: (props, styles) => styles.staticTooltipLabel
|
122 | })(memoTheme(({
|
123 | theme
|
124 | }) => ({
|
125 | position: 'absolute',
|
126 | ...theme.typography.body1,
|
127 | backgroundColor: (theme.vars || theme).palette.background.paper,
|
128 | borderRadius: (theme.vars || theme).shape.borderRadius,
|
129 | boxShadow: (theme.vars || theme).shadows[1],
|
130 | color: (theme.vars || theme).palette.text.secondary,
|
131 | padding: '4px 16px',
|
132 | wordBreak: 'keep-all'
|
133 | })));
|
134 | const SpeedDialAction = React.forwardRef(function SpeedDialAction(inProps, ref) {
|
135 | const props = useDefaultProps({
|
136 | props: inProps,
|
137 | name: 'MuiSpeedDialAction'
|
138 | });
|
139 | const {
|
140 | className,
|
141 | delay = 0,
|
142 | FabProps = {},
|
143 | icon,
|
144 | id,
|
145 | open,
|
146 | TooltipClasses,
|
147 | tooltipOpen: tooltipOpenProp = false,
|
148 | tooltipPlacement = 'left',
|
149 | tooltipTitle,
|
150 | ...other
|
151 | } = props;
|
152 | const ownerState = {
|
153 | ...props,
|
154 | tooltipPlacement
|
155 | };
|
156 | const classes = useUtilityClasses(ownerState);
|
157 | const [tooltipOpen, setTooltipOpen] = React.useState(tooltipOpenProp);
|
158 | const handleTooltipClose = () => {
|
159 | setTooltipOpen(false);
|
160 | };
|
161 | const handleTooltipOpen = () => {
|
162 | setTooltipOpen(true);
|
163 | };
|
164 | const transitionStyle = {
|
165 | transitionDelay: `${delay}ms`
|
166 | };
|
167 | const fab = _jsx(SpeedDialActionFab, {
|
168 | size: "small",
|
169 | className: clsx(classes.fab, className),
|
170 | tabIndex: -1,
|
171 | role: "menuitem",
|
172 | ownerState: ownerState,
|
173 | ...FabProps,
|
174 | style: {
|
175 | ...transitionStyle,
|
176 | ...FabProps.style
|
177 | },
|
178 | children: icon
|
179 | });
|
180 | if (tooltipOpenProp) {
|
181 | return _jsxs(SpeedDialActionStaticTooltip, {
|
182 | id: id,
|
183 | ref: ref,
|
184 | className: classes.staticTooltip,
|
185 | ownerState: ownerState,
|
186 | ...other,
|
187 | children: [_jsx(SpeedDialActionStaticTooltipLabel, {
|
188 | style: transitionStyle,
|
189 | id: `${id}-label`,
|
190 | className: classes.staticTooltipLabel,
|
191 | ownerState: ownerState,
|
192 | children: tooltipTitle
|
193 | }), React.cloneElement(fab, {
|
194 | 'aria-labelledby': `${id}-label`
|
195 | })]
|
196 | });
|
197 | }
|
198 | if (!open && tooltipOpen) {
|
199 | setTooltipOpen(false);
|
200 | }
|
201 | return _jsx(Tooltip, {
|
202 | id: id,
|
203 | ref: ref,
|
204 | title: tooltipTitle,
|
205 | placement: tooltipPlacement,
|
206 | onClose: handleTooltipClose,
|
207 | onOpen: handleTooltipOpen,
|
208 | open: open && tooltipOpen,
|
209 | classes: TooltipClasses,
|
210 | ...other,
|
211 | children: fab
|
212 | });
|
213 | });
|
214 | process.env.NODE_ENV !== "production" ? SpeedDialAction.propTypes = {
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | |
220 |
|
221 |
|
222 | classes: PropTypes.object,
|
223 | |
224 |
|
225 |
|
226 | className: PropTypes.string,
|
227 | |
228 |
|
229 |
|
230 |
|
231 | delay: PropTypes.number,
|
232 | |
233 |
|
234 |
|
235 |
|
236 | FabProps: PropTypes.object,
|
237 | |
238 |
|
239 |
|
240 | icon: PropTypes.node,
|
241 | |
242 |
|
243 |
|
244 |
|
245 | id: PropTypes.string,
|
246 | |
247 |
|
248 |
|
249 | open: PropTypes.bool,
|
250 | |
251 |
|
252 |
|
253 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
254 | |
255 |
|
256 |
|
257 | TooltipClasses: PropTypes.object,
|
258 | |
259 |
|
260 |
|
261 |
|
262 | tooltipOpen: PropTypes.bool,
|
263 | |
264 |
|
265 |
|
266 |
|
267 | tooltipPlacement: PropTypes.oneOf(['bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']),
|
268 | |
269 |
|
270 |
|
271 | tooltipTitle: PropTypes.node
|
272 | } : void 0;
|
273 | export default SpeedDialAction; |
\ | No newline at end of file |