11import { useSetAtom } from 'jotai' ;
22import type { ReactNode } from 'react' ;
3- import { useId , useRef } from 'react' ;
3+ import { useEffect , useId , useRef } from 'react' ;
4+ import cs from 'classnames' ;
45import CrossSvg from '../assets/cross.svg' ;
56import HamburgerSvg from '../assets/hamburger.svg' ;
67import {
@@ -22,23 +23,36 @@ export function ExampleLayout(props: ExampleLayoutProps) {
2223 const [ menuShown , setMenuShown ] = useHydratedAtom ( menuShownAtom , false ) ;
2324 const [ codeShown , setCodeShown ] = useHydratedAtom ( codeEditorShownAtom , false ) ;
2425
26+ useEffect ( ( ) => {
27+ // Opening the side menu on large screens by default
28+ if ( window . innerWidth >= 768 ) {
29+ setMenuShown ( true ) ;
30+ }
31+ } , [ ] ) ;
32+
2533 return (
2634 < >
27- < div className = "absolute top-4 left-4 z-50 flex gap-2 text-sm md:hidden" >
35+ < div
36+ className = { cs (
37+ 'absolute top-4 left-4 md:top-5 md:left-5 z-50 flex gap-2 text-sm' ,
38+ menuShown && 'md:left-84' ,
39+ ) }
40+ >
2841 { ! menuShown && (
2942 < Button onClick = { ( ) => setMenuShown ( true ) } >
30- < img src = { HamburgerSvg . src } alt = "menu" className = "-m-2 h-6 w-6" />
43+ < img src = { HamburgerSvg . src } alt = "menu" className = "-m-2 h-6 w-6 mr-1" />
44+ Explore
3145 </ Button >
3246 ) }
3347
3448 < Button onClick = { ( ) => setCodeShown ( ( prev ) => ! prev ) } >
35- { /* Applying the actual label only after the component has been hydrated */ }
36- { codeShown ? 'Preview ' : 'Code' }
49+ < span className = "md:hidden" > { codeShown ? 'Preview' : 'Code' } </ span >
50+ < span className = "hidden md:block" > { codeShown ? 'Hide Code ' : 'Show Code' } </ span >
3751 </ Button >
3852 </ div >
39-
4053 < div className = "box-border flex h-dvh gap-4 bg-tameplum-50 p-4" >
4154 { menuShown && < SideMenu /> }
55+
4256 { props . children }
4357 </ div >
4458 </ >
@@ -57,17 +71,24 @@ function SideMenu() {
5771 const groupByCategoryToggleId = useId ( ) ;
5872
5973 return (
60- < aside className = "absolute inset-0 z-50 box-border flex w-full flex-col bg-white md:static md:w-75 md:rounded-2xl" >
74+ < aside className = "absolute inset-0 z-50 box-border flex w-full flex-col bg-white md:relative md:w-75 md:rounded-2xl" >
6175 < header className = "px-5 py-3" >
6276 < div className = "grid place-items-center" >
6377 < a href = "/TypeGPU" className = "box-border grid h-12 cursor-pointer place-content-center" >
6478 < img className = "w-40" src = "/TypeGPU/typegpu-logo-light.svg" alt = "TypeGPU Logo" />
6579 </ a >
6680 </ div >
67- < div className = "absolute top-5 right-5 md:hidden" >
68- < Button onClick = { ( ) => setMenuShown ( false ) } >
81+ < div className = "absolute top-5 right-5 md:top-2.5 md:right-2.5" >
82+ < button
83+ className = { cs (
84+ 'box-border inline-flex items-center justify-center gap-2 rounded-[6.25rem] px-2.5 py-2.5 text-sm focus:ring-2 focus:ring-gradient-blue' ,
85+ 'bg-white hover:bg-tameplum-20' ,
86+ ) }
87+ type = "button"
88+ onClick = { ( ) => setMenuShown ( false ) }
89+ >
6990 < img src = { CrossSvg . src } alt = "Close menu" className = "h-3 w-3" />
70- </ Button >
91+ </ button >
7192 </ div >
7293 </ header >
7394
0 commit comments