11'use client' ;
2- import React from 'react' ;
2+ import React , { useEffect , useState , useRef } from 'react' ;
33import Icon from '@/components/Icon' ;
44
5- type Props = {
6- active : boolean ;
7- onChange : ( active : boolean ) => void ;
8- className ?: string ;
9- } ;
10-
5+ // needs to be hardcoded because tailwind doesn't support dynamic classes
116const breakpoints = [
127 { name : 'xs' , classes : 'inline sm:hidden' } ,
138 { name : 'sm' , classes : 'hidden sm:inline md:hidden' } ,
@@ -19,43 +14,60 @@ const breakpoints = [
1914 { name : '4xl' , classes : 'hidden 4xl:inline' } ,
2015] ;
2116
22- const GridOverlayToggle : React . FC < Props > = ( { active, onChange, className = '' } ) => (
23- < button
24- onClick = { ( ) => onChange ( ! active ) }
25- className = { `
26- ${ className }
27- flex items-center
28- w-32 h-12
29- rounded-lg
30- px-3
31- bg-neu-navy-base
32- shadow-neu-navy-base
33- transition-all duration-200
34- ` }
35- >
36- < div className = "flex items-end mr-2" >
37- < span className = "text-white text-display-label font-bold leading-tight" > Grid</ span >
38- < span className = "text-display-caption text-neu-white-darker ml-1" >
39- { breakpoints . map ( ( { name, classes } ) => (
40- < span key = { name } className = { classes } >
41- ({ name } )
42- </ span >
43- ) ) }
44- </ span >
45- </ div >
17+ const GridOverlayToggle : React . FC = ( ) => {
18+ const [ active , setActive ] = useState ( false ) ;
19+ const mainRef = useRef < HTMLElement | null > ( null ) ;
20+
21+ // Get main element reference once on mount
22+ useEffect ( ( ) => {
23+ mainRef . current = document . querySelector ( 'main' ) ;
24+ } , [ ] ) ;
4625
47- < div
26+ // Toggle grid overlay
27+ useEffect ( ( ) => {
28+ if ( mainRef . current ) {
29+ mainRef . current . setAttribute ( 'data-grid-overlay' , active ? 'active' : '' ) ;
30+ }
31+ } , [ active ] ) ;
32+
33+ return (
34+ < button
35+ onClick = { ( ) => setActive ( prev => ! prev ) }
4836 className = { `
49- flex items-center justify-center
50- w-[36px] h-[36px]
51- rounded-full
52- bg-neu-navy-dark
53- shadow-neu-navy-inset
37+ flex items-center
38+ w-32 h-12
39+ rounded-lg
40+ px-3
41+ bg-neu-navy-base
42+ shadow-neu-navy-base
43+ transition-all duration-200
44+ fixed bottom-8 right-4 z-20
5445 ` }
5546 >
56- < Icon type = "grid" active = { active } size = { 18 } />
57- </ div >
58- </ button >
59- ) ;
47+ < div className = "flex items-end mr-2" >
48+ < span className = "text-white text-display-label font-bold leading-tight" > Grid</ span >
49+ < span className = "text-display-caption text-neu-white-darker ml-1" >
50+ { breakpoints . map ( ( { name, classes } ) => (
51+ < span key = { name } className = { classes } >
52+ ({ name } )
53+ </ span >
54+ ) ) }
55+ </ span >
56+ </ div >
57+
58+ < div
59+ className = { `
60+ flex items-center justify-center
61+ w-[36px] h-[36px]
62+ rounded-full
63+ bg-neu-navy-dark
64+ shadow-neu-navy-inset
65+ ` }
66+ >
67+ < Icon type = "grid" active = { active } size = { 18 } />
68+ </ div >
69+ </ button >
70+ ) ;
71+ } ;
6072
6173export default GridOverlayToggle ;
0 commit comments