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 H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
11 id?: string
12 passRef?: React.RefObject<HTMLHeadingElement | null>
13 hideAnchorLink?: boolean
14 }
15
16 export const H2 = ({
17 className,
18 children,
19 passRef,
20 hideAnchorLink = false,
21 ...props
22 }: H2Props) => {
23 const { showCollapsedNavbar } = useLayout()
24
25 const copyText = useHeadingUrl({
26 id: props.id || "",
27 })
28 return (
29 <h2
30 className={clsx(
31 "text-h2 [&>code]:!text-h2 [&>code]:!font-mono mb-docs_1 mt-docs_2 text-medusa-fg-base",
32 props.id && [
33 "group/h2",
34 showCollapsedNavbar && "scroll-m-docs_7",
35 !showCollapsedNavbar && "scroll-m-56",
36 ],
37 className
38 )}
39 {...props}
40 ref={passRef}
41 >
42 {children}
43 {props.id && !hideAnchorLink && (
44 <CopyButton
45 text={copyText}
46 className="opacity-0 group-hover/h2:opacity-100 transition-opacity ml-docs_0.5 inline-block"
47 >
48 <Link href={`#${props.id}`} scroll={false} prefetch={false}>
49 #
50 </Link>
51 </CopyButton>
52 )}
53 </h2>
54 )
55 }