src/components/ui/mobile-menu.tsx (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import { useState, useEffect } from 'react' import { Button } from '@/components/ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { NAV_LINKS } from '@/consts' import { Menu } from 'lucide-react' const MobileMenu = () => { const [isOpen, setIsOpen] = useState(false) useEffect(() => { const handleViewTransitionStart = () => { setIsOpen(false) } document.addEventListener('astro:before-swap', handleViewTransitionStart) return () => { document.removeEventListener( 'astro:before-swap', handleViewTransitionStart, ) } }, []) return ( <DropdownMenu open={isOpen} onOpenChange={setIsOpen} modal={false}> <DropdownMenuTrigger asChild> <Button variant="outline" size="icon" className="md:hidden" title="Menu" > <Menu className="h-5 w-5" /> <span className="sr-only">Toggle menu</span> </Button> </DropdownMenuTrigger> <DropdownMenuContent align="end" className="bg-background"> {NAV_LINKS.map((item) => ( <DropdownMenuItem key={item.href} asChild> <a href={item.href} className="w-full text-lg font-medium capitalize" onClick={() => setIsOpen(false)} > {item.label} </a> </DropdownMenuItem> ))} </DropdownMenuContent> </DropdownMenu> ) } export default MobileMenu |