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", "lastTransitionedPropertyOnExit", "enterClassName", "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 |
|
22 |
|
23 | const CssTransition = React.forwardRef(function CssTransition(props, forwardedRef) {
|
24 | const {
|
25 | children,
|
26 | className,
|
27 | lastTransitionedPropertyOnExit,
|
28 | enterClassName,
|
29 | exitClassName
|
30 | } = props,
|
31 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
32 | const {
|
33 | requestedEnter,
|
34 | onExited
|
35 | } = useTransitionStateManager();
|
36 | const [isEntering, setIsEntering] = React.useState(false);
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | React.useEffect(() => {
|
43 | if (requestedEnter) {
|
44 | requestAnimationFrame(() => {
|
45 | setIsEntering(true);
|
46 | });
|
47 | } else {
|
48 | setIsEntering(false);
|
49 | }
|
50 | }, [requestedEnter]);
|
51 | const handleTransitionEnd = React.useCallback(event => {
|
52 | if (!requestedEnter && (lastTransitionedPropertyOnExit == null || event.propertyName === lastTransitionedPropertyOnExit)) {
|
53 | onExited();
|
54 | }
|
55 | }, [onExited, requestedEnter, lastTransitionedPropertyOnExit]);
|
56 | return _jsx("div", _extends({
|
57 | onTransitionEnd: handleTransitionEnd,
|
58 | className: clsx(className, isEntering ? enterClassName : exitClassName)
|
59 | }, other, {
|
60 | ref: forwardedRef,
|
61 | children: children
|
62 | }));
|
63 | });
|
64 | process.env.NODE_ENV !== "production" ? CssTransition.propTypes = {
|
65 | children: PropTypes.node,
|
66 | className: PropTypes.string,
|
67 | enterClassName: PropTypes.string,
|
68 | exitClassName: PropTypes.string,
|
69 | lastTransitionedPropertyOnEnter: PropTypes.string,
|
70 | lastTransitionedPropertyOnExit: PropTypes.string
|
71 | } : void 0;
|
72 | export { CssTransition }; |
\ | No newline at end of file |