'use client'; import { ChevronDown } from 'lucide-react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useEffect, useId, useRef, useState } from 'react'; import { t } from '@/i18n'; import { cn } from '@/lib/cn'; interface Item { href: string; label: string; group: 'explore' | 'reference'; } /** "More ▾" disclosure in the desktop header: two columns (Explore · Reference), keyboard + outside-click closing. */ export function MoreMenu({ items }: { items: Item[] }) { const [open, setOpen] = useState(false); const id = useId(); const ref = useRef(null); const pathname = usePathname(); const active = items.some((it) => pathname === it.href || pathname.startsWith(`${it.href}/`)); useEffect(() => { setOpen(false); }, [pathname]); useEffect(() => { if (!open) return; const onDoc = (e: PointerEvent) => { if (!ref.current?.contains(e.target as Node)) setOpen(false); }; const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(false); }; document.addEventListener('pointerdown', onDoc); document.addEventListener('keydown', onKey); return () => { document.removeEventListener('pointerdown', onDoc); document.removeEventListener('keydown', onKey); }; }, [open]); const groups: Array<{ key: Item['group']; label: string }> = [ { key: 'explore', label: t('site.footer.explore') }, { key: 'reference', label: t('site.footer.reference') }, ]; return (
{open ? ( ) : null}
); }