Skip to content

Commit 6269378

Browse files
committed
Highlight current heading
1 parent 240c6e6 commit 6269378

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/_design-system/mdx-components/get-mdx-headings.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const createHeading = (
3030
id,
3131
className,
3232
...props
33-
}: React.ComponentPropsWithoutRef<"h2">): React.ReactElement {
33+
}: React.ComponentPropsWithoutRef<"h2"> & {
34+
size?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6"
35+
}): React.ReactElement {
3436
// Nextra tracks anchors in context
3537
const setActiveAnchor = useSetActiveAnchor()
3638
const slugs = useSlugs()
@@ -61,7 +63,7 @@ const createHeading = (
6163
className === "sr-only"
6264
? // can be added by footnotes
6365
"sr-only"
64-
: clsx(headingClasses[Tag], "text-neu-900", className)
66+
: clsx(headingClasses[props.size || Tag], "text-neu-900", className)
6567
}
6668
{...props}
6769
>

src/components/faq-aggregator/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client"
22

3+
import { getMdxHeadings } from "@/_design-system/mdx-components/get-mdx-headings"
34
import { type ReactNode, useRef, useLayoutEffect, useState } from "react"
45

56
function slugify(text: string): string {
@@ -9,17 +10,18 @@ function slugify(text: string): string {
910
.replace(/(^-|-$)/g, "")
1011
}
1112

13+
const mdxHeadings = getMdxHeadings()
14+
1215
function FaqH1({ id, children }: { id?: string; children?: ReactNode }) {
1316
const slug = id ?? slugify(String(children))
1417
return (
15-
<h2
18+
<mdxHeadings.h2
1619
id={slug}
17-
className="typography-h2 mb-4 mt-8 scroll-mt-24 text-neu-900 first:mt-0"
20+
size="h1"
21+
className="mb-4 mt-8 scroll-mt-24 text-neu-900 first:mt-0"
1822
>
19-
<a href={`#${slug}`} className="hover:underline">
20-
{children}
21-
</a>
22-
</h2>
23+
{children}
24+
</mdxHeadings.h2>
2325
)
2426
}
2527

0 commit comments

Comments
 (0)