'use client'; import Link from 'next/link'; import { useEffect, useState } from 'react'; import { usePathname } from 'next/navigation'; import { ChevronRight, Menu, X } from 'lucide-react'; import type { NavItem } from '@/config/nav'; import { LogoMark } from './logo'; export function MobileNav({ items, groups }: { items: NavItem[]; groups: Array<{ id: NavItem['group']; label: string }> }) { const [open, setOpen] = useState(false); const pathname = usePathname(); const [prevPath, setPrevPath] = useState(pathname); if (pathname !== prevPath) { // close the drawer on navigation (state adjustment during render, no effect needed) setPrevPath(pathname); setOpen(false); } useEffect(() => { document.body.style.overflow = open ? 'hidden' : ''; const onKey = (e: KeyboardEvent) => e.key === 'Escape' && setOpen(false); window.addEventListener('keydown', onKey); return () => { document.body.style.overflow = ''; window.removeEventListener('keydown', onKey); }; }, [open]); return (
{open ? (
setOpen(false)} />
RareIndex
) : null}
); }