kimi2.6.0 / web /src /components /shared /CopyButton.tsx
heyeyydss's picture
Upload 120 files
d18adc9 verified
Raw
History Blame Contribute Delete
821 Bytes
import { useState, useCallback } from "react"
import { Copy, Check } from "lucide-react"
import { Button } from "@/components/ui/button"
interface CopyButtonProps {
text: string
className?: string
}
export function CopyButton({ text, className }: CopyButtonProps) {
const [copied, setCopied] = useState(false)
const handleCopy = useCallback(async () => {
try {
await navigator.clipboard.writeText(text)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
} catch {
setCopied(false)
}
}, [text])
return (
<Button
variant="ghost"
size="icon"
className={className}
onClick={handleCopy}
>
{copied ? (
<Check className="h-4 w-4 text-success" />
) : (
<Copy className="h-4 w-4" />
)}
</Button>
)
}