34 lines
838 B
TypeScript
34 lines
838 B
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { Check, Copy } from "lucide-react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
interface CopyButtonProps {
|
|
text: string;
|
|
className?: string;
|
|
}
|
|
|
|
export function CopyButton({ text, className }: CopyButtonProps) {
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
const handleCopy = async () => {
|
|
await navigator.clipboard.writeText(text);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 1500);
|
|
};
|
|
|
|
return (
|
|
<button
|
|
onClick={handleCopy}
|
|
title="Copy to clipboard"
|
|
className={cn(
|
|
"inline-flex items-center justify-center rounded p-0.5 text-muted-foreground/60 transition-colors hover:text-muted-foreground",
|
|
className
|
|
)}
|
|
>
|
|
{copied ? <Check className="h-3 w-3" /> : <Copy className="h-3 w-3" />}
|
|
</button>
|
|
);
|
|
}
|