1"use client"23importReact,{ useState }from"react"45import{ cn }from"@/lib/utils"67/**
8 * InteractiveGridPattern is a component that renders a grid pattern with interactive squares.
9 *
10 * @param width - The width of each square.
11 * @param height - The height of each square.
12 * @param squares - The number of squares in the grid. The first element is the number of horizontal squares, and the second element is the number of vertical squares.
13 * @param className - The class name of the grid.
14 * @param squaresClassName - The class name of the squares.
15 */16interfaceInteractiveGridPatternPropsextendsReact.SVGProps<SVGSVGElement>{17 width?:number18 height?:number19 squares?:[number,number]// [horizontal, vertical]20 className?:string21 squaresClassName?:string22}2324/**
25 * The InteractiveGridPattern component.
26 *
27 * @see InteractiveGridPatternProps for the props interface.
28 * @returns A React component.
29 */30exportfunctionInteractiveGridPattern({31 width =40,32 height =40,33 squares =[24,24],34 className,35 squaresClassName,36...props
37}:InteractiveGridPatternProps){38const[horizontal, vertical]= squares
39const[hoveredSquare, setHoveredSquare]=useState<number|null>(null)4041return(42<svg43width={width * horizontal}44height={height * vertical}45className={cn(46"absolute inset-0 h-full w-full border border-gray-400/30",47 className
48)}49{...props}50>51{Array.from({ length: horizontal * vertical }).map((_, index)=>{52const x =(index % horizontal)* width
53const y =Math.floor(index / horizontal)* height
54return(55<rect56key={index}57x={x}58y={y}59width={width}60height={height}61className={cn(62"stroke-gray-400/30 transition-all duration-100 ease-in-out not-[&:hover]:duration-1000",63 hoveredSquare === index ?"fill-gray-300/30":"fill-transparent",64 squaresClassName
65)}66onMouseEnter={()=>setHoveredSquare(index)}67onMouseLeave={()=>setHoveredSquare(null)}68/>69)70})}71</svg>72)73}74