Skip to content

Commit 32f2aac

Browse files
refactor(table-of-contents): remove isActive and depth logic from link component
1 parent 235be43 commit 32f2aac

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

src/components/TableOfContents/ItemsList.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ const ItemsList: React.FC<IPropsItemsList> = ({
2525
<>
2626
{items.map((item, index) => (
2727
<ListItem key={index} m={0} {...rest}>
28-
{item.title && (
29-
<Link depth={depth} item={item} activeHash={activeHash} />
30-
)}
28+
{item.title && <Link item={item} activeHash={activeHash} />}
3129
{item.items && (
3230
<List
3331
key={item.title}

src/components/TableOfContents/TableOfContentsLink.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,12 @@ import CustomLink from "../Link"
55
import { getCustomId, Item, trimmedTitle } from "./utils"
66

77
export interface IPropsTableOfContentsLink {
8-
depth: number
98
item: Item
109
activeHash?: string
1110
}
1211

13-
const Link: React.FC<IPropsTableOfContentsLink> = ({
14-
depth,
15-
item,
16-
activeHash,
17-
}) => {
12+
const Link: React.FC<IPropsTableOfContentsLink> = ({ item }) => {
1813
const url = `#${getCustomId(item.title)}`
19-
const isActive = activeHash === url
20-
const isNested = depth === 2
21-
let classes = ""
22-
if (isActive) {
23-
classes += " active"
24-
}
25-
if (isNested) {
26-
classes += " nested"
27-
}
2814

2915
const $dotBg = cssVar("dot-bg")
3016

@@ -48,7 +34,6 @@ const Link: React.FC<IPropsTableOfContentsLink> = ({
4834
<CustomLink
4935
as={GatsbyLink}
5036
to={url}
51-
className={classes}
5237
textDecoration="none"
5338
display="inline-block"
5439
position="relative"

0 commit comments

Comments
 (0)