diff --git a/components/CopyToClipboard/CopyToClipboard.tsx b/components/CopyToClipboard/CopyToClipboard.tsx index e28002ea7..ab8b12bad 100644 --- a/components/CopyToClipboard/CopyToClipboard.tsx +++ b/components/CopyToClipboard/CopyToClipboard.tsx @@ -1,50 +1,36 @@ -import useCopyToClipboard from 'hooks/useCopyToClipboard' -import React, { useState } from 'react' -import { FaRegCopy } from 'react-icons/fa' +import useCopyToClipboard from 'hooks/useCopyToClipboard'; +import React, { useState } from 'react'; +import { FaRegCopy, FaCheckSquare } from 'react-icons/fa'; type CopyToClipboardProps = { - url: string -} + url: string; +}; export const CopyToClipboard = ({ url }: CopyToClipboardProps): JSX.Element => { - const [copyToClipboard, { success }] = useCopyToClipboard() - const [isHovering, setIsHovering] = useState(false) + const [copyToClipboard, { success }] = useCopyToClipboard(); + const [isCopied, setIsCopied] = useState(false); - function handleCopy(e: React.MouseEvent) { - e.stopPropagation() - copyToClipboard(url) + function handleCopy() { + copyToClipboard(url); + setIsCopied(true); + setTimeout(() => setIsCopied(false), 2000); // Reset the icon after 2 seconds } return ( -
setIsHovering(true)} - onMouseLeave={() => setIsHovering(false)} +
- ) -} + {success && isCopied ? ( + + ) : ( + + )} + + ); +}; -export default CopyToClipboard +export default CopyToClipboard;