mirror of
https://github.com/logos-storage/logos-storage-marketplace-ui.git
synced 2026-01-09 00:43:06 +00:00
38 lines
841 B
TypeScript
38 lines
841 B
TypeScript
import { useRef, useState } from "react";
|
|
import { COPY_DURATION } from "../../utils/constants";
|
|
import { Button } from "@codex-storage/marketplace-ui-components";
|
|
import { CoypIcon } from "./CopyIcon";
|
|
|
|
type CopyButtonProps = {
|
|
cid: string;
|
|
};
|
|
|
|
export function CidCopyButton({ cid }: CopyButtonProps) {
|
|
const [copied, setCopied] = useState(false);
|
|
const timeout = useRef<number | null>(null);
|
|
|
|
const onCopy = () => {
|
|
if (timeout.current) {
|
|
clearTimeout(timeout.current);
|
|
}
|
|
|
|
navigator.clipboard.writeText(cid);
|
|
|
|
setCopied(true);
|
|
|
|
timeout.current = window.setTimeout(() => {
|
|
setCopied(false);
|
|
}, COPY_DURATION);
|
|
};
|
|
|
|
const label = copied ? "Copied !" : "Copy CID";
|
|
|
|
return (
|
|
<Button
|
|
label={label}
|
|
variant="outline"
|
|
onClick={onCopy}
|
|
Icon={CoypIcon}></Button>
|
|
);
|
|
}
|