UNPKG

8.26 kBJavaScriptView Raw
1'use client';
2
3// @inheritedComponent Tooltip
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import composeClasses from '@mui/utils/composeClasses';
8import { emphasize } from '@mui/system/colorManipulator';
9import { styled } from "../zero-styled/index.js";
10import memoTheme from "../utils/memoTheme.js";
11import { useDefaultProps } from "../DefaultPropsProvider/index.js";
12import Fab from "../Fab/index.js";
13import Tooltip from "../Tooltip/index.js";
14import capitalize from "../utils/capitalize.js";
15import speedDialActionClasses, { getSpeedDialActionUtilityClass } from "./speedDialActionClasses.js";
16import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17const 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};
30const 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})));
63const 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})));
118const 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})));
134const SpeedDialAction = /*#__PURE__*/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 = /*#__PURE__*/_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 /*#__PURE__*/_jsxs(SpeedDialActionStaticTooltip, {
182 id: id,
183 ref: ref,
184 className: classes.staticTooltip,
185 ownerState: ownerState,
186 ...other,
187 children: [/*#__PURE__*/_jsx(SpeedDialActionStaticTooltipLabel, {
188 style: transitionStyle,
189 id: `${id}-label`,
190 className: classes.staticTooltipLabel,
191 ownerState: ownerState,
192 children: tooltipTitle
193 }), /*#__PURE__*/React.cloneElement(fab, {
194 'aria-labelledby': `${id}-label`
195 })]
196 });
197 }
198 if (!open && tooltipOpen) {
199 setTooltipOpen(false);
200 }
201 return /*#__PURE__*/_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});
214process.env.NODE_ENV !== "production" ? SpeedDialAction.propTypes /* remove-proptypes */ = {
215 // ┌────────────────────────────── Warning ──────────────────────────────┐
216 // │ These PropTypes are generated from the TypeScript type definitions. │
217 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
218 // └─────────────────────────────────────────────────────────────────────┘
219 /**
220 * Override or extend the styles applied to the component.
221 */
222 classes: PropTypes.object,
223 /**
224 * @ignore
225 */
226 className: PropTypes.string,
227 /**
228 * Adds a transition delay, to allow a series of SpeedDialActions to be animated.
229 * @default 0
230 */
231 delay: PropTypes.number,
232 /**
233 * Props applied to the [`Fab`](https://mui.com/material-ui/api/fab/) component.
234 * @default {}
235 */
236 FabProps: PropTypes.object,
237 /**
238 * The icon to display in the SpeedDial Fab.
239 */
240 icon: PropTypes.node,
241 /**
242 * This prop is used to help implement the accessibility logic.
243 * If you don't provide this prop. It falls back to a randomly generated id.
244 */
245 id: PropTypes.string,
246 /**
247 * If `true`, the component is shown.
248 */
249 open: PropTypes.bool,
250 /**
251 * The system prop that allows defining system overrides as well as additional CSS styles.
252 */
253 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
254 /**
255 * `classes` prop applied to the [`Tooltip`](https://mui.com/material-ui/api/tooltip/) element.
256 */
257 TooltipClasses: PropTypes.object,
258 /**
259 * Make the tooltip always visible when the SpeedDial is open.
260 * @default false
261 */
262 tooltipOpen: PropTypes.bool,
263 /**
264 * Placement of the tooltip.
265 * @default 'left'
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 * Label to display in the tooltip.
270 */
271 tooltipTitle: PropTypes.node
272} : void 0;
273export default SpeedDialAction;
\No newline at end of file