File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
src/components/TableOfContents Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,9 @@ const ItemsList: React.FC<IPropsItemsList> = ({
25
25
< >
26
26
{ items . map ( ( item , index ) => (
27
27
< ListItem key = { index } m = { 0 } { ...rest } >
28
- { item . title && < Link item = { item } activeHash = { activeHash } /> }
28
+ { item . title && (
29
+ < Link depth = { depth } item = { item } activeHash = { activeHash } />
30
+ ) }
29
31
{ item . items && (
30
32
< List
31
33
key = { item . title }
Original file line number Diff line number Diff line change @@ -5,13 +5,29 @@ import CustomLink from "../Link"
5
5
import { getCustomId , Item , trimmedTitle } from "./utils"
6
6
7
7
export interface IPropsTableOfContentsLink {
8
+ depth : number
8
9
item : Item
9
10
activeHash ?: string
10
11
}
11
12
12
- const Link : React . FC < IPropsTableOfContentsLink > = ( { item } ) => {
13
+ const Link : React . FC < IPropsTableOfContentsLink > = ( {
14
+ depth,
15
+ item,
16
+ activeHash,
17
+ } ) => {
13
18
const url = `#${ getCustomId ( item . title ) } `
14
19
20
+ const isActive = activeHash === url
21
+ const isNested = depth === 2
22
+
23
+ let classes = ""
24
+ if ( isActive ) {
25
+ classes += " active"
26
+ }
27
+ if ( isNested ) {
28
+ classes += " nested"
29
+ }
30
+
15
31
const $dotBg = cssVar ( "dot-bg" )
16
32
17
33
const hoverOrActiveStyle : SystemStyleObject = {
@@ -34,6 +50,7 @@ const Link: React.FC<IPropsTableOfContentsLink> = ({ item }) => {
34
50
< CustomLink
35
51
as = { GatsbyLink }
36
52
to = { url }
53
+ className = { classes }
37
54
textDecoration = "none"
38
55
display = "inline-block"
39
56
position = "relative"
You can’t perform that action at this time.
0 commit comments