import { ComponentPropsWithoutRef, useEffect, useRef } from 'react' import { cn } from '@/lib/utils' type Level = 2 | 3 interface HeadingProps extends Omit, 'children'> { id: string level?: Level children: React.ReactNode } const levelStyles = { 2: { tag: 'h2', className: 'text-2xl font-semibold mb-4' }, 3: { tag: 'h3', className: 'text-xl font-semibold mb-3' }, } as const export function Heading({ id, level = 2, className, children, ...props }: HeadingProps) { const ref = useRef(null) const { tag: Tag, className: defaultClassName } = levelStyles[level] useEffect(() => { if (window.location.hash === `#${id}`) { ref.current?.scrollIntoView({ behavior: 'smooth' }) } }, [id]) return ( # {children} ) }