Initial commit
This commit is contained in:
27
components/public/copy-button.tsx
Normal file
27
components/public/copy-button.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
"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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user