24 lines
503 B
TypeScript
24 lines
503 B
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
|
|
export function CopyButton({ value, label = "Kopieren" }: { value: string; label?: string }) {
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
async function copy() {
|
|
try {
|
|
await navigator.clipboard.writeText(value);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2000);
|
|
} catch {
|
|
setCopied(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<button type="button" className="btn btn-sekundaer btn-klein" onClick={copy}>
|
|
{copied ? "Kopiert" : label}
|
|
</button>
|
|
);
|
|
}
|