'use client'; import { ArrowDown01Icon, Cancel01Icon, ListViewIcon, Menu01Icon, } from '@hugeicons/core-free-icons'; import { HugeiconsIcon } from '@hugeicons/react'; import { useEffect, useState, type ReactNode } from 'react'; import { useSectionSpy, type TocItem } from './toc'; /** * Docs navigation for phones, where both rails are hidden. * * The desktop sidebar lives on the left and the section rail on the right, so * the two controls here keep those sides: the tree slides in from the left, * the section list drops down under its own button. Mount it ABOVE the padded * docs container so the bar itself can run full-bleed. * * Remount it on navigation (`key={pathname}`) — that re-derives the section * list from the new article and closes whatever was open. */ export function DocsMobileBar({ label, children }: { label: ReactNode; children: ReactNode }) { const [panel, setPanel] = useState<'none' | 'tree' | 'sections'>('none'); const { items, activeId } = useSectionSpy(); useEffect(() => { if (panel === 'none') return; const onKey = (event: KeyboardEvent) => { if (event.key === 'Escape') setPanel('none'); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [panel]); // The tree is a full-height overlay; letting the page scroll behind it // strands the reader somewhere else when it closes. useEffect(() => { if (panel !== 'tree') return; const previous = document.body.style.overflow; document.body.style.overflow = 'hidden'; return () => { document.body.style.overflow = previous; }; }, [panel]); return ( <>
{items.length > 0 ? ( ) : null}
{panel === 'sections' ? ( setPanel('none')} /> ) : null}
{panel === 'tree' ? (
{children}
) : null} ); } function SectionDropdown({ items, activeId, onPick, }: { items: TocItem[]; activeId: string | null; onPick: () => void; }) { return (
); }