TableOfContents

An auto-highlighting table of contents sidebar. Tracks which heading is currently in view via IntersectionObserver.

Import

import { TableOfContents } from '@adjanour/react-components'
import '@adjanour/react-components/table-of-contents.css'

Usage

const headings = [
  { id: 'intro', label: 'Introduction', level: 2 },
  { id: 'usage', label: 'Usage', level: 2 },
  { id: 'api', label: 'API Reference', level: 3 },
  { id: 'examples', label: 'Examples', level: 2 },
]

<TableOfContents headings={headings} />

Props

PropTypeDefaultDescription
headingsTocHeading[]RequiredArray of { id, label, level }
renderLink(heading, children) => ReactNode<a>Custom link renderer

TocHeading

interface TocHeading {
  id: string
  label: string
  level: number
}

Behavior

Theming

VariableDefaultDescription
--aw-toc-text#475569Inactive item text
--aw-toc-active-text#0f172aActive item text
--aw-toc-active-border#3b82f6Active item left border
--aw-toc-label#94a3b8”On this page” label
--aw-toc-hover#3b82f6Hover text color