Skip to content

Commit

Permalink
feat(WizardSlideshow): component to be used on wizard-related logics …
Browse files Browse the repository at this point in the history
…to render a step with animation between steps
  • Loading branch information
YossiSaadi committed Oct 21, 2024
1 parent c793e13 commit b3c716b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.slideshow {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
32 changes: 32 additions & 0 deletions packages/core/src/components/WizardSlideshow/WizardSlideshow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { forwardRef } from "react";
import cx from "classnames";
import { AnimatePresence } from "framer-motion";
import { WizardSlideshowProps } from "./WizardSlideshow.types";
import { getTestId } from "../../tests/test-ids-utils";
import { ComponentDefaultTestId } from "../../tests/constants";
import styles from "./WizardSlideshow.module.scss";
import SlideTransition from "../SlideTransition/SlideTransition";

const WizardSlideshow = forwardRef(
(
{ activeStep, direction, id, className, "data-testid": dataTestId, children }: WizardSlideshowProps,
ref: React.ForwardedRef<HTMLDivElement>
) => {
return (
<div
id={id}
className={cx(styles.slideshow, className)}
data-testid={dataTestId || getTestId(ComponentDefaultTestId.WIZARD_SLIDESHOW, id)}
ref={ref}
>
<AnimatePresence initial={false} exitBeforeEnter custom={direction}>
<SlideTransition key={activeStep} direction={direction}>
{children[activeStep]}
</SlideTransition>
</AnimatePresence>
</div>
);
}
);

export default WizardSlideshow;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import { VibeComponentProps } from "../../types";
import { SlideDirection } from "../SlideTransition/SlideTransition.types";

export interface WizardSlideshowProps extends VibeComponentProps {
activeStep: number;
direction: WizardDirection;
children: React.ReactNode[];
}

export type WizardDirection = SlideDirection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import WizardSlideshow from "../WizardSlideshow";

jest.mock("framer-motion", () => {
const actual = jest.requireActual<typeof import("framer-motion")>("framer-motion");
return {
...actual,
AnimatePresence: ({ children }: { children: React.ReactNode }) => <>{children}</>
};
});

describe("WizardSlideshow", () => {
const mockChildren = [<div key="1">Step 1</div>, <div key="2">Step 2</div>, <div key="3">Step 3</div>];

it("should render first step", () => {
render(
<WizardSlideshow activeStep={0} direction="forward">
{mockChildren}
</WizardSlideshow>
);
expect(screen.getByText("Step 1")).toBeInTheDocument();
});

it("should display the correct step based on activeStep prop", () => {
const { rerender } = render(
<WizardSlideshow activeStep={0} direction="forward">
{mockChildren}
</WizardSlideshow>
);
expect(screen.getByText("Step 1")).toBeInTheDocument();

rerender(
<WizardSlideshow activeStep={1} direction="forward">
{mockChildren}
</WizardSlideshow>
);
expect(screen.getByText("Step 2")).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions packages/core/src/tests/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum ComponentDefaultTestId {
// Don't remove next line
// plop_marker:default-data-testid-declarations
WIZARD_SLIDESHOW = "wizard-slideshow",
TEXT_AREA = "text-area",
EDITABLE_TEXT = "editable-text",
TIPSEEN_MEDIA = "tipseen-media",
Expand Down

0 comments on commit b3c716b

Please sign in to comment.