mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-21 00:10:33 +02:00
fix: fixed copy to clipboard button (#8426)
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
22
packages/excalidraw/hooks/useCopiedIndicator.ts
Normal file
22
packages/excalidraw/hooks/useCopiedIndicator.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
const TIMEOUT = 2000;
|
||||
|
||||
export const useCopyStatus = () => {
|
||||
const [copyStatus, setCopyStatus] = useState<"success" | null>(null);
|
||||
const timeoutRef = useRef<number>(0);
|
||||
|
||||
const onCopy = () => {
|
||||
clearTimeout(timeoutRef.current);
|
||||
setCopyStatus("success");
|
||||
|
||||
timeoutRef.current = window.setTimeout(() => {
|
||||
setCopyStatus(null);
|
||||
}, TIMEOUT);
|
||||
};
|
||||
|
||||
return {
|
||||
copyStatus,
|
||||
onCopy,
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user