UNPKG

2.04 kBJavaScriptView Raw
1'use client';
2
3import _extends from "@babel/runtime/helpers/esm/extends";
4import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5const _excluded = ["children", "className", "enterAnimationName", "enterClassName", "exitAnimationName", "exitClassName"];
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import clsx from 'clsx';
9import { useTransitionStateManager } from '../useTransition';
10import { jsx as _jsx } from "react/jsx-runtime";
11/**
12 *
13 * Demos:
14 *
15 * - [Transitions](https://mui.com/base-ui/react-transitions/)
16 *
17 * API:
18 *
19 * - [CssAnimation API](https://mui.com/base-ui/react-transitions/components-api/#css-animation)
20 */
21function 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 /*#__PURE__*/_jsx("div", _extends({
50 onAnimationEnd: handleAnimationEnd,
51 className: clsx(className, requestedEnter ? enterClassName : exitClassName)
52 }, other, {
53 children: children
54 }));
55}
56process.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;
64export { CssAnimation };
\No newline at end of file