11// Docs section shell: sidebar of documents (from the registry) + the routed
22// document via <Outlet/>.
33import { Link, Outlet, useParams } from '@octanejs/tanstack-router';
4- import { useState } from 'octane';
54import { OnThisPage } from '../components/OnThisPage.tsrx';
65import { docGroups, defaultDoc, findDoc } from '../content/docs.ts';
6+ import { useMobileNavigation } from '../hooks/use-mobile-navigation.ts';
77
88export function DocsLayout() @{
9- const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
10- const closeMobileNavigation = () => {
11- if (!mobileMenuOpen) return;
12- setMobileMenuOpen(false);
13- // Reveal the target only after the overlay has closed. A timer also covers
14- // browsers that omit transitionend.
15- const reduce =
16- typeof window.matchMedia === 'function' &&
17- window.matchMedia('(prefers-reduced-motion: reduce)').matches;
18- return new Promise<void>((resolve) => window.setTimeout(resolve, reduce ? 0 : 240));
19- };
9+ const mobileNavigation = useMobileNavigation();
2010
2111 // The Link's own data-status covers `/docs/$slug`, but the bare `/docs` index
2212 // renders the default doc (quick-start) without a slug in the URL — so no link
@@ -31,14 +21,14 @@ export function DocsLayout() @{
3121 <button
3222 type="button"
3323 class="sidebar-mobile-toggle"
34- aria-expanded={mobileMenuOpen }
24+ aria-expanded={mobileNavigation.open }
3525 aria-controls="docs-sidebar-nav"
36- onClick={() => setMobileMenuOpen((open) => !open) }
26+ onClick={mobileNavigation.toggle }
3727 >
3828 <span>Documentation</span>
3929 <span class="sidebar-mobile-icon" aria-hidden="true">+</span>
4030 </button>
41- <div class={['sidebar-panel', mobileMenuOpen && 'is-open']}>
31+ <div class={['sidebar-panel', mobileNavigation.open && 'is-open']}>
4232 <div class="sidebar-panel-inner">
4333 <nav id="docs-sidebar-nav" class="sidebar-nav" aria-label="Documentation">
4434 <p class="sidebar-title">Documentation</p>
@@ -56,7 +46,7 @@ export function DocsLayout() @{
5646 params={{ slug: doc.slug }}
5747 class={['sidebar-link', indexActive(doc.slug) && 'is-active']}
5848 onClick={() => {
59- void closeMobileNavigation ();
49+ void mobileNavigation.close ();
6050 }}
6151 >
6252 {doc.title as string}
@@ -65,7 +55,7 @@ export function DocsLayout() @{
6555 <OnThisPage
6656 sections={doc.sections}
6757 resetKey={doc.slug}
68- onNavigate={closeMobileNavigation }
58+ onNavigate={mobileNavigation.close }
6959 />
7060 }
7161 </li>
0 commit comments