import React, { FC, PropsWithChildren, ReactNode, useState } from "react"; import "./index.css"; interface IProps { currentPage: number; } const AnimatedPageContainer: FC> = ( { children, currentPage }, ) => { const [uuid] = useState(crypto.randomUUID()); const renderChild = (child: ReactNode, index: number) => { const isActive = index === currentPage; let position = "active"; switch ((index - currentPage) / Math.abs(index - currentPage)) { case 1: position = "right"; break; case -1: position = "left"; break; default: position = "active"; } return (
{child}
); }; return (
{React.Children.map(children, renderChild)}
); }; export default AnimatedPageContainer;