Progress
Track reading position along a bending table of contents rail with smooth section jumps and a time-left countdown.
import { TocProgress } from '@uthereal/ui/toc-progress'Toc progress playground
Overview
TocProgress renders an article outline beside a continuous SVG rail that bends smoothly across up to three heading levels. As the reader scrolls, the rail fills with the theme accent, a marker dot rides its tip, each heading shifts through read, current, and upcoming contrast states, and the countdown beside the title rolls down to Finished.
Use TocProgress alongside long documentation pages, guides, policies, or scrollable reader panels with four or more headings. Use tabs when sections represent alternate views rather than parts of one document, sequential multi-step workflows, and progress for standalone completion meters without section navigation.
Usage
'use client'
import { TocProgress, type TocProgressItem } from '@uthereal/ui/toc-progress'
const headings: TocProgressItem[] = [
{ id: 'overview', label: 'Overview', level: 1 },
{ id: 'install', label: 'Installation', level: 1 },
{ id: 'install-cli', label: 'With the CLI', level: 2 },
{ id: 'install-manual', label: 'Manual setup', level: 2 },
{ id: 'configure', label: 'Configuration', level: 1 },
]
export function ArticleOutline() {
return (
<TocProgress
items={headings}
offset={88}
onNavigate={(id) => history.replaceState(null, '', `#${id}`)}
/>
)
}Pass the article's real heading id values in document order and set offset to match your sticky header height plus breathing room (matching scroll-margin-top on the headings). Use onNavigate to sync the URL hash or analytics, and use action with onAction when a host dispatches named actions.
Examples
Finished state
defaultProgress renders the rail, marker, active heading highlight, and reading-time countdown declaratively without a live scroll container. At defaultProgress: 1, the countdown swaps to finishedLabel with a check icon.
Landmark-only rail
Pass an empty title and showTimeLeft: false when the surrounding sidebar already supplies a heading. The <nav> landmark falls back to label as its accessible name.
Live scroll and declarative mode
| Mode | Trigger | Scroll listeners | Reading time |
|---|---|---|---|
| Live scroll | defaultProgress and progress omitted | Follows scrollContainer, nearest scrolling ancestor of the first heading, or window | Uses readingTime, or counts words in the scroll container at 230 words per minute |
| Declarative preview | defaultProgress set (0 to 1) | Disabled; renders static rail geometry without DOM scroll reads | Uses readingTime when supplied; hidden if omitted |
| Controlled progress | progress prop set (0 to 1) | Disabled; animates rail and countdown whenever progress changes | Uses readingTime when supplied; hidden if omitted |
In live mode, ResizeObserver re-measures both wrapped heading rows and scroll-container layout changes so S-curve bends stay aligned between rows. Near the end of an article, a quadratic ramp eases the reading line from offset to the viewport bottom so short trailing sections still activate. Choosing a heading near the end pins it as current until pointer, touch, wheel, or keyboard input resumes scrolling.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
items | TocProgressItem[]Default: [{"id":"overview","label":"Overview","level":1},{"id":"details","label":"Details","level":1}] | The page's headings in document order: each needs the id of the heading element it scrolls to, a sentence-case label, and its nesting level 1 to 3. |
title | stringDefault: "On this page" | Heading above the list; defaults to "On this page", and an empty string hides it. |
label | stringDefault: "On this page" | Accessible name of the nav landmark when title is empty. |
offset | integerDefault: 96 | Distance in px from the top of the scroll viewport where a heading counts as reached; match the page scroll-margin-top. |
defaultActiveId | string— | Initially current heading id when reading position is not yet known. Edits do not reset a mounted instance. |
defaultProgress | number— | Declarative read progress from 0 to 1 that renders a static line without reading scroll position; use for previews and AI hosts. |
readingTime | number— | Total article reading time in minutes; estimated at 230 words per minute from the scroll container when omitted. |
showTimeLeft | booleanDefault: true | Show the minutes left beside the title, counting down to Finished. |
finishedLabel | stringDefault: "Finished" | Time-left text once the article is fully read. |
minutesLeftLabel | stringDefault: "{minutes} min left" | Time-left template where {minutes} is the count, such as "{minutes} min left". |
action | string— | Host-registered action name sent through onAction with the chosen heading id. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | TocProgressTheme— | Color mode, accent, and tokens, including laneStep, bend, trackWidth, fillWidth, and dotSize. |
motion | none | subtle | expressiveDefault: "subtle" | Line glide, heading colors, and countdown animations. System reduced-motion preferences take precedence. |
motionOptions | TocProgressMotionOptions— | Overrides for the follow spring and time-left swap transition; durations are milliseconds. |
dir | ltr | rtl— | Reading direction; inherited when omitted. |
TocProgressItem is { id, label, level? }: a unique heading element ID matching the document, sentence-case heading text, and an optional nesting depth of 1, 2, or 3 (defaults to 1). The module also exports estimateReadingTime(words) and reconcileActiveId(stored, config).
React integration
| Prop | Purpose |
|---|---|
scrollContainer | RefObject<HTMLElement | null> or HTMLElement that scrolls the article. Omit to auto-detect the nearest scrolling ancestor or window. |
activeId, onActiveChange | Control or observe the current heading ID as the marker crosses each section. |
progress | Control normalized reading progress (0 to 1) externally through the same SVG rail and countdown. |
onNavigate(id) | Called with the chosen heading ID before scrolling the article. |
onAction(action, id) | Called with the configured action name and chosen heading ID on link activation. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme. |
ref, className, style | Applied to the root <nav> landmark, which carries the resolved theme tokens. |
| Native attributes | id, aria-*, data-*, and remaining <nav> props forwarded to the root. |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Moves focus through heading links in document order. |
ArrowDown, ArrowUp | Moves focus to the next or previous heading link. |
Home, End | Moves focus to the first or last heading link. |
Enter | Scrolls the article to the target heading and moves focus to it without a second scroll jump. |
TocProgress renders a <nav> landmark named by title via aria-labelledby, or by label via aria-label when title is empty. Headings render as an ordered list of anchor links (href="#<id>") so navigation works before hydration. The active heading carries aria-current="location", and read, current, and upcoming headings differ in text contrast rather than relying on the rail alone. When a heading is chosen in live mode, the target element receives tabindex="-1" if needed and focuses with preventScroll: true.
The SVG track, accent fill, knockout mask, and marker dot are hidden from assistive technology (aria-hidden="true"). The visual rolling countdown is paired with visually hidden plain text built from minutesLeftLabel or finishedLabel so screen readers announce a single string instead of split digit spans. In right-to-left layouts, the rail mirrors to the inline start (scaleX(-1)) and indentation uses logical CSS properties. Under forced-colors: active, the track uses CanvasText, the fill and marker use Highlight, and heading links follow LinkText and CanvasText.
Motion and theming
The rail fill and marker dot follow reading position on the critically damped smooth spring so progress never overshoots the active section (motionOptions.follow overrides it). Countdown digits roll via RollingNumber, and switching between the countdown and finishedLabel uses a subtle rise and blur on the snappy spring (motionOptions.swap overrides it). Heading link colors transition over 240ms (160ms for focus background) on the standard curve.
motion="none"makes rail updates, heading colors, scroll jumps, and countdown swaps immediate (0ms).prefers-reduced-motion: reducejumps the rail and scroll position immediately, disables link transitions, and replaces digit rolls and status swaps with a 120ms opacity crossfade.
theme accepts mode, accent, global tokens (foreground, textSecondary, mutedForeground, border, borderStrong, accent, success, focusRing, radius, fontFamily, fontSize), and component rail tokens (laneStep, bend, trackWidth, fillWidth, dotSize). An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, TocProgress is a leaf. The host stores the current heading ID at /components/instance-<id>/activeId, seeded from defaultActiveId, and reconciles it when headings are removed. If action is set, it must name a host-registered action; activations report { componentId, itemId }. See Building with agents.
{
"type": "TocProgress",
"props": {
"title": "On this page",
"readingTime": 6,
"defaultProgress": 0.45,
"items": [
{ "id": "overview", "label": "Overview", "level": 1 },
{ "id": "setup", "label": "Setup", "level": 1 },
{ "id": "setup-tokens", "label": "Theme tokens", "level": 2 },
{ "id": "api", "label": "API reference", "level": 1 }
]
},
"children": []
}