Library navigation

A Notion-style list of heading links with nested indentation, subtle hover backgrounds, and active-section tracking. Use level 1, 2, or 3 to reflect your heading hierarchy. Motion and smooth scrolling respect reduced motion.

Installation

Add the toc component from Hangry UI to this project.
Use the project's package manager to run:
shadcn@latest add https://ui.razeev.com/r/toc.json
Integrate the component with the existing layout and styling.
Keep its interactions and reduced-motion support intact.

How to use

import { Toc } from "@/components/hangry-ui/components/toc";
<Toc
items={[
{ id: "overview", label: "Overview" },
{ id: "installation", label: "Installation" },
{ id: "usage", label: "Usage" },
]}
/>;

Match each item ID to an element on the page. The TOC highlights every listed target visible in the viewport. level controls indentation and marker width: level 1 is the longest, level 2 is shorter, and level 3 is shortest. The docs page also adds its title and preview to the TOC automatically.

Props

PropTypeDefaultDescription
itemsTocItem[]Required

Ordered links to page elements. Each item has an id, label, and optional level.

titlestring"Table of contents"Accessible label for the navigation.
classNamestring""Additional classes applied to the navigation rail.

TocItem

FieldTypeRequiredDescription
idstringYesID of the target element on the page.
labelstringYesText shown in the expanded table.
level1 | 2 | 3NoDeeper levels use shorter, indented markers.

Dependencies

  • Motion