# Page outline

> A spring-guided hairline table of contents and collapsible reading progress pill whose active indicator glides smoothly along a continuous stepped SVG path.

Most documentation sites split navigation into three disconnected pieces: a static sidebar list whose highlight snaps abruptly between links, a separate progress bar, and a mobile dropdown. PageOutline unifies all three around one stepped SVG hairline path measured from the real heading rows. Nested sub-headings indent along crisp 45-degree elbows, and coupled createSpring springs drive stroke-dasharray and stroke-dashoffset directly on the SVG path so the active indicator glides smoothly around every corner without per-frame React re-renders. Switch to variant="pill" for a compact floating reading pill with a circular progress ring that unfolds into the full stepped outline on click. Tracks either window scroll or any scrollable containerRef, locks cleanly to the final heading at the bottom and respects prefers-reduced-motion.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/page-outline.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`, `number-roll`
- Docs and live preview: https://hairlineui.com/ui/page-outline
- Registry item (source): https://hairlineui.com/r/page-outline.json

## Usage

```tsx
import { PageOutline } from "@/components/page-outline";

<PageOutline
  items={[
    { id: "overview", title: "Overview", level: 2 },
    { id: "architecture", title: "Architecture", level: 2 },
    { id: "springs", title: "Spring runner", level: 3 },
    { id: "deployment", title: "Deployment", level: 2 },
  ]}
/>
```

## Responsive docs layout: desktop sticky rail paired with mobile reading pill

Share the same headings array across both variants so wide screens get a persistent stepped rail and smaller screens get a compact floating pill.

```tsx
"use client";
import { PageOutline, type OutlineItem } from "@/components/page-outline";

export function DocsChrome({ headings, children }: { headings: OutlineItem[]; children: React.ReactNode }) {
  return (
    <div className="mx-auto grid max-w-5xl grid-cols-1 gap-10 lg:grid-cols-[1fr_220px]">
      <article className="min-w-0">{children}</article>

      <aside className="hidden lg:block">
        <div className="sticky top-24">
          <PageOutline items={headings} variant="rail" />
        </div>
      </aside>

      <div className="fixed bottom-4 left-4 z-40 lg:hidden">
        <PageOutline items={headings} variant="pill" popoverSide="up" />
      </div>
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `OutlineItem[]` | – | Ordered array of { id, title, level } headings matching DOM ids. |
| `variant / popoverSide` | `"rail" \| "pill" / "down" \| "up"` | `"rail" / "down"` | Render as a sticky sidebar rail or a compact expanding reading pill. |
| `containerRef / topOffset` | `RefObject<HTMLElement \| null> / number` | `window / 84` | Optional inner scroll container to track plus reading-line offset from the top in px. |
| `activeId / progress / onActiveChange` | `string / number / (id) => void` | – | Optional controlled active heading and 0..1 progress, plus active heading change callback. |
| `title / showProgress / showTrail / sound` | `string / boolean / boolean / boolean` | `"On this page" / true / true / false` | Outline header label, circular progress readout, read-trail highlight and opt-in jump tick. |

## States

- **rail scrolling**: As headings cross the reading line, the active SVG indicator springs smoothly along the vertical rail and around 45-degree nested elbows while the read trail follows behind.
- **section jump**: Clicking any link locks the target immediately, glides the indicator directly to its arc-length segment and scrolls smoothly into view.
- **pill collapsed**: Compact hairline pill displays a circular progress ring, the active section title and tabular percentage.
- **pill expanded**: Clicking the pill unfolds the full stepped-path outline card above or below the trigger; selecting a section or pressing Escape folds it cleanly back.
- **reduced motion**: Indicator jumps cleanly along the path without spring travel and section jumps scroll immediately.

## What it handles

Good reading outlines show hierarchy, exact active position and overall reading progress without fighting scroll momentum or breaking on nested headings.

- **Spring gliding along a stepped SVG path**: Measures real heading positions via ResizeObserver, builds one continuous SVG hairline with 45-degree indentation elbows, and springs stroke-dasharray smoothly around corners.
- **Rail and collapsible reading pill in one component**: Use variant="rail" for desktop sidebars or variant="pill" for a compact circular-ring pill that unfolds cleanly into the full stepped outline.
- **Window or container scroll-spy**: Spies on full window scroll by default or any custom containerRef, automatically locking to the final section at scroll bottom so short endings stay reachable.
- **Smooth-scroll click lock**: Clicking a heading updates the indicator immediately and holds scroll-spy briefly while smooth scrolling settles so intermediate headings never flicker.
- **Subtle read trail and circular progress**: Illuminates the already-read portion of the stepped rail and pairs it with a crisp circular SVG ring and tabular reading percentage.
- **Zero per-frame React churn**: SVG stroke attributes write straight to DOM refs inside the shared spring loop and sleep completely at 0% CPU when settled.

## Replaces

static TOC sidebar, scroll progress bar, floating section pill, framer-motion layoutId indicator

## Where it fits

- **Documentation and API references**: Drop variant="rail" into a sticky right column to track H2 and nested H3 headings with a spring-guided stepped path.
- **Long-form essays and changelogs**: Float variant="pill" at the bottom of the screen so readers see current section and percentage without a permanent sidebar.
- **Split-pane editors and legal agreements**: Pass containerRef to spy on an inner scrollable pane rather than the window.
- **Mobile documentation navigation**: Render the rail on desktop breakpoints and swap to the collapsible reading pill on narrow viewports.

## Notes

- Row geometry updates automatically via ResizeObserver so font loads, responsive wraps or dynamic headings keep the stepped SVG rail aligned to the pixel.
- When scrolled within 8px of the bottom, scroll-spy locks cleanly to the final heading so short concluding sections are always selectable.
- Both the active indicator and read trail animate via stroke-dasharray and stroke-dashoffset directly on SVG paths with zero layout reflow.
- Under prefers-reduced-motion: reduce, the indicator snaps cleanly in place and jumps use instant scroll.

License: MIT (https://hairlineui.com/license#components)
