'use client';
import { cn } from '@fumadocs/ui/cn';
import { Link, Check } from 'lucide-react';
import { useState, type ComponentPropsWithoutRef } from 'react';
type HeadingProps = ComponentPropsWithoutRef<'h1'> & {
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
};
export function Heading({ as, className, ...props }: HeadingProps) {
const As = as ?? 'h1';
if (!props.id) return ;
return (
{props.children}
);
}
function HeadingAnchor({ id, children }: { id: string; children: React.ReactNode }) {
const [copied, setCopied] = useState(false);
const copyLink = () => {
const url = `${window.location.origin}${window.location.pathname}${window.location.search}#${id}`;
window.history.replaceState(null, '', `#${id}`);
navigator.clipboard.writeText(url).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
}).catch(() => {});
};
const handleClick = (e: React.MouseEvent) => {
e.preventDefault();
copyLink();
};
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
copyLink();
}
};
return (
<>
{children}
{copied ? (
) : (
)}
>
);
}