This repository was archived by the owner on May 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { DocTracingBeam } from './DocTracingBeam'
7
7
import { Button } from '../ui/button'
8
8
import { GitHubIcon } from '../icons/GitHubIcon'
9
9
import { useMotionValue } from 'framer-motion'
10
+ import { cn } from '@/lib/utils'
10
11
11
12
interface Toc {
12
13
url : string
@@ -22,9 +23,11 @@ const DocToC = ({ doc }: { doc: Doc }) => {
22
23
const y1 = useMotionValue ( 0 )
23
24
const y2 = useMotionValue ( 0 )
24
25
26
+ const [ activeIndex , setActiveIndex ] = useState ( - 1 )
27
+
25
28
useEffect ( ( ) => {
26
29
const headings = document
27
- . querySelectorAll < HTMLHeadingElement > ( '.md-content-header' )
30
+ . querySelectorAll < HTMLHeadingElement > ( 'h2 .md-content-header' )
28
31
. values ( )
29
32
. toArray ( )
30
33
@@ -42,6 +45,8 @@ const DocToC = ({ doc }: { doc: Doc }) => {
42
45
)
43
46
44
47
y2 . set ( initial + ( index * sectionSize + offset ) )
48
+
49
+ setActiveIndex ( index )
45
50
}
46
51
} )
47
52
} , options )
@@ -68,7 +73,12 @@ const DocToC = ({ doc }: { doc: Doc }) => {
68
73
< li key = { item . url + i } >
69
74
< Link
70
75
href = { item . url }
71
- className = "text-2xs text-muted-foreground transition-colors hover:text-zinc-900 dark:hover:text-zinc-200"
76
+ className = { cn (
77
+ 'text-2xs' ,
78
+ activeIndex === i
79
+ ? 'text-zinc-900 dark:text-zinc-200'
80
+ : 'text-muted-foreground transition-colors hover:text-zinc-900 dark:hover:text-zinc-200' ,
81
+ ) }
72
82
>
73
83
{ item . value }
74
84
</ Link >
You can’t perform that action at this time.
0 commit comments