28 lines
578 B
TypeScript
28 lines
578 B
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
|
|
type CopyButtonProps = {
|
|
value: string;
|
|
};
|
|
|
|
export function CopyButton({ value }: CopyButtonProps) {
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
async function handleCopy() {
|
|
try {
|
|
await navigator.clipboard.writeText(value);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 1200);
|
|
} catch {
|
|
setCopied(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<button type="button" onClick={handleCopy} aria-label="Copy value" className="method-action">
|
|
{copied ? "Copied" : "Copy"}
|
|
</button>
|
|
);
|
|
}
|