Componentnavigation0.96 KB gzipZero dependencies

Toc

Table of contents with IntersectionObserver scroll-spy and dashed active underline

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add toc

Or install the full npm package:

npm install bigbullui

Usage

tsx3 lines
import { Toc } from "@/components/ui/toc" <Toc headings={headings} />

Source code

toc.tsx + 1 helper

Zero 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

PropTypeDescription
headingsTocHeading[]Configures headings. (Default: [])
onSelectHeading(id: string) => voidCallback invoked on select heading.