"use client"; import { useSectionStore } from "@/components/docs/SectionProvider"; import { Tag } from "@/components/docs/Tag"; import { remToPx } from "@/lib/remToPx"; import { useInView } from "framer-motion"; import Link from "next/link"; import { useEffect, useRef } from "react"; function AnchorIcon(props: React.ComponentPropsWithoutRef<"svg">) { return ( ); } function Eyebrow({ tag, label }: { tag?: string; label?: string }) { if (!tag && !label) { return null; } return (
{tag && {tag}} {tag && label && ( )} {label && ( {label} )}
); } function Anchor({ id, inView, children, }: { id: string; inView: boolean; children: React.ReactNode; }) { return ( {inView && (
)} {children} ); } export function Heading({ children, tag, label, level, anchor = true, ...props }: React.ComponentPropsWithoutRef<`h${Level}`> & { id: string; tag?: string; label?: string; level?: Level; anchor?: boolean; }) { level = level ?? (2 as Level); const Component = `h${level}` as "h2" | "h3"; const ref = useRef(null); const registerHeading = useSectionStore((s) => s.registerHeading); const inView = useInView(ref, { margin: `${remToPx(-3.5)}px 0px 0px 0px`, amount: "all", }); useEffect(() => { if (level === 2) { registerHeading({ id: props.id, ref, offsetRem: tag || label ? 8 : 6 }); } }); return ( <> {anchor ? ( {children} ) : ( children )} ); }