Updated
On This Page
Customize
Offset96px
Inset18px
Curve softness0.50
Bend room8px
Section gap8px
Subsection gap0px
Max subsections5
Row height32px
Line width2.0px
Dot size8px
Installation
npx shadcn@latest add https://uibrik.com/r/on-this-page.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/on-this-page/on-this-page.tsx"use client"; import { Fragment, useCallback, useEffect, useId, useMemo, useRef, useState, type RefObject } from "react"; import { animate, motion, motionValue, useMotionValue, useMotionValueEvent, useReducedMotion, useSpring, useTransform, } from "motion/react"; import { IconChevronDown, IconChevronUp } from "@tabler/icons-react"; import { cn } from "@/lib/utils"; export type SubSection = { id: string; title: string }; /** A section, optionally with one level of subsections. */ export type Section = SubSection & { children?: readonly SubSection[] }; /** A section or subsection in document order. */ export type Item = { id: string;
Adds the files to
components/uibrik/on-this-page and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/on-this-page.Usage
import { OnThisPage } from "@/components/uibrik/on-this-page/on-this-page";const sections = [ { id: "overview", title: "Overview" }, { id: "install", title: "Installation", children: [ { id: "requirements", title: "Requirements" }, { id: "manual-setup", title: "Manual setup" }, ], },];<OnThisPage sections={sections} label="On this page" offset={96} inset={18} curve={0.5} bendRoom={8} sectionGap={8} subsectionGap={0} maxSubsections={5} rowHeight={32} lineWidth={2} dotSize={8} container={null}/>Where to use On This Page
Docs table of contents
A dot riding a rail with your scroll shows where you are on a long page.
Pairs with Section Pill
Long guides and blog posts
Subsections folding open as you reach them keep the outline short.
Pairs with Tick Nav
Legal and policy pages
Clicking a section to jump makes long terms and privacy pages navigable.
Props
OnThisPage- label
- Type string
- "On this page"
- Heading above the list.
- offset
- Type number
- 96
- Distance from the top of the scroller where a section counts as current.
- inset
- Type number
- 18
- How far in the subsection line sits from the main line.
- curve
- Type number
- 0.5
- Softness of the bend between the two lines. 0.5 is the classic S; lower is tighter.
- bendRoom
- Type number
- 8
- Extra space above a group's first subsection, giving the bend more room.
- sectionGap
- Type number
- 8
- Extra space above each new section.
- subsectionGap
- Type number
- 0
- Space between subsections. Negative values tighten them past the row height.
- maxSubsections
- Type number
- 5
- Most subsections shown at once for one section; the rest sit behind a More above or More below row and slide in as you go. 0 shows all.
- rowHeight
- Type number
- 32
- Height of one row.
- lineWidth
- Type number
- 2
- Thickness of the rail.
- dotSize
- Type number
- 8
- Diameter of the dot.
- sectionsrequired
- Type { id: string; title: string; children?: { id: string; title: string }[] }[]
- –
- Sections to list, each with optional subsections one level deep. Each id is the id of an element on the page.
- container
- Type RefObject<HTMLElement | null>
- –
- Scrolling element to follow. Defaults to the window.
- className
- Type string
- –
- Classes for the wrapper.