Docs Layout
The documentation page frame: a skip link, the site header, then up to three columns, the page tree, the page and its contents. It is the one page frame with a sidebar and a contents column; marketing and reading pages keep the centered measure.
import { DocsLayout, DocsLayoutDrawer } from '@fairgarden/design/page/docs-layout'
Compose it from the system's own parts: a NavigationBar with wide as the header, whose drawer is a DocsLayoutDrawer; a SidebarNav as the sidebar; a TableOfContents as the optional toc; and the page as children. The root is a kind="band" Ground on the page ground (paper by default), so every part takes the page's role variables and follows light and dark mode, the pastel grounds and right-to-left text by itself.
function Contents() {
const activeId = useActiveHeading(headings.map((heading) => heading.id))
return <TableOfContents items={headings} activeId={activeId} />
}
<DocsLayout
header={
<NavigationBar
wide
logo={<Wordmark />}
logoLabel="Garden Handbook home"
search={<Search kind="trigger" label="Search the handbook" />}
drawer={<DocsLayoutDrawer />}
/>
}
sidebar={<SidebarNav items={handbook} currentPath={pathname} />}
toc={<Contents />}
>
{page}
</DocsLayout>
The frame
A handbook page
The columns sit inside --fgd-container-wide, which the frame reaches at a 1440 px window, with the grid gutter between them. The sidebar is a 240 px column, sticky at the top of the window with its own scroll and a hairline rule on its end edge; it opens scrolled to the current page. The page column keeps an end gutter at every width (24 px, then 44 px from 768 px) for the code blocks' hanging ⋮, and the frame clips sideways so that hit area never makes the page scroll. Prose inside keeps the reading measure. The contents column is 240 px, sticky and scrolling on its own when long. The layout renders the page's one skip link, aimed at its main, so the Navigation Bar in its header renders none. In print only the page remains: the skip link, the columns, the drawer and the contents bar are hidden, and the header prints as its masthead logo.
The demo runs in a frame that is its own viewport, so at this column's width it shows the drawer and the contents bar: scroll the page and the bar names the section in view; press it and the whole list opens, centered on that section. Open the full page to see the columns.
Thresholds
The layout adds no breakpoint. The sidebar column starts at --fgd-nav-inline-n-above (1024 px by default), the step where the header already swaps its drawer for inline navigation: below it, every navigation is in the drawer; from it, every navigation is inline. At 1024 px the page column still measures about 620 px after the sidebar, above the reading measure, while at 768 px it would fall to about 430 px, narrower than a phone held sideways. A site that sets the inline threshold to 1440 px moves the sidebar with it.
The contents column starts at --xl-n-above (1440 px), where three columns fit: 240 px, the page at about 800 px, and 240 px. At 1024 px the page would drop below 400 px. Below 1440 px the contents become their compact bar: one line at the top of the page, straight under the header, that sticks to the top of the window once the header scrolls away. It names the section in view, so a reader always knows where they are and can jump anywhere from there. It is the page's one sticky bar, since the header is static, and it sits in the page column, so it never covers the sidebar.
Zero layout shift
Every placement is viewport media in the layout's CSS: the columns, the menu Button, the contents bar. Nothing is measured and nothing waits for hydration, so the server HTML paints the final frame: no drawer flashes open, and a phone never paints the sidebar in the page flow for a frame. The contents bar has one fixed height and names the first section in the server HTML; naming another section later never changes its size, and its panel is an overlay that moves nothing. Headings in the page keep a scroll-margin so a link lands them clear of the bar. The sidebar scrolls to the current page inside its own column (before first paint where scroll-initial-target is supported), which moves nothing around it. The sidebar and the contents reserve the bold width of every entry, so marking the current page or the section in view never rewraps a line.
The drawer
DocsLayoutDrawer is the Nav Drawer showing the layout's sidebar: the same SidebarNav, from the same data. Put it in the Navigation Bar's drawer slot, which shows its menu Button below the inline threshold, exactly where the sidebar column is absent. It keeps the drawer's behavior: a full-screen sheet below 768 px and a 480 px side sheet from there, the header repeated in the sheet's bar, focus moved into the sheet (to the current page's link), trapped there, Escape to close, focus returned to the menu Button, and the page behind inert and still. If the window widens past the threshold while it is open, it closes and focus moves to the current page's link in the sidebar column. Outside a Navigation Bar, the layout hides its menu Button from the threshold itself.
The table of contents
The toc slot takes a TableOfContents. From 1440 px it fills the sticky end column; below, the layout draws the same element as the contents' compact bar (kind="bar", which it sets through TableOfContentsContext), pinned under the header. The bar names the section in view and opens the whole list in a panel about a third of the window tall, scrolled so that section sits centered and marked. Pass useActiveHeading(ids) as its activeId for scrollspy; with no items, neither the column nor the bar appears. On this site the slot is a placeholder: only this page feeds it, with its headings written out by hand, until the docs engine's page headings are wired (below).
Wiring plan (planned)
This part is planned, not built. The sidebar is already fed from the docs engine; the contents are not yet.
- Sidebar (built).
toSidebarItems(sitemap)from@fairgarden/design/utils/docsmaps the engine's sitemap, the object that also feeds search, toSidebarNavitems on the server: each section's title and index page over its pages, in index order. The layout marks the current page from the URL. - Contents data (planned). The engine already extracts every page's headings: the section index's outline lists them, and the sitemap carries them as each page's
sections, which search indexes as "Sections". Some things are missing. The keys are slugs the engine makes itself, which can differ from the idsrehype-slugwrites on the page: on this site 29 of 607 keys name no heading, because a repeated heading gets a-1suffix on the page and punctuation slugs differently. The level is implied by nesting, with H4s not recorded, and demo titles, which render as H3s, aren't listed. The engine should record each heading's rendered id and level. - Helper (planned).
toTableOfContents(page)in@fairgarden/design/utils/docswill flatten those records intoTableOfContentsitems (id,title,level), so the navigation components stay free of the engine, which remains an optional peer. - Route (planned). A layout can't see its route on the server, so a parallel route slot (
app/(lib)/@toc/[...slug]/page.tsxwith adefault.tsx) will look the page up in the sitemap and render the contents with scrollspy, server-side, so the column is in the first paint. The static map in the site'sDocsTocthen goes. - Checks (planned). Every contents link resolves to a heading on its page; no layout shift at 1440, 1024 and 390 px; the bar naming the first section in the server HTML.
API Reference
DocsLayout
The documentation page frame [D202, D203]. A skip link first (the
header’s Navigation Bar then renders none), the header, then up to three
columns inside --fgd-container-wide: the sidebar (SidebarNav, a
sticky 240 px column with its own scroll, from --fgd-nav-inline-n-above;
below it the header’s menu Button opens the same navigation in the
drawer), the main page with its end gutter for the code blocks’
hanging ⋮, and the table of contents (a sticky 240 px column from
--xl-n-above; below it the contents’ compact bar, pinned under the
header while the page scrolls, naming the section in view and opening
the list in a panel). Every placement is viewport media and the bar has
one fixed height, so the first paint is the final frame. Print keeps the
page alone.
| Prop | Type | Description |
|---|---|---|
footer | | A full-width part under the columns, such as the site |
header | | The site header: a |
mainId | | The |
preset | | The page ground: |
primary | | Override the page ground’s primary. Never defaulted [D133]. |
secondary | | Override the page ground’s secondary. Never defaulted. |
sidebar | | The page tree: a |
skipLabel | | The skip link’s words. Default “Skip to main content”. |
toc | | The page’s contents: a |
children | | The page. |
DocsLayoutDrawer
The docs layout’s drawer [D202]: a NavDrawer whose sheet shows the
layout’s sidebar (the same SidebarNav, from the same data). Put it in
the header’s drawer slot: the Navigation Bar shows its menu Button
below --fgd-nav-inline-n-above, exactly where the sidebar column is
absent. Focus moves to the current page’s link, is trapped, Escape
closes, and focus returns to the menu Button; the page behind is inert
and does not scroll. If the window widens past the threshold while it is
open, it closes and focus moves to the sidebar column’s current link.
| Prop | Type | Description |
|---|---|---|
label | | The menu Button’s label, authored in title case [D160]. Default “Menu”. |
defaultOpen | | Initial open state. Default |
open | | Controlled open state. |
onOpenChange | | Called when the drawer opens or closes. |
closeLabel | | The close control’s label. Default “Close”. |
currentPath | | The current page’s URL path. Default: the Navigation Bar’s. |
footer | | The fixed footer zone: a |
inlineTarget | | Where focus goes when the drawer closes because the viewport reached the inline threshold. Default: the Navigation Bar item matching the last open group, else the bar’s first item. The docs layout passes the in-flow sidebar’s current link. |
logo | | The logo repeated in the drawer’s bar. Default: the Navigation Bar’s. |
logoHref | | The logo link. Default: the Navigation Bar’s, else “/". |
logoLabel | | The logo link’s accessible name. Default: the Navigation Bar’s. |
morph | | The outline morph (§9.17) [D206]: the menu Button’s ring (or its ink
box) grows into the sheet as it opens and shrinks back onto it as it
closes. Default |
primary | | Override the header scope’s primary. Never defaulted [D133]. |
renderLink | | Builds the logo link, e.g. |
secondary | | Override the header scope’s secondary. Never defaulted. |
triggerClassName | | Class names for the menu Button, added after its own. |
className | | Class names for the sheet, added after its own. |
Additional types
docsLayout
type docsLayout = docsLayoutDocsLayoutContext
Provided by DocsLayout; read by DocsLayoutDrawer.
type DocsLayoutContext = React.Context<DocsLayoutContextValue | null>DocsLayoutDrawerProps
Props for DocsLayoutDrawer: NavDrawer’s, less the list it builds itself.
type DocsLayoutDrawerProps = {
/** The fixed footer zone: a `NavDrawerFooter`. */
footer?: React.ReactNode;
/** The menu Button's label, authored in title case [D160]. Default "Menu". */
label?: string;
/** Class names for the sheet, added after its own. */
className?: string;
/** Override the header scope's primary. Never defaulted [D133]. */
primary?:
| 'ruby'
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| null;
/** Override the header scope's secondary. Never defaulted. */
secondary?:
| 'ruby'
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| 'amber'
| 'blue'
| 'cyan'
| 'grass'
| 'green'
| 'jade'
| 'lime'
| 'mint'
| 'orange'
| 'sky'
| 'teal'
| 'yellow'
| null;
/**
* Where focus goes when the drawer closes because the viewport reached
* the inline threshold. Default: the Navigation Bar item matching the
* last open group, else the bar's first item. The docs layout passes the
* in-flow sidebar's current link.
*/
inlineTarget?: () => HTMLElement | null;
/** The close control's label. Default "Close". */
closeLabel?: string;
/** The logo repeated in the drawer's bar. Default: the Navigation Bar's. */
logo?: React.ReactNode;
/** The logo link. Default: the Navigation Bar's, else "/". */
logoHref?: string;
/** The logo link's accessible name. Default: the Navigation Bar's. */
logoLabel?: string;
/**
* Builds the logo link, e.g. `(href) => <NextLink href={href} />`.
* Default: the Navigation Bar's, else a plain `<a href>`.
*/
renderLink?: (href: string) => ReactElement;
/** The current page's URL path. Default: the Navigation Bar's. */
currentPath?: string;
/** Controlled open state. */
open?: boolean;
/** Initial open state. Default `false`. */
defaultOpen?: boolean;
/** Called when the drawer opens or closes. */
onOpenChange?: (open: boolean) => void;
/**
* The outline morph (§9.17) [D206]: the menu Button's ring (or its ink
* box) grows into the sheet as it opens and shrinks back onto it as it
* closes. Default `true`; `false` opens and closes at once.
*/
morph?: boolean;
/** Class names for the menu Button, added after its own. */
triggerClassName?: string;
}DocsLayoutProps
Props for DocsLayout: div props, the frame’s slots, the page ground and the color axes.
type DocsLayoutProps = {
/**
* The site header: a `NavigationBar` with `wide` (so its content box
* meets the columns), whose `drawer` is a `DocsLayoutDrawer`.
*/
header?: React.ReactNode;
/**
* The page tree: a `SidebarNav`. It fills the sticky start column from
* --fgd-nav-inline-n-above and, below it, the drawer that
* `DocsLayoutDrawer` opens from the header.
*/
sidebar?: React.ReactNode;
/**
* The page's contents: a `TableOfContents`. It fills the sticky end
* column from --xl-n-above; below it, the same element draws as its
* compact bar (`kind="bar"`, set through `TableOfContentsContext`),
* pinned at the top of the page under the header. Omitted, or with no
* items, neither appears.
*/
toc?: React.ReactNode;
/** The page. */
children?: React.ReactNode;
/** A full-width part under the columns, such as the site `Footer`. */
footer?: React.ReactNode;
/** The page ground: `paper` (default), `white` or the page's one pastel. */
preset?: 'paper' | 'white' | 'tide' | 'meadow' | 'pollen' | 'apricot' | 'rose' | 'heather';
/** The `main` element's id, the skip link's target. Default "main". */
mainId?: string;
/** The skip link's words. Default "Skip to main content". */
skipLabel?: string;
/** Override the page ground's primary. Never defaulted [D133]. */
primary?:
| 'ruby'
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| null;
/** Override the page ground's secondary. Never defaulted. */
secondary?:
| 'ruby'
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| 'amber'
| 'blue'
| 'cyan'
| 'grass'
| 'green'
| 'jade'
| 'lime'
| 'mint'
| 'orange'
| 'sky'
| 'teal'
| 'yellow'
| null;
}Specification: DESIGN-SYSTEM.md §11.15 (docs layout) [D202, D203], with the Navigation Bar of §11.5, the drawer of §11.6, the Sidebar Navigation of §9.15 and the Table of Contents of §9.16.