BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/nexvyn/table-of-contents

Table of Contents

nexvyn/table-of-contents
FreeComponent

A fixed bottom-left floating block that tracks scroll position, shows the active section, and expands into a navigable section list.

Live preview

live · rendered by the registry
Rendered by nexvyn on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://ui.nexvyn.dev/r/table-of-contents.json

Source

components/ui/table-of-contents.tsxui.nexvyn.dev/r/table-of-contents.json · first 6 KB
1'use client'
2
3import { useState, useEffect, useRef, useCallback, type RefObject } from 'react'
4import { motion, AnimatePresence, useReducedMotion } from 'motion/react'
5import { cn } from '@/lib/utils'
6import { playHoverSound, playClickSound } from '@/lib/sound'
7import { CircularProgress } from './circular-progress'
8
9export interface TOCSection {
10 id: string
11 title: string
12 level?: number
13}
14
15interface TableOfContentsProps {
16 sections: TOCSection[]
17 scrollOffset?: number
18 showAfterScroll?: number
19 scrollContainer?: RefObject<HTMLElement | null>
20 className?: string
21}
22
23export function TableOfContents({
24 sections,
25 scrollOffset = 120,
26 showAfterScroll = 300,
27 scrollContainer,
28 className,
29}: TableOfContentsProps) {
30 const [isExpanded, setIsExpanded] = useState(false)
31 const [isVisible, setIsVisible] = useState(false)
32 const [activeId, setActiveId] = useState<string>('')
33 const [scrollProgress, setScrollProgress] = useState(0)
34 const containerRef = useRef<HTMLDivElement>(null)
35 const rafRef = useRef<number>(0)
36 const prefersReduced = useReducedMotion()
37
38 useEffect(() => {
39 let ticking = false
40 const el = scrollContainer?.current
41
42 const getScrollTop = () => (el ? el.scrollTop : window.scrollY)
43 const getScrollHeight = () =>
44 el
45 ? el.scrollHeight - el.clientHeight
46 : document.documentElement.scrollHeight - window.innerHeight
47
48 const handleScroll = () => {
49 if (!ticking) {
50 rafRef.current = requestAnimationFrame(() => {
51 const scrollTop = getScrollTop()
52 const height = getScrollHeight()
53 const scrolled = height > 0 ? (scrollTop / height) * 100 : 0
54
55 setScrollProgress(scrolled)
56 setIsVisible(scrollTop > showAfterScroll)
57 ticking = false
58 })
59 ticking = true
60 }
61 }
62
63 const target = el || window
64 target.addEventListener('scroll', handleScroll, { passive: true })
65 handleScroll()
66
67 return () => {
68 target.removeEventListener('scroll', handleScroll)
69 cancelAnimationFrame(rafRef.current)
70 }
71 }, [showAfterScroll, scrollContainer])
72
73 useEffect(() => {
74 const root = scrollContainer?.current ?? null
75 const observer = new IntersectionObserver(
76 (entries) => {
77 const visible = entries
78 .filter((e) => e.isIntersecting)
79 .sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top)
80
81 if (visible.length > 0) {
82 setActiveId(visible[0].target.id)
83 }
84// … truncated

What it pulls in

npm packages

  • motion

Files it writes

  • components/ui/table-of-contents.tsx
  • components/ui/circular-progress.tsx
  • lib/sound.ts

Facts

Registry
nexvyn
Type
registry:ui
Access
Free
Files written
3
Licence
MIT
First indexed
2026-08-03
Last confirmed
today

Go to the source

Docs on nexvyn ui.nexvyn.dev Nexvyn/Nexvyn-ui on GitHub Raw registry item This item as JSON

More from nexvyn

All 33 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
BadgebadgenexvynComponentsFree2 deps · 2 files
Bars Themebars-themenexvynComponentsFree1 dep · 3 files
Bounce Sidebarbounce-sidebarnexvynComponentsFree1 dep · 2 files
BreadcrumbsbreadcrumbsnexvynComponentsFree1 dep · 2 files
CheckboxcheckboxnexvynComponentsFree1 dep · 3 files
Clipboard Fieldclipboard-fieldnexvynComponentsFreeno deps · 2 files
Color Pickercolor-pickernexvynComponentsFreeno deps · 16 files
ComboboxcomboboxnexvynComponentsFree1 dep · 2 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex