On This Page
A table of contents whose dot rides a thin rail with the scroll, bending in to fold open each section's subsections as you reach them.
3 variantsNew
Preview
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest https://floret.shippedui.com/r/on-this-page.jsonUsage
Pass your own data and wire the callbacks to your app.
import { OnThisPage } from "@/components/ui/on-this-page";
// Each id must match an element on the page, like <h2 id="install">.
const sections = [
{ id: "intro", title: "Introduction" },
{
id: "install",
title: "Installation",
children: [
{ id: "install-cli", title: "With the CLI" },
{ id: "install-manual", title: "By hand" },
],
},
{ id: "usage", title: "Usage" },
];
export function DocsSidebar() {
return (
<aside className="sticky top-24 w-56">
<OnThisPage sections={sections} />
</aside>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| sections* | Section[] | — | The page's sections in order, each with an optional list of subsections. |
| container | RefObject<HTMLElement | null> | — | The element that scrolls, when it isn't the window. Section ids are looked up inside it. |
| label | string | "On this page" | Heading above the list; also the nav's accessible name. |
| offset | number | 96 | Distance in px from the top of the scroller where a section counts as current. Match your sticky header. |
| maxSubsections | number | 5 | Most subsections shown at once; the rest slide in as you go, with More above / More below rows. 0 shows all. |
| inset | number | 18 | How far in, in px, the subsection line sits from the main line. |
| curve | number | 0.5 | Softness of the bend between the two lines. 0.5 is a classic S; lower is tighter. |
| rowHeight | number | 30 | Height of one row, px. |
| sectionGap | number | 4 | Extra space above each new section, px. |
| subsectionGap | number | 0 | Space between subsections, px. Negative values pull them closer. |
| bendRoom | number | 8 | Extra space above a group's first subsection, giving the bend more room, px. |
| lineWidth | number | 2 | Width of the rail, px. |
| dotSize | number | 8 | Diameter of the dot, px. |
| className | string | — | Classes for the nav. |
type SubSection = { id: string; title: string };
// A section, optionally with one level of subsections.
type Section = SubSection & { children?: readonly SubSection[] };