24 lines
609 B
TypeScript
24 lines
609 B
TypeScript
"use client";
|
|
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
import { useState } from "react";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
export function CopyButton({ text }: { text: string }) {
|
|
const [copied, setCopied] = useState(false);
|
|
return (
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={async () => {
|
|
await navigator.clipboard.writeText(text);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2000);
|
|
}}
|
|
>
|
|
{copied ? <CheckIcon /> : <CopyIcon />}
|
|
{copied ? "Copied" : "Copy"}
|
|
</Button>
|
|
);
|
|
}
|