import { useCallback, useRef, useState } from "react"; import { cn } from "@/lib/utils"; interface CopyTextProps { text: string; /** What to display. Defaults to `text`. */ children?: React.ReactNode; className?: string; /** Tooltip message shown after copying. Default: "Copied!" */ copiedLabel?: string; } export function CopyText({ text, children, className, copiedLabel = "Copied!" }: CopyTextProps) { const [visible, setVisible] = useState(false); const timerRef = useRef>(undefined); const triggerRef = useRef(null); const handleClick = useCallback(() => { navigator.clipboard.writeText(text); clearTimeout(timerRef.current); setVisible(true); timerRef.current = setTimeout(() => setVisible(false), 1500); }, [text]); return ( {copiedLabel} ); }