-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tooltip to confirm the copy action
- Loading branch information
Showing
4 changed files
with
68 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
import { useState } from "react"; | ||
import { useAppDispatch } from "../hooks"; | ||
import { CopyToClipboard } from "react-copy-to-clipboard"; | ||
import { MdContentCopy } from "react-icons/md"; | ||
import { setCopied } from "../state/priceChartSlice"; | ||
import { DexterToast } from "components/DexterToaster"; | ||
import { useAppDispatch } from "../hooks"; | ||
import Tippy from "@tippyjs/react"; | ||
import "tippy.js/dist/tippy.css"; | ||
import "tippy.js/dist/svg-arrow.css"; | ||
|
||
interface CopyIconProps { | ||
targetUrl: string; | ||
} | ||
|
||
export function CopyIcon({ targetUrl }: CopyIconProps) { | ||
const dispatch = useAppDispatch(); | ||
const [visible, setVisible] = useState(false); | ||
|
||
const handleCopy = () => { | ||
dispatch(setCopied(true)); | ||
DexterToast.success("Copied!"); | ||
setVisible(true); | ||
|
||
setTimeout(() => { | ||
setVisible(false); | ||
dispatch(setCopied(false)); | ||
}, 2000); | ||
}, 700); | ||
}; | ||
|
||
return ( | ||
<> | ||
<CopyToClipboard text={targetUrl} onCopy={handleCopy}> | ||
<MdContentCopy | ||
className="cursor-pointer text-base" | ||
title="Copy to clipboard" | ||
/> | ||
</CopyToClipboard> | ||
<Tippy | ||
content={<span>Copied!</span>} | ||
visible={visible} | ||
onClickOutside={() => setVisible(false)} | ||
arrow={true} | ||
theme="custom" | ||
> | ||
<div> | ||
<CopyToClipboard text={targetUrl} onCopy={handleCopy}> | ||
<MdContentCopy | ||
className="cursor-pointer text-base" | ||
title="Copy to clipboard" | ||
onClick={() => setVisible(true)} | ||
/> | ||
</CopyToClipboard> | ||
</div> | ||
</Tippy> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters