|
1
|
"use client" |
|
2
|
|
|
3
|
import clsx from "clsx" |
|
4
|
import React from "react" |
|
5
|
import { CopyButton } from "@/components/CopyButton" |
|
6
|
import { Link } from "@/components/Link" |
|
7
|
import { useHeadingUrl } from "../../../hooks/use-heading-url" |
|
8
|
import { useLayout } from "../../../providers/Layout" |
|
9
|
|
|
10
|
export type H3Props = React.HTMLAttributes<HTMLHeadingElement> & { |
|
11
|
id?: string |
|
12
|
hideAnchorLink?: boolean |
|
13
|
} |
|
14
|
|
|
15
|
export const H3 = ({ |
|
16
|
className, |
|
17
|
children, |
|
18
|
hideAnchorLink = false, |
|
19
|
...props |
|
20
|
}: H3Props) => { |
|
21
|
const { showCollapsedNavbar } = useLayout() |
|
22
|
const copyText = useHeadingUrl({ id: props.id || "" }) |
|
23
|
return ( |
|
24
|
<h3 |
|
25
|
className={clsx( |
|
26
|
"text-h3 [&>code]:!text-h3 [&>code]:!font-mono my-docs_1 text-medusa-fg-base", |
|
27
|
props.id && [ |
|
28
|
"group/h3", |
|
29
|
showCollapsedNavbar && "scroll-m-docs_7", |
|
30
|
!showCollapsedNavbar && "scroll-m-56", |
|
31
|
], |
|
32
|
className |
|
33
|
)} |
|
34
|
{...props} |
|
35
|
> |
|
36
|
{children} |
|
37
|
{props.id && !hideAnchorLink && ( |
|
38
|
<CopyButton |
|
39
|
text={copyText} |
|
40
|
className="opacity-0 group-hover/h3:opacity-100 transition-opacity ml-docs_0.5 inline-block" |
|
41
|
> |
|
42
|
<Link href={`#${props.id}`} scroll={false}> |
|
43
|
# |
|
44
|
</Link> |
|
45
|
</CopyButton> |
|
46
|
)} |
|
47
|
</h3> |
|
48
|
) |
|
49
|
} |