From bab04bed9785e3b44e54b0862540f158e8624d8a Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 4 Mar 2026 19:07:04 +0000 Subject: [PATCH] Switch to version 1: modified src/components/cardStack/layouts/carousels/AutoCarousel.tsx --- .../layouts/carousels/AutoCarousel.tsx | 182 ++++++++++++++---- 1 file changed, 141 insertions(+), 41 deletions(-) diff --git a/src/components/cardStack/layouts/carousels/AutoCarousel.tsx b/src/components/cardStack/layouts/carousels/AutoCarousel.tsx index f3cbdeb..85ad98e 100644 --- a/src/components/cardStack/layouts/carousels/AutoCarousel.tsx +++ b/src/components/cardStack/layouts/carousels/AutoCarousel.tsx @@ -1,48 +1,148 @@ -import React, { useRef } from 'react'; -import { useCardAnimation, UseCardAnimationOptions } from '@/hooks/useCardAnimation'; +"use client"; -export interface AutoCarouselProps { - children: React.ReactNode; - title?: string; - description?: string; - textboxLayout?: string; - animationType?: string; - className?: string; - carouselClassName?: string; - containerClassName?: string; - itemClassName?: string; - ariaLabel?: string; - showTextBox?: boolean; - tag?: string; - tagIcon?: any; - tagAnimation?: string; - buttons?: Array<{ text: string; onClick?: () => void; href?: string }>; - buttonAnimation?: string; - titleSegments?: Array<{ type: 'text'; content: string } | { type: 'image'; src: string; alt?: string }>; -} +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"; -export const AutoCarousel: React.FC = ({ - children, - containerClassName = '', - ...props -}) => { - const containerRef = useRef(null); - const itemRefs = useRef<(HTMLDivElement | null)[]>([]); - const bottomContentRef = useRef(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 + }); - const animationOptions: UseCardAnimationOptions = { - containerRef, - itemRefs, - bottomContentRef, - }; + // Bottom marquee direction is opposite of top + const bottomMarqueeDirection = topMarqueeDirection === "left" ? "right" : "left"; - const { } = useCardAnimation(animationOptions); + // Reverse order for bottom marquee to avoid alignment with top + const bottomChildren = dualMarquee ? [...childrenArray].reverse() : []; - return ( -
- {children} -
- ); + 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);