1 | "use client";
|
2 |
|
3 | import React, { useCallback, useRef } from 'react';
|
4 | import Transition from 'react-transition-group/Transition';
|
5 | import useMergedRefs from '@restart/hooks/useMergedRefs';
|
6 | import safeFindDOMNode from './safeFindDOMNode';
|
7 | import { jsx as _jsx } from "react/jsx-runtime";
|
8 |
|
9 | const TransitionWrapper = React.forwardRef(({
|
10 | onEnter,
|
11 | onEntering,
|
12 | onEntered,
|
13 | onExit,
|
14 | onExiting,
|
15 | onExited,
|
16 | addEndListener,
|
17 | children,
|
18 | childRef,
|
19 | ...props
|
20 | }, ref) => {
|
21 | const nodeRef = useRef(null);
|
22 | const mergedRef = useMergedRefs(nodeRef, childRef);
|
23 | const attachRef = r => {
|
24 | mergedRef(safeFindDOMNode(r));
|
25 | };
|
26 | const normalize = callback => param => {
|
27 | if (callback && nodeRef.current) {
|
28 | callback(nodeRef.current, param);
|
29 | }
|
30 | };
|
31 |
|
32 |
|
33 | const handleEnter = useCallback(normalize(onEnter), [onEnter]);
|
34 | const handleEntering = useCallback(normalize(onEntering), [onEntering]);
|
35 | const handleEntered = useCallback(normalize(onEntered), [onEntered]);
|
36 | const handleExit = useCallback(normalize(onExit), [onExit]);
|
37 | const handleExiting = useCallback(normalize(onExiting), [onExiting]);
|
38 | const handleExited = useCallback(normalize(onExited), [onExited]);
|
39 | const handleAddEndListener = useCallback(normalize(addEndListener), [addEndListener]);
|
40 |
|
41 |
|
42 | return _jsx(Transition, {
|
43 | ref: ref,
|
44 | ...props,
|
45 | onEnter: handleEnter,
|
46 | onEntered: handleEntered,
|
47 | onEntering: handleEntering,
|
48 | onExit: handleExit,
|
49 | onExited: handleExited,
|
50 | onExiting: handleExiting,
|
51 | addEndListener: handleAddEndListener,
|
52 | nodeRef: nodeRef,
|
53 | children: typeof children === 'function' ? (status, innerProps) =>
|
54 |
|
55 | children(status, {
|
56 | ...innerProps,
|
57 | ref: attachRef
|
58 | }) : React.cloneElement(children, {
|
59 | ref: attachRef
|
60 | })
|
61 | });
|
62 | });
|
63 | export default TransitionWrapper; |
\ | No newline at end of file |