|
| 1 | +import { useState } from "react" |
| 2 | +import { FaLink, FaXTwitter } from "react-icons/fa6" |
| 3 | +import { MdCheck } from "react-icons/md" |
| 4 | + |
| 5 | +import { Button } from "@/components/ui/buttons/Button" |
| 6 | +import { |
| 7 | + Dialog, |
| 8 | + DialogContent, |
| 9 | + DialogDescription, |
| 10 | + DialogHeader, |
| 11 | + DialogTitle, |
| 12 | + DialogTrigger, |
| 13 | +} from "@/components/ui/dialog-modal" |
| 14 | + |
| 15 | +import { useClipboard } from "@/hooks/useClipboard" |
| 16 | + |
| 17 | +export const shareOnTwitter = (): void => { |
| 18 | + const url = "https://ethereum.org/start" |
| 19 | + const hashtags = ["ethereum", "web3", "startwithethereum"] |
| 20 | + const tweet = `${encodeURI(`I connected to ethereum on ethereum.org! Try it yourself at ${url}`)}` |
| 21 | + |
| 22 | + window.open( |
| 23 | + `https://twitter.com/intent/tweet?text=${tweet}&hashtags=${hashtags}` |
| 24 | + ) |
| 25 | +} |
| 26 | + |
| 27 | +const ShareModal = () => { |
| 28 | + const [isOpen, setIsOpen] = useState(false) |
| 29 | + const { onCopy, hasCopied } = useClipboard() |
| 30 | + |
| 31 | + return ( |
| 32 | + <Dialog open={isOpen} onOpenChange={setIsOpen}> |
| 33 | + <DialogTrigger> |
| 34 | + <Button>Share this page</Button> |
| 35 | + </DialogTrigger> |
| 36 | + <DialogContent> |
| 37 | + <DialogHeader> |
| 38 | + <DialogTitle>Share this page</DialogTitle> |
| 39 | + </DialogHeader> |
| 40 | + <DialogDescription> |
| 41 | + Share this page with your friends and family. |
| 42 | + </DialogDescription> |
| 43 | + <div className="flex flex-row justify-center"> |
| 44 | + <Button |
| 45 | + onClick={() => onCopy(window.location.href)} |
| 46 | + variant="ghost" |
| 47 | + className="flex flex-col hover:bg-background-highlight" |
| 48 | + > |
| 49 | + {hasCopied ? ( |
| 50 | + <> |
| 51 | + <MdCheck /> |
| 52 | + <p className="text-sm">Copied!</p> |
| 53 | + </> |
| 54 | + ) : ( |
| 55 | + <> |
| 56 | + <FaLink /> |
| 57 | + <p className="text-sm">Share</p> |
| 58 | + </> |
| 59 | + )} |
| 60 | + </Button> |
| 61 | + <Button |
| 62 | + variant="ghost" |
| 63 | + className="flex flex-col hover:bg-background-highlight" |
| 64 | + onClick={() => shareOnTwitter()} |
| 65 | + > |
| 66 | + <FaXTwitter /> |
| 67 | + <p className="text-sm">Twitter</p> |
| 68 | + </Button> |
| 69 | + </div> |
| 70 | + </DialogContent> |
| 71 | + </Dialog> |
| 72 | + ) |
| 73 | +} |
| 74 | + |
| 75 | +export default ShareModal |
0 commit comments