diff --git a/src/components/cardStack/layouts/carousels/ArrowCarousel.tsx b/src/components/cardStack/layouts/carousels/ArrowCarousel.tsx index 80fe4c7..22d2132 100644 --- a/src/components/cardStack/layouts/carousels/ArrowCarousel.tsx +++ b/src/components/cardStack/layouts/carousels/ArrowCarousel.tsx @@ -1,18 +1,144 @@ -'use client'; +"use client"; -import React from 'react'; -import { ArrowCarouselProps } from '@/components/cardStack/types'; +import { memo, Children, useCallback, useEffect, useState } from "react"; +import useEmblaCarousel from "embla-carousel-react"; +import { EmblaCarouselType } from "embla-carousel"; +import CardStackTextBox from "../../CardStackTextBox"; +import { cls } from "@/lib/utils"; +import { ChevronLeft, ChevronRight } from "lucide-react"; +import { ArrowCarouselProps } from "../../types"; -const ArrowCarousel: React.FC = ({ items, className = '' }) => { - return ( -
- {items.map((item, index) => ( -
- {item.title} -
- ))} -
- ); +const ArrowCarousel = ({ + children, + title, + titleSegments, + description, + tag, + tagIcon, + tagAnimation, + buttons, + buttonAnimation, + textboxLayout = "default", + useInvertedBackground, + className = "", + containerClassName = "", + carouselClassName = "", + controlsClassName = "", + textBoxClassName = "", + titleClassName = "", + titleImageWrapperClassName = "", + titleImageClassName = "", + descriptionClassName = "", + tagClassName = "", + buttonContainerClassName = "", + buttonClassName = "", + buttonTextClassName = "", + ariaLabel = "Carousel section", +}: ArrowCarouselProps) => { + const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true, align: "center" }); + const [selectedIndex, setSelectedIndex] = useState(0); + + const childrenArray = Children.toArray(children); + + const onSelect = useCallback((emblaApi: EmblaCarouselType) => { + setSelectedIndex(emblaApi.selectedScrollSnap()); + }, []); + + const scrollPrev = useCallback(() => emblaApi?.scrollPrev(), [emblaApi]); + const scrollNext = useCallback(() => emblaApi?.scrollNext(), [emblaApi]); + + useEffect(() => { + if (!emblaApi) return; + + onSelect(emblaApi); + emblaApi.on("select", onSelect).on("reInit", onSelect); + + return () => { + emblaApi.off("select", onSelect).off("reInit", onSelect); + }; + }, [emblaApi, onSelect]); + + return ( +
+
+
+ +
+ +
+
+
+ {childrenArray.map((child, index) => ( +
+
+ {child} +
+
+ ))} +
+
+ +
+ + +
+
+
+
+ ); }; -export default ArrowCarousel; +ArrowCarousel.displayName = "ArrowCarousel"; + +export default memo(ArrowCarousel);