diff --git a/src/components/cardStack/layouts/carousels/AutoCarousel.tsx b/src/components/cardStack/layouts/carousels/AutoCarousel.tsx index 3f80a7a..85ad98e 100644 --- a/src/components/cardStack/layouts/carousels/AutoCarousel.tsx +++ b/src/components/cardStack/layouts/carousels/AutoCarousel.tsx @@ -1,22 +1,148 @@ -'use client'; +"use client"; -import React from 'react'; -import { AutoCarouselProps } from '@/components/cardStack/types'; -import { useCardAnimation } from '@/components/cardStack/hooks/useCardAnimation'; +import { memo, Children } from "react"; +import Marquee from "react-fast-marquee"; +import CardStackTextBox from "../../CardStackTextBox"; +import { cls } from "@/lib/utils"; +import { AutoCarouselProps } from "../../types"; +import { useCardAnimation } from "../../hooks/useCardAnimation"; -const AutoCarousel: React.FC = ({ items, className = '' }) => { - const animation = useCardAnimation(); - const itemRefs = React.useRef<(HTMLDivElement | null)[]>([]); +const AutoCarousel = ({ + children, + uniformGridCustomHeightClasses, + animationType, + speed = 50, + title, + titleSegments, + description, + tag, + tagIcon, + tagAnimation, + buttons, + buttonAnimation, + textboxLayout = "default", + useInvertedBackground, + bottomContent, + className = "", + containerClassName = "", + carouselClassName = "", + itemClassName = "", + textBoxClassName = "", + titleClassName = "", + titleImageWrapperClassName = "", + titleImageClassName = "", + descriptionClassName = "", + tagClassName = "", + buttonContainerClassName = "", + buttonClassName = "", + buttonTextClassName = "", + ariaLabel, + showTextBox = true, + dualMarquee = false, + topMarqueeDirection = "left", + bottomCarouselClassName = "", + marqueeGapClassName = "", +}: AutoCarouselProps) => { + const childrenArray = Children.toArray(children); + const heightClasses = uniformGridCustomHeightClasses || "min-h-80 2xl:min-h-90"; + const { itemRefs, bottomContentRef } = useCardAnimation({ + animationType, + itemCount: childrenArray.length, + isGrid: false + }); - return ( -
} className={`auto-carousel ${className}`}> - {items.map((item, index) => ( -
{ if (el) itemRefs.current[index] = el; }} className="carousel-item"> - {item.title} -
- ))} -
- ); + // Bottom marquee direction is opposite of top + const bottomMarqueeDirection = topMarqueeDirection === "left" ? "right" : "left"; + + // Reverse order for bottom marquee to avoid alignment with top + const bottomChildren = dualMarquee ? [...childrenArray].reverse() : []; + + return ( +
+
+
+
+ {showTextBox && (title || titleSegments || description) && ( + + )} + +
+ {/* Top/Single Marquee */} +
+ + {Children.map(childrenArray, (child, index) => ( +
{ itemRefs.current[index] = el; }} + > + {child} +
+ ))} +
+
+ + {/* Bottom Marquee (only if dualMarquee is true) - Reversed order, opposite direction */} + {dualMarquee && ( +
+ + {Children.map(bottomChildren, (child, index) => ( +
+ {child} +
+ ))} +
+
+ )} +
+ {bottomContent && ( +
+ {bottomContent} +
+ )} +
+
+
+
+ ); }; -export default AutoCarousel; +AutoCarousel.displayName = "AutoCarousel"; + +export default memo(AutoCarousel);