UNPKG

4.97 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import { styled } from "../zero-styled/index.js";
8import memoTheme from "../utils/memoTheme.js";
9import { useDefaultProps } from "../DefaultPropsProvider/index.js";
10import AddIcon from "../internal/svg-icons/Add.js";
11import speedDialIconClasses, { getSpeedDialIconUtilityClass } from "./speedDialIconClasses.js";
12import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13const 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};
26const 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})));
92const SpeedDialIcon = /*#__PURE__*/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 (/*#__PURE__*/React.isValidElement(icon)) {
108 return /*#__PURE__*/React.cloneElement(icon, {
109 className: newClassName
110 });
111 }
112 return icon;
113 }
114 return /*#__PURE__*/_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) : /*#__PURE__*/_jsx(AddIcon, {
120 className: classes.icon
121 })]
122 });
123});
124process.env.NODE_ENV !== "production" ? SpeedDialIcon.propTypes /* remove-proptypes */ = {
125 // ┌────────────────────────────── Warning ──────────────────────────────┐
126 // │ These PropTypes are generated from the TypeScript type definitions. │
127 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
128 // └─────────────────────────────────────────────────────────────────────┘
129 /**
130 * Override or extend the styles applied to the component.
131 */
132 classes: PropTypes.object,
133 /**
134 * @ignore
135 */
136 className: PropTypes.string,
137 /**
138 * The icon to display.
139 */
140 icon: PropTypes.node,
141 /**
142 * @ignore
143 * If `true`, the component is shown.
144 */
145 open: PropTypes.bool,
146 /**
147 * The icon to display in the SpeedDial Floating Action Button when the SpeedDial is open.
148 */
149 openIcon: PropTypes.node,
150 /**
151 * The system prop that allows defining system overrides as well as additional CSS styles.
152 */
153 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
154} : void 0;
155SpeedDialIcon.muiName = 'SpeedDialIcon';
156export default SpeedDialIcon;
\No newline at end of file