1+ import { Bars3BottomLeftIcon , XMarkIcon } from '@heroicons/react/20/solid' ;
12import { Link , useRouterState } from '@tanstack/react-router' ;
3+ import { useState } from 'react' ;
24import icon from '~/assets/images/icon-transparent.png' ;
35import { Button } from '~/components/button' ;
46import { cn } from '~/utils/helpers' ;
@@ -31,6 +33,12 @@ function NavbarItem({ page, route }: { page: NavPage; route: NavRoute }) {
3133}
3234
3335export function Navbar ( ) {
36+ const [ showMenu , setShowMenu ] = useState ( false ) ;
37+
38+ const toggleMenu = ( ) => {
39+ setShowMenu ( ( prev ) => ! prev ) ;
40+ } ;
41+
3442 return (
3543 < div className = "flex items-center h-20 gap-8 px-4 border-b shadow-sm select-none shadow-primary-dark/50 min-h-20 border-primary/80 overflow-clip" >
3644 < Link
@@ -40,11 +48,31 @@ export function Navbar() {
4048 < img src = { icon } id = "logo" alt = "logo" className = "cursor-pointer w-14 h-14" draggable = { false } />
4149 </ Link >
4250
43- < ul className = "flex gap-8 " >
51+ < ul className = "hidden gap-4 overflow-x-auto md:flex " >
4452 { Object . entries ( NAV_PAGES ) . map ( ( [ page , route ] ) => (
4553 < NavbarItem key = { page } page = { page as keyof typeof NAV_PAGES } route = { route } />
4654 ) ) }
4755 </ ul >
56+
57+ < div className = "flex justify-end flex-1 md:hidden" >
58+ < Button
59+ className = "px-2 py-1 text-lg rounded-lg cursor-pointer text-primary hover:bg-black/10"
60+ variant = "ghost"
61+ onClick = { toggleMenu }
62+ >
63+ { showMenu ? < XMarkIcon width = { 24 } height = { 24 } /> : < Bars3BottomLeftIcon width = { 24 } height = { 24 } /> }
64+ </ Button >
65+
66+ < div >
67+ { showMenu && (
68+ < ul className = "absolute flex flex-col gap-2 p-4 border rounded-lg shadow-lg bg-background top-16 right-4 md:hidden border-primary/40" >
69+ { Object . entries ( NAV_PAGES ) . map ( ( [ page , route ] ) => (
70+ < NavbarItem key = { page } page = { page as keyof typeof NAV_PAGES } route = { route } />
71+ ) ) }
72+ </ ul >
73+ ) }
74+ </ div >
75+ </ div >
4876 </ div >
4977 ) ;
5078}
0 commit comments