Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TransitionView): handle parent without definite height #2584

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.slide {
position: absolute;
width: 100%;
height: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SlideTransitionProps } from "./SlideTransition.types";
import styles from "./SlideTransition.module.scss";

const SlideTransition = forwardRef(
({ direction, children, className }: SlideTransitionProps, ref: React.ForwardedRef<HTMLDivElement>) => {
({ direction, style, children, className }: SlideTransitionProps, ref: React.ForwardedRef<HTMLDivElement>) => {
return (
<motion.div
ref={ref}
Expand All @@ -17,6 +17,7 @@ const SlideTransition = forwardRef(
exit="exit"
transition={slideAnimationTransition}
className={cx(styles.slide, className)}
style={style}
>
{children}
</motion.div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { VibeComponentProps } from "../../types";

export interface SlideTransitionProps extends VibeComponentProps {
direction: SlideDirection;
style?: React.CSSProperties;
children: React.ReactNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import { SlideDirection } from "../SlideTransition.types";

export const slideAnimationVariants = {
initial: (direction: SlideDirection) => ({
x: direction === "forward" ? "10%" : "-10%"
x: direction === "forward" ? "10%" : "-10%",
opacity: 0
}),
enter: {
x: 0
x: 0,
opacity: 1
},
exit: (direction: SlideDirection) => ({
x: direction === "forward" ? "-100%" : "100%"
x: direction === "forward" ? "-10%" : "10%",
opacity: 0
})
};

export const slideAnimationTransition = {
duration: 0.2,
duration: 0.1,
ease: [0.0, 0.0, 0.4, 1.0]
};
21 changes: 18 additions & 3 deletions packages/core/src/components/TransitionView/TransitionView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef } from "react";
import React, { forwardRef, useEffect, useRef, useState } from "react";
import cx from "classnames";
import { AnimatePresence } from "framer-motion";
import { TransitionViewProps } from "./TransitionView.types";
Expand All @@ -9,18 +9,33 @@ import SlideTransition from "../SlideTransition/SlideTransition";

const TransitionView = forwardRef(
(
{ activeStep, direction, id, className, "data-testid": dataTestId, children }: TransitionViewProps,
{ activeStep, direction, height, id, className, "data-testid": dataTestId, children }: TransitionViewProps,
ref: React.ForwardedRef<HTMLDivElement>
) => {
const slideTransitionRef = useRef<HTMLDivElement>(null);
const [slideHeight, setSlideHeight] = useState<number>(height);

useEffect(() => {
if (!slideTransitionRef.current) return;
setSlideHeight(slideTransitionRef.current.scrollHeight);
}, [height, slideTransitionRef]);

return (
<div
id={id}
className={cx(styles.slideshow, className)}
data-testid={dataTestId || getTestId(ComponentDefaultTestId.TRANSITION_VIEW, id)}
ref={ref}
style={{ height: height ?? slideHeight }}
>
<AnimatePresence initial={false} custom={direction}>
<SlideTransition key={activeStep} direction={direction}>
<SlideTransition
key={activeStep}
direction={direction}
// it must be "auto" on initial load to consider scrollable content in slideHeight calculation
style={{ height: height || slideHeight > 0 ? "100%" : "auto" }}
ref={slideTransitionRef}
YossiSaadi marked this conversation as resolved.
Show resolved Hide resolved
>
{children[activeStep]}
</SlideTransition>
</AnimatePresence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SlideDirection } from "../SlideTransition/SlideTransition.types";
export interface TransitionViewProps extends VibeComponentProps {
activeStep: number;
direction: TransitionDirection;
height?: number;
children: React.ReactNode[];
}

Expand Down
Loading