Files
xmrcheckout/ui/components/copy-icon-button.tsx
T

57 lines
1.5 KiB
TypeScript

"use client";
import { useState } from "react";
type CopyIconButtonProps = {
value: string;
label: string;
className?: string;
};
export default function CopyIconButton({ value, label, className }: CopyIconButtonProps) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(value);
setCopied(true);
window.setTimeout(() => setCopied(false), 1500);
} catch {
setCopied(false);
}
};
return (
<button
type="button"
aria-label={label}
title={copied ? "Copied" : label}
onClick={handleCopy}
className={
className ??
"inline-flex h-7 w-7 items-center justify-center rounded-md border border-neutral-200 bg-white text-neutral-600 transition hover:bg-neutral-50"
}
>
{copied ? (
<svg viewBox="0 0 24 24" className="h-4 w-4" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M20 6 9 17l-5-5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
) : (
<svg viewBox="0 0 24 24" className="h-4 w-4" fill="none" stroke="currentColor" strokeWidth="2">
<path
d="M8 5h9a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2Z"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M6 17H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
)}
</button>
);
}