"use client"; import { motion, useTransform, useScroll } from "framer-motion"; import React, { useRef, ReactNode } from "react"; interface CarouselItem { id: string | number; content: ReactNode; contentid: ReactNode; } interface HorizontalCarouselProps { items: CarouselItem[]; itemWidth?: string; itemHeight?: string; gap?: string; scrollLength?: string; initialXOffset?: string; finalXOffset?: string; children?: ReactNode; afterCarouselContent?: ReactNode; } const HorizontalCarousel: React.FC = ({ items, itemWidth = "90vw", itemHeight = "450px", gap = "1rem", scrollLength = "150vh", initialXOffset = "80%", // Start far off-screen finalXOffset = "-95%", // End fully off-screen left children, afterCarouselContent, }) => { const targetRef = useRef(null); const { scrollYProgress } = useScroll({ target: targetRef, offset: ["start end", "end start"], }); // Delay entrance even more (start at 20% scroll progress) const x = useTransform( scrollYProgress, [0.2, 1], [initialXOffset, finalXOffset] ); return (
{children && (
{children}
)}
{items.map((item) => (
{item.content}

{String(item.contentid) .replace(/-/g, " ") .replace(/\b\w/g, (l) => l.toUpperCase())}

))}
{afterCarouselContent && (
{afterCarouselContent}
)}
); }; export default HorizontalCarousel;