From d4eb191f69fec958c44864d6eee910e5b69a2f57 Mon Sep 17 00:00:00 2001 From: bender Date: Sun, 8 Mar 2026 21:29:29 +0000 Subject: [PATCH] Update src/components/cardStack/layouts/carousels/AutoCarousel.tsx --- .../layouts/carousels/AutoCarousel.tsx | 187 +++++------------- 1 file changed, 47 insertions(+), 140 deletions(-) diff --git a/src/components/cardStack/layouts/carousels/AutoCarousel.tsx b/src/components/cardStack/layouts/carousels/AutoCarousel.tsx index 85ad98e..ea02de4 100644 --- a/src/components/cardStack/layouts/carousels/AutoCarousel.tsx +++ b/src/components/cardStack/layouts/carousels/AutoCarousel.tsx @@ -1,148 +1,55 @@ -"use client"; +'use client'; -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"; +import React, { useRef, useEffect } from 'react'; +import { useCardAnimation } from '@/hooks/useCardAnimation'; +import { cn } from '@/lib/utils'; -const AutoCarousel = ({ - children, - uniformGridCustomHeightClasses, +export type CardAnimationType = 'none' | 'opacity' | 'slide-up' | 'scale-rotate' | 'blur-reveal'; + +interface AutoCarouselProps { + children: React.ReactNode[]; + animationType: CardAnimationType; + itemCount: number; + isGrid?: boolean; + className?: string; +} + +export const AutoCarousel: React.FC = ({ + children, + animationType, + itemCount, + isGrid = false, + className, +}) => { + const containerRef = useRef(null); + const itemRefs = useRef<(HTMLDivElement | null)[]>([]); + + const { itemRefs: animationItemRefs } = useCardAnimation({ 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 - }); + itemCount, + isGrid, + }); - // Bottom marquee direction is opposite of top - const bottomMarqueeDirection = topMarqueeDirection === "left" ? "right" : "left"; + useEffect(() => { + itemRefs.current = itemRefs.current.slice(0, itemCount); + }, [itemCount]); - // Reverse order for bottom marquee to avoid alignment with top - const bottomChildren = dualMarquee ? [...childrenArray].reverse() : []; - - return ( -
+ {React.Children.map(children, (child, index) => ( +
{ + if (el) itemRefs.current[index] = el; + if (animationItemRefs && animationItemRefs[index]) animationItemRefs[index].current = el; + }} + className="carousel-item" > -
-
-
- {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} -
- )} -
-
-
-
- ); + {child} + + ))} + + ); }; -AutoCarousel.displayName = "AutoCarousel"; - -export default memo(AutoCarousel); +export default AutoCarousel;