Skip to content

Commit 8d97deb

Browse files
committed
revert active styles logic
1 parent 2040c0a commit 8d97deb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/components/TableOfContents/ItemsList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const ItemsList: React.FC<IPropsItemsList> = ({
2525
<>
2626
{items.map((item, index) => (
2727
<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+
)}
2931
{item.items && (
3032
<List
3133
key={item.title}

src/components/TableOfContents/TableOfContentsLink.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ import CustomLink from "../Link"
55
import { getCustomId, Item, trimmedTitle } from "./utils"
66

77
export interface IPropsTableOfContentsLink {
8+
depth: number
89
item: Item
910
activeHash?: string
1011
}
1112

12-
const Link: React.FC<IPropsTableOfContentsLink> = ({ item }) => {
13+
const Link: React.FC<IPropsTableOfContentsLink> = ({
14+
depth,
15+
item,
16+
activeHash,
17+
}) => {
1318
const url = `#${getCustomId(item.title)}`
1419

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+
1531
const $dotBg = cssVar("dot-bg")
1632

1733
const hoverOrActiveStyle: SystemStyleObject = {
@@ -34,6 +50,7 @@ const Link: React.FC<IPropsTableOfContentsLink> = ({ item }) => {
3450
<CustomLink
3551
as={GatsbyLink}
3652
to={url}
53+
className={classes}
3754
textDecoration="none"
3855
display="inline-block"
3956
position="relative"

0 commit comments

Comments
 (0)