1- "use client" ;
1+ /* eslint-disable react-hooks/exhaustive-deps */
2+ /* eslint-disable @typescript-eslint/no-unused-vars */
3+ /* eslint-disable @typescript-eslint/no-explicit-any */
4+ 'use client'
25
3- import { useEffect , useId , useRef , useState } from " react" ;
4- import { motion } from " framer-motion" ;
6+ import { useEffect , useId , useRef , useState } from ' react'
7+ import { motion } from ' framer-motion'
58
6- import { cn } from " @/lib/utils" ;
9+ import { cn } from ' @/lib/utils'
710
811interface GridPatternProps {
9- width ?: number ;
10- height ?: number ;
11- x ?: number ;
12- y ?: number ;
13- strokeDasharray ?: any ;
14- numSquares ?: number ;
15- className ?: string ;
16- maxOpacity ?: number ;
17- duration ?: number ;
18- repeatDelay ?: number ;
12+ width ?: number
13+ height ?: number
14+ x ?: number
15+ y ?: number
16+ strokeDasharray ?: any
17+ numSquares ?: number
18+ className ?: string
19+ maxOpacity ?: number
20+ duration ?: number
21+ repeatDelay ?: number
1922}
2023
2124export function GridPattern ( {
@@ -31,24 +34,24 @@ export function GridPattern({
3134 repeatDelay = 0.5 ,
3235 ...props
3336} : GridPatternProps ) {
34- const id = useId ( ) ;
35- const containerRef = useRef ( null ) ;
36- const [ dimensions , setDimensions ] = useState ( { width : 0 , height : 0 } ) ;
37- const [ squares , setSquares ] = useState ( ( ) => generateSquares ( numSquares ) ) ;
37+ const id = useId ( )
38+ const containerRef = useRef ( null )
39+ const [ dimensions , setDimensions ] = useState ( { width : 0 , height : 0 } )
40+ const [ squares , setSquares ] = useState ( ( ) => generateSquares ( numSquares ) )
3841
3942 function getPos ( ) {
4043 return [
4144 Math . floor ( ( Math . random ( ) * dimensions . width ) / width ) ,
42- Math . floor ( ( Math . random ( ) * dimensions . height ) / height ) ,
43- ] ;
45+ Math . floor ( ( Math . random ( ) * dimensions . height ) / height )
46+ ]
4447 }
4548
4649 // Adjust the generateSquares function to return objects with an id, x, and y
4750 function generateSquares ( count : number ) {
4851 return Array . from ( { length : count } , ( _ , i ) => ( {
4952 id : i ,
50- pos : getPos ( ) ,
51- } ) ) ;
53+ pos : getPos ( )
54+ } ) )
5255 }
5356
5457 // Function to update a single square's position
@@ -58,70 +61,60 @@ export function GridPattern({
5861 sq . id === id
5962 ? {
6063 ...sq ,
61- pos : getPos ( ) ,
64+ pos : getPos ( )
6265 }
63- : sq ,
64- ) ,
65- ) ;
66- } ;
66+ : sq
67+ )
68+ )
69+ }
6770
6871 // Update squares to animate in
6972 useEffect ( ( ) => {
7073 if ( dimensions . width && dimensions . height ) {
71- setSquares ( generateSquares ( numSquares ) ) ;
74+ setSquares ( generateSquares ( numSquares ) )
7275 }
73- } , [ dimensions , numSquares ] ) ;
76+ // eslint-disable-next-line react-hooks/exhaustive-deps
77+ } , [ dimensions , numSquares ] )
7478
7579 // Resize observer to update container dimensions
7680 useEffect ( ( ) => {
7781 const resizeObserver = new ResizeObserver ( ( entries ) => {
78- for ( let entry of entries ) {
82+ for ( const entry of entries ) {
7983 setDimensions ( {
8084 width : entry . contentRect . width ,
81- height : entry . contentRect . height ,
82- } ) ;
85+ height : entry . contentRect . height
86+ } )
8387 }
84- } ) ;
88+ } )
8589
8690 if ( containerRef . current ) {
87- resizeObserver . observe ( containerRef . current ) ;
91+ resizeObserver . observe ( containerRef . current )
8892 }
8993
9094 return ( ) => {
9195 if ( containerRef . current ) {
92- resizeObserver . unobserve ( containerRef . current ) ;
96+ resizeObserver . unobserve ( containerRef . current )
9397 }
94- } ;
95- } , [ containerRef ] ) ;
98+ }
99+ } , [ containerRef ] )
96100
97101 return (
98102 < svg
99103 ref = { containerRef }
100- aria-hidden = " true"
104+ aria-hidden = ' true'
101105 className = { cn (
102- " pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30" ,
103- className ,
106+ ' pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30' ,
107+ className
104108 ) }
105109 { ...props }
106110 >
107111 < defs >
108- < pattern
109- id = { id }
110- width = { width }
111- height = { height }
112- patternUnits = "userSpaceOnUse"
113- x = { x }
114- y = { y }
115- >
116- < path
117- d = { `M.5 ${ height } V.5H${ width } ` }
118- fill = "none"
119- strokeDasharray = { strokeDasharray }
120- />
112+ < pattern id = { id } width = { width } height = { height } patternUnits = 'userSpaceOnUse' x = { x } y = { y } >
113+ < path d = { `M.5 ${ height } V.5H${ width } ` } fill = 'none' strokeDasharray = { strokeDasharray } />
121114 </ pattern >
122115 </ defs >
123- < rect width = " 100%" height = " 100%" fill = { `url(#${ id } )` } />
124- < svg x = { x } y = { y } className = " overflow-visible" >
116+ < rect width = ' 100%' height = ' 100%' fill = { `url(#${ id } )` } />
117+ < svg x = { x } y = { y } className = ' overflow-visible' >
125118 { squares . map ( ( { pos : [ x , y ] , id } , index ) => (
126119 < motion . rect
127120 initial = { { opacity : 0 } }
@@ -130,21 +123,21 @@ export function GridPattern({
130123 duration,
131124 repeat : 1 ,
132125 delay : index * 0.1 ,
133- repeatType : " reverse" ,
126+ repeatType : ' reverse'
134127 } }
135128 onAnimationComplete = { ( ) => updateSquarePosition ( id ) }
136129 key = { `${ x } -${ y } -${ index } ` }
137130 width = { width - 1 }
138131 height = { height - 1 }
139132 x = { x * width + 1 }
140133 y = { y * height + 1 }
141- fill = " currentColor"
142- strokeWidth = "0"
134+ fill = ' currentColor'
135+ strokeWidth = '0'
143136 />
144137 ) ) }
145138 </ svg >
146139 </ svg >
147- ) ;
140+ )
148141}
149142
150- export default GridPattern ;
143+ export default GridPattern
0 commit comments