|
1 |
| -import React, { forwardRef, useEffect, useRef, useState } from "react"; |
| 1 | +import React, { forwardRef } from "react"; |
2 | 2 | import cx from "classnames";
|
3 | 3 | import { AnimatePresence } from "framer-motion";
|
4 | 4 | import { TransitionViewProps } from "./TransitionView.types";
|
5 | 5 | import { getTestId } from "../../tests/test-ids-utils";
|
6 | 6 | import { ComponentDefaultTestId } from "../../tests/constants";
|
7 | 7 | import styles from "./TransitionView.module.scss";
|
8 | 8 | import SlideTransition from "../SlideTransition/SlideTransition";
|
9 |
| -import useMergeRef from "../../hooks/useMergeRef"; |
10 | 9 |
|
11 | 10 | const TransitionView = forwardRef(
|
12 | 11 | (
|
13 |
| - { activeStep, direction, height, id, className, "data-testid": dataTestId, children }: TransitionViewProps, |
| 12 | + { activeStep, direction, id, className, "data-testid": dataTestId, children }: TransitionViewProps, |
14 | 13 | ref: React.ForwardedRef<HTMLDivElement>
|
15 | 14 | ) => {
|
16 |
| - const componentRef = useRef<HTMLDivElement>(null); |
17 |
| - const mergedRef = useMergeRef(ref, componentRef); |
18 |
| - const slideTransitionRef = useRef<HTMLDivElement>(null); |
19 |
| - const [contentHeight, setContentHeight] = useState<number | "100%">(height); |
20 |
| - const slideTransitionHeight = height || contentHeight === "100%" || contentHeight > 0 ? "100%" : "auto"; |
21 |
| - |
22 |
| - useEffect(() => { |
23 |
| - if (!slideTransitionRef.current) return; |
24 |
| - // if parent has definite height, stretch component to fill it, otherwise use content height |
25 |
| - setContentHeight(componentRef.current.clientHeight > 0 ? "100%" : slideTransitionRef.current.scrollHeight); |
26 |
| - }, [height, slideTransitionRef]); |
27 |
| - |
28 | 15 | return (
|
29 | 16 | <div
|
30 | 17 | id={id}
|
31 | 18 | className={cx(styles.slideshow, className)}
|
32 | 19 | data-testid={dataTestId || getTestId(ComponentDefaultTestId.TRANSITION_VIEW, id)}
|
33 |
| - ref={mergedRef} |
34 |
| - style={{ height: height ?? contentHeight }} |
| 20 | + ref={ref} |
35 | 21 | >
|
36 |
| - <AnimatePresence initial={false} custom={direction}> |
37 |
| - <SlideTransition |
38 |
| - key={activeStep} |
39 |
| - direction={direction} |
40 |
| - // it must be "auto" on initial load to consider scrollable content in contentHeight calculation |
41 |
| - style={{ height: slideTransitionHeight }} |
42 |
| - ref={slideTransitionRef} |
43 |
| - > |
| 22 | + <AnimatePresence initial={false} custom={direction} exitBeforeEnter> |
| 23 | + <SlideTransition key={activeStep} direction={direction}> |
44 | 24 | {children[activeStep]}
|
45 | 25 | </SlideTransition>
|
46 | 26 | </AnimatePresence>
|
|
0 commit comments