From 2ae3e744404ef7364927ac62d16e0aa298e6b5fd Mon Sep 17 00:00:00 2001 From: bender Date: Mon, 9 Mar 2026 08:26:28 +0000 Subject: [PATCH] Switch to version 1: modified src/components/cardStack/layouts/grid/GridLayout.tsx --- .../cardStack/layouts/grid/GridLayout.tsx | 170 +++++++++++++++--- 1 file changed, 147 insertions(+), 23 deletions(-) diff --git a/src/components/cardStack/layouts/grid/GridLayout.tsx b/src/components/cardStack/layouts/grid/GridLayout.tsx index bbf678c..f308c49 100644 --- a/src/components/cardStack/layouts/grid/GridLayout.tsx +++ b/src/components/cardStack/layouts/grid/GridLayout.tsx @@ -1,26 +1,150 @@ -import React, { useRef } from "react"; -import { useCardAnimation } from "@/components/cardStack/hooks/useCardAnimation"; +"use client"; -interface GridLayoutProps { - items?: any[]; -} +import { memo, Children } from "react"; +import CardStackTextBox from "../../CardStackTextBox"; +import { cls } from "@/lib/utils"; +import { GridLayoutProps } from "../../types"; +import { gridConfigs } from "./gridConfigs"; +import { useCardAnimation } from "../../hooks/useCardAnimation"; -export default function GridLayout({ items = [] }: GridLayoutProps) { - const state = useCardAnimation({ - rotationX: 0, - rotationY: 0, - rotationZ: 0, - perspective: 1000, - duration: 0.3, - }); +const GridLayout = ({ + children, + itemCount, + gridVariant = "uniform-all-items-equal", + uniformGridCustomHeightClasses, + gridRowsClassName, + itemHeightClassesOverride, + animationType, + supports3DAnimation = false, + title, + titleSegments, + description, + tag, + tagIcon, + tagAnimation, + buttons, + buttonAnimation, + textboxLayout = "default", + useInvertedBackground, + bottomContent, + className = "", + containerClassName = "", + gridClassName = "", + textBoxClassName = "", + titleClassName = "", + titleImageWrapperClassName = "", + titleImageClassName = "", + descriptionClassName = "", + tagClassName = "", + buttonContainerClassName = "", + buttonClassName = "", + buttonTextClassName = "", + ariaLabel, +}: GridLayoutProps) => { + // Get config for this variant and item count + const config = gridConfigs[gridVariant]?.[itemCount]; - return ( -
- {items.map((item, index) => ( -
- {item.label} -
- ))} -
- ); -} + // Fallback to default uniform grid if no config + const gridColsMap = { + 1: "md:grid-cols-1", + 2: "md:grid-cols-2", + 3: "md:grid-cols-3", + 4: "md:grid-cols-4", + }; + const defaultGridCols = gridColsMap[itemCount as keyof typeof gridColsMap] || "md:grid-cols-4"; + + // Use config values or fallback + const gridCols = config?.gridCols || defaultGridCols; + const gridRows = gridRowsClassName || config?.gridRows || ""; + const itemClasses = config?.itemClasses || []; + const itemHeightClasses = itemHeightClassesOverride || config?.itemHeightClasses || []; + const heightClasses = uniformGridCustomHeightClasses || config?.heightClasses || ""; + const itemWrapperClass = config?.itemWrapperClass || ""; + + const childrenArray = Children.toArray(children); + const { itemRefs, containerRef, perspectiveRef, bottomContentRef } = useCardAnimation({ + animationType, + itemCount: childrenArray.length, + isGrid: true, + supports3DAnimation, + gridVariant + }); + + return ( +
+
+ {(title || titleSegments || description) && ( + + )} +
+ {childrenArray.map((child, index) => { + const itemClass = itemClasses[index] || ""; + const itemHeightClass = itemHeightClasses[index] || ""; + const combinedClass = cls(itemWrapperClass, itemClass, itemHeightClass, heightClasses); + return combinedClass ? ( +
{ itemRefs.current[index] = el; }} + > + {child} +
+ ) : ( +
{ itemRefs.current[index] = el; }} + > + {child} +
+ ); + })} +
+ {bottomContent && ( +
+ {bottomContent} +
+ )} +
+
+ ); +}; + +GridLayout.displayName = "GridLayout"; + +export default memo(GridLayout);