diff options
| author | Yuval Adam <_@yuv.al> | 2024-09-24 14:27:43 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2024-09-24 14:27:43 +0200 |
| commit | 2c4773cbfa77ec7cb6a2b4d5bf2f122700e3b718 (patch) | |
| tree | e9f03b8838efbfc25818316c3f51bc7bb71b391a | |
| parent | 8e085d9f066b4bbc43a72c29f0e59d37ff6d7534 (diff) | |
Add copy CIDR button, fixes #25
| -rw-r--r-- | app/page.tsx | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/app/page.tsx b/app/page.tsx index 94c76f6..13ce9ee 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -7,6 +7,7 @@ export default function Cidr() { const [ip, setIp] = useState([10, 88, 135, 144]); const [cidr, setCidr] = useState(28); const [cols] = useState(["bg-purple-400", "bg-red-400", "bg-green-400", "bg-yellow-400", "bg-slate-300"]); + const [isCopied, setIsCopied] = useState(false); const [isShared, setIsShared] = useState(false); const bits = ip.map(octet => Array.from({ length: 8 }, (_, i) => (octet >> (7 - i)) & 1)); @@ -113,6 +114,12 @@ export default function Cidr() { updateCidrString(text); } + const handleCopy = async () => { + await navigator.clipboard.writeText(pretty); + setIsCopied(true); + setTimeout(() => setIsCopied(false), 2000); + }; + const handleShare = async () => { const frag = "#" + ip.join(".") + "/" + cidr; window.location.hash = frag; @@ -194,12 +201,22 @@ export default function Cidr() { </div> <div className="flex justify-end p-5"> - <button - onClick={handleShare} - className="flex items-center gap-2 px-4 py-2 text-sm text-gray-100 bg-blue-500 rounded-md hover:bg-blue-600" - > - {isShared ? "Copied!" : "Share"} - </button> + <div className="mx-2"> + <button + onClick={handleCopy} + className="flex items-center gap-2 px-4 py-2 text-sm text-gray-100 bg-blue-500 rounded-md hover:bg-blue-600" + > + {isCopied ? "Copied!" : "Copy CIDR"} + </button> + </div> + <div className="mx-2"> + <button + onClick={handleShare} + className="flex items-center gap-2 px-4 py-2 text-sm text-gray-100 bg-blue-500 rounded-md hover:bg-blue-600" + > + {isShared ? "Copied!" : "Copy Share Link"} + </button> + </div> </div> </div> |
