Componentnavigation0.96 KB gzipZero dependencies
Toc
Table of contents with IntersectionObserver scroll-spy and dashed active underline
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add tocOr install the full npm package:
npm install bigbulluiUsage
tsx3 lines
import { Toc } from "@/components/ui/toc" <Toc headings={headings} />Source code
toc.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxtoc.tsx92 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export interface TocHeading { id: string; text: string; level: 2 | 3;} export interface TocProps extends React.HTMLAttributes<HTMLElement> { headings?: TocHeading[]; onSelectHeading?: (id: string) => void;} export const Toc = React.forwardRef<HTMLElement, TocProps>(function Toc( { headings = [], onSelectHeading, className, "aria-label": ariaLabel = "Table of contents", ...props },Props
| Prop | Type | Description |
|---|---|---|
| headings | TocHeading[] | Configures headings. (Default: []) |
| onSelectHeading | (id: string) => void | Callback invoked on select heading. |