fix(dashboard-v2): fix CopyButton's timeout

This commit is contained in:
Michał Leszczyk 2022-03-16 09:04:15 +01:00
parent 2e871f4712
commit 539fc32fb9
No known key found for this signature in database
GPG Key ID: FA123CA8BAA2FBF4
1 changed files with 3 additions and 3 deletions

View File

@ -22,7 +22,7 @@ const TooltipContent = styled.div.attrs({
className: "bg-primary-light/10 text-palette-600 py-2 px-4 ", className: "bg-primary-light/10 text-palette-600 py-2 px-4 ",
})``; })``;
export const CopyButton = ({ value }) => { export const CopyButton = ({ value, className }) => {
const containerRef = useRef(); const containerRef = useRef();
const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
const [timer, setTimer] = useState(null); const [timer, setTimer] = useState(null);
@ -32,13 +32,13 @@ export const CopyButton = ({ value }) => {
copy(value); copy(value);
setCopied(true); setCopied(true);
setTimer(setTimeout(() => setCopied(false), 150000)); setTimer(setTimeout(() => setCopied(false), 1500));
}, [value, timer]); }, [value, timer]);
useClickAway(containerRef, () => setCopied(false)); useClickAway(containerRef, () => setCopied(false));
return ( return (
<div ref={containerRef} className="inline-flex relative overflow-visible pr-2"> <div ref={containerRef} className={`inline-flex relative overflow-visible pr-2 ${className ?? ""}`}>
<Button onClick={handleCopy} className={copied ? "text-primary" : ""}> <Button onClick={handleCopy} className={copied ? "text-primary" : ""}>
<CopyIcon size={16} /> <CopyIcon size={16} />
</Button> </Button>