"use client"; import { useInView } from "framer-motion"; import Link from "next/link"; import { type ComponentPropsWithoutRef, type ReactNode, type RefObject, useEffect, useRef, } from "react"; import { remToPx } from "../lib/remToPx"; import { useSectionStore } from "./SectionProvider"; import { Tag } from "./Tag"; export function AnchorIcon(props: 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: ReactNode; }) { return ( {inView && (
)} {children} ); } export function Heading({ children, tag, label, level, anchor = true, ...props }: 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 && ref.current) { registerHeading({ id: props.id, ref: ref as RefObject, offsetRem: tag || label ? 8 : 6, }); } }); return ( <> {anchor ? ( {children} ) : ( children )} ); }