"use client"; import React, { useState } from "react"; import { Check, Copy } from "lucide-react"; import { Button } from "@/components/ui/button"; import { copyToClipboard } from "@/lib/utils"; import { cn } from "@/lib/utils"; export interface CopyButtonProps extends React.ButtonHTMLAttributes { text?: string | (() => string); onCopy?: () => void; iconOnly?: boolean; variant?: any; } export const CopyButton = React.forwardRef( ({ text, onCopy, iconOnly = true, className, variant = "link", children, onClick, ...props }, ref) => { const [copied, setCopied] = useState(false); const handleCopy = (e: React.MouseEvent) => { e.stopPropagation(); if (text) { const copyContent = typeof text === "function" ? text() : text; copyToClipboard(copyContent); } if (onCopy) { onCopy(); } if (onClick) { onClick(e); } setCopied(true); setTimeout(() => setCopied(false), 2000); }; return ( ); } ); CopyButton.displayName = "CopyButton";