UNPKG

8.68 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _useTimeout = _interopRequireDefault(require("@mui/utils/useTimeout"));
13var _elementAcceptingRef = _interopRequireDefault(require("@mui/utils/elementAcceptingRef"));
14var _getReactElementRef = _interopRequireDefault(require("@mui/utils/getReactElementRef"));
15var _reactTransitionGroup = require("react-transition-group");
16var _zeroStyled = require("../zero-styled");
17var _utils = require("../transitions/utils");
18var _useForkRef = _interopRequireDefault(require("../utils/useForkRef"));
19var _jsxRuntime = require("react/jsx-runtime");
20function getScale(value) {
21 return `scale(${value}, ${value ** 2})`;
22}
23const styles = {
24 entering: {
25 opacity: 1,
26 transform: getScale(1)
27 },
28 entered: {
29 opacity: 1,
30 transform: 'none'
31 }
32};
33
34/*
35 TODO v6: remove
36 Conditionally apply a workaround for the CSS transition bug in Safari 15.4 / WebKit browsers.
37 */
38const isWebKit154 = typeof navigator !== 'undefined' && /^((?!chrome|android).)*(safari|mobile)/i.test(navigator.userAgent) && /(os |version\/)15(.|_)4/i.test(navigator.userAgent);
39
40/**
41 * The Grow transition is used by the [Tooltip](/material-ui/react-tooltip/) and
42 * [Popover](/material-ui/react-popover/) components.
43 * It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
44 */
45const Grow = /*#__PURE__*/React.forwardRef(function Grow(props, ref) {
46 const {
47 addEndListener,
48 appear = true,
49 children,
50 easing,
51 in: inProp,
52 onEnter,
53 onEntered,
54 onEntering,
55 onExit,
56 onExited,
57 onExiting,
58 style,
59 timeout = 'auto',
60 // eslint-disable-next-line react/prop-types
61 TransitionComponent = _reactTransitionGroup.Transition,
62 ...other
63 } = props;
64 const timer = (0, _useTimeout.default)();
65 const autoTimeout = React.useRef();
66 const theme = (0, _zeroStyled.useTheme)();
67 const nodeRef = React.useRef(null);
68 const handleRef = (0, _useForkRef.default)(nodeRef, (0, _getReactElementRef.default)(children), ref);
69 const normalizedTransitionCallback = callback => maybeIsAppearing => {
70 if (callback) {
71 const node = nodeRef.current;
72
73 // onEnterXxx and onExitXxx callbacks have a different arguments.length value.
74 if (maybeIsAppearing === undefined) {
75 callback(node);
76 } else {
77 callback(node, maybeIsAppearing);
78 }
79 }
80 };
81 const handleEntering = normalizedTransitionCallback(onEntering);
82 const handleEnter = normalizedTransitionCallback((node, isAppearing) => {
83 (0, _utils.reflow)(node); // So the animation always start from the start.
84
85 const {
86 duration: transitionDuration,
87 delay,
88 easing: transitionTimingFunction
89 } = (0, _utils.getTransitionProps)({
90 style,
91 timeout,
92 easing
93 }, {
94 mode: 'enter'
95 });
96 let duration;
97 if (timeout === 'auto') {
98 duration = theme.transitions.getAutoHeightDuration(node.clientHeight);
99 autoTimeout.current = duration;
100 } else {
101 duration = transitionDuration;
102 }
103 node.style.transition = [theme.transitions.create('opacity', {
104 duration,
105 delay
106 }), theme.transitions.create('transform', {
107 duration: isWebKit154 ? duration : duration * 0.666,
108 delay,
109 easing: transitionTimingFunction
110 })].join(',');
111 if (onEnter) {
112 onEnter(node, isAppearing);
113 }
114 });
115 const handleEntered = normalizedTransitionCallback(onEntered);
116 const handleExiting = normalizedTransitionCallback(onExiting);
117 const handleExit = normalizedTransitionCallback(node => {
118 const {
119 duration: transitionDuration,
120 delay,
121 easing: transitionTimingFunction
122 } = (0, _utils.getTransitionProps)({
123 style,
124 timeout,
125 easing
126 }, {
127 mode: 'exit'
128 });
129 let duration;
130 if (timeout === 'auto') {
131 duration = theme.transitions.getAutoHeightDuration(node.clientHeight);
132 autoTimeout.current = duration;
133 } else {
134 duration = transitionDuration;
135 }
136 node.style.transition = [theme.transitions.create('opacity', {
137 duration,
138 delay
139 }), theme.transitions.create('transform', {
140 duration: isWebKit154 ? duration : duration * 0.666,
141 delay: isWebKit154 ? delay : delay || duration * 0.333,
142 easing: transitionTimingFunction
143 })].join(',');
144 node.style.opacity = 0;
145 node.style.transform = getScale(0.75);
146 if (onExit) {
147 onExit(node);
148 }
149 });
150 const handleExited = normalizedTransitionCallback(onExited);
151 const handleAddEndListener = next => {
152 if (timeout === 'auto') {
153 timer.start(autoTimeout.current || 0, next);
154 }
155 if (addEndListener) {
156 // Old call signature before `react-transition-group` implemented `nodeRef`
157 addEndListener(nodeRef.current, next);
158 }
159 };
160 return /*#__PURE__*/(0, _jsxRuntime.jsx)(TransitionComponent, {
161 appear: appear,
162 in: inProp,
163 nodeRef: nodeRef,
164 onEnter: handleEnter,
165 onEntered: handleEntered,
166 onEntering: handleEntering,
167 onExit: handleExit,
168 onExited: handleExited,
169 onExiting: handleExiting,
170 addEndListener: handleAddEndListener,
171 timeout: timeout === 'auto' ? null : timeout,
172 ...other,
173 children: (state, childProps) => {
174 return /*#__PURE__*/React.cloneElement(children, {
175 style: {
176 opacity: 0,
177 transform: getScale(0.75),
178 visibility: state === 'exited' && !inProp ? 'hidden' : undefined,
179 ...styles[state],
180 ...style,
181 ...children.props.style
182 },
183 ref: handleRef,
184 ...childProps
185 });
186 }
187 });
188});
189process.env.NODE_ENV !== "production" ? Grow.propTypes /* remove-proptypes */ = {
190 // ┌────────────────────────────── Warning ──────────────────────────────┐
191 // │ These PropTypes are generated from the TypeScript type definitions. │
192 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
193 // └─────────────────────────────────────────────────────────────────────┘
194 /**
195 * Add a custom transition end trigger. Called with the transitioning DOM
196 * node and a done callback. Allows for more fine grained transition end
197 * logic. Note: Timeouts are still used as a fallback if provided.
198 */
199 addEndListener: _propTypes.default.func,
200 /**
201 * Perform the enter transition when it first mounts if `in` is also `true`.
202 * Set this to `false` to disable this behavior.
203 * @default true
204 */
205 appear: _propTypes.default.bool,
206 /**
207 * A single child content element.
208 */
209 children: _elementAcceptingRef.default.isRequired,
210 /**
211 * The transition timing function.
212 * You may specify a single easing or a object containing enter and exit values.
213 */
214 easing: _propTypes.default.oneOfType([_propTypes.default.shape({
215 enter: _propTypes.default.string,
216 exit: _propTypes.default.string
217 }), _propTypes.default.string]),
218 /**
219 * If `true`, the component will transition in.
220 */
221 in: _propTypes.default.bool,
222 /**
223 * @ignore
224 */
225 onEnter: _propTypes.default.func,
226 /**
227 * @ignore
228 */
229 onEntered: _propTypes.default.func,
230 /**
231 * @ignore
232 */
233 onEntering: _propTypes.default.func,
234 /**
235 * @ignore
236 */
237 onExit: _propTypes.default.func,
238 /**
239 * @ignore
240 */
241 onExited: _propTypes.default.func,
242 /**
243 * @ignore
244 */
245 onExiting: _propTypes.default.func,
246 /**
247 * @ignore
248 */
249 style: _propTypes.default.object,
250 /**
251 * The duration for the transition, in milliseconds.
252 * You may specify a single timeout for all transitions, or individually with an object.
253 *
254 * Set to 'auto' to automatically calculate transition time based on height.
255 * @default 'auto'
256 */
257 timeout: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.number, _propTypes.default.shape({
258 appear: _propTypes.default.number,
259 enter: _propTypes.default.number,
260 exit: _propTypes.default.number
261 })])
262} : void 0;
263if (Grow) {
264 Grow.muiSupportAuto = true;
265}
266var _default = exports.default = Grow;
\No newline at end of file