1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["children", "className", "enterAnimationName", "enterClassName", "exitAnimationName", "exitClassName"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import clsx from 'clsx';
|
9 | import { useTransitionStateManager } from '../useTransition';
|
10 | import { jsx as _jsx } from "react/jsx-runtime";
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function CssAnimation(props) {
|
22 | const {
|
23 | children,
|
24 | className,
|
25 | enterAnimationName,
|
26 | enterClassName,
|
27 | exitAnimationName,
|
28 | exitClassName
|
29 | } = props,
|
30 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
31 | const {
|
32 | requestedEnter,
|
33 | onExited
|
34 | } = useTransitionStateManager();
|
35 | const hasExited = React.useRef(true);
|
36 | React.useEffect(() => {
|
37 | if (requestedEnter && hasExited.current) {
|
38 | hasExited.current = false;
|
39 | }
|
40 | }, [requestedEnter]);
|
41 | const handleAnimationEnd = React.useCallback(event => {
|
42 | if (event.animationName === exitAnimationName) {
|
43 | onExited();
|
44 | hasExited.current = true;
|
45 | } else if (event.animationName === enterAnimationName) {
|
46 | hasExited.current = false;
|
47 | }
|
48 | }, [onExited, exitAnimationName, enterAnimationName]);
|
49 | return _jsx("div", _extends({
|
50 | onAnimationEnd: handleAnimationEnd,
|
51 | className: clsx(className, requestedEnter ? enterClassName : exitClassName)
|
52 | }, other, {
|
53 | children: children
|
54 | }));
|
55 | }
|
56 | process.env.NODE_ENV !== "production" ? CssAnimation.propTypes = {
|
57 | children: PropTypes.node,
|
58 | className: PropTypes.string,
|
59 | enterAnimationName: PropTypes.string,
|
60 | enterClassName: PropTypes.string,
|
61 | exitAnimationName: PropTypes.string,
|
62 | exitClassName: PropTypes.string
|
63 | } : void 0;
|
64 | export { CssAnimation }; |
\ | No newline at end of file |