From 03394f1b3747f5a11f449504a48ab1a653c97d3e Mon Sep 17 00:00:00 2001 From: Dewansh Rawat Date: Sun, 3 Oct 2021 15:58:02 +0530 Subject: [PATCH 1/2] Added a feature to encrypt mail in base64 --- src/demo/index.tsx | 19 +++++++++++-------- src/lib/index.tsx | 12 +++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/demo/index.tsx b/src/demo/index.tsx index 4db66df..7f6013a 100644 --- a/src/demo/index.tsx +++ b/src/demo/index.tsx @@ -3,13 +3,16 @@ import ReactDOM from "react-dom"; import CopyMailTo from "../lib"; -const App = () => ( -
-

Copy email address to clipboard

- -
-); +const App = () => { + let email = "email@domain.com"; + return ( +
+

Copy email address to clipboard

+ +
+ ) +}; ReactDOM.render(, document.getElementById("app")); diff --git a/src/lib/index.tsx b/src/lib/index.tsx index abb9161..7c76ad5 100644 --- a/src/lib/index.tsx +++ b/src/lib/index.tsx @@ -3,6 +3,7 @@ import React, { MouseEvent } from "react"; type theme = "dark" | "light"; interface CopyMailToPropsInterface { email: string; + isSecure: boolean; theme: theme; children?: React.ReactNode; defaultTooltip?: string; @@ -66,6 +67,7 @@ const toolTipVisibleStyles: React.CSSProperties = { const CopyMailTo = ({ email, + isSecure, theme = "dark", children = null, defaultTooltip = "Copy email address", @@ -79,7 +81,7 @@ const CopyMailTo = ({ const copyEmail = (e: MouseEvent) => { e.preventDefault(); - copyToClipboard(email); + copyToClipboard(window.atob(email)); setShowCopied(true); setShowTooltip(true); }; @@ -109,6 +111,10 @@ const CopyMailTo = ({ ...(showTooltip && toolTipVisibleStyles) }; + if(isSecure){ + email = window.btoa(email); + } + return ( - {children || email} + {children || isSecure ? window.atob(email) : email} {showCopied ? copiedTooltip : defaultTooltip} From f7362d47647325d1f3740683f75f823f4a813e8a Mon Sep 17 00:00:00 2001 From: Dewansh Rawat Date: Sun, 3 Oct 2021 16:03:59 +0530 Subject: [PATCH 2/2] Patch to secure email --- src/demo/index.tsx | 3 ++- src/lib/index.tsx | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/demo/index.tsx b/src/demo/index.tsx index 7f6013a..1d2706c 100644 --- a/src/demo/index.tsx +++ b/src/demo/index.tsx @@ -5,12 +5,13 @@ import CopyMailTo from "../lib"; const App = () => { let email = "email@domain.com"; + let isSecure = false; return (

Copy email address to clipboard

- +
) }; diff --git a/src/lib/index.tsx b/src/lib/index.tsx index 7c76ad5..c6e5660 100644 --- a/src/lib/index.tsx +++ b/src/lib/index.tsx @@ -79,9 +79,13 @@ const CopyMailTo = ({ const [showCopied, setShowCopied] = React.useState(false); const [showTooltip, setShowTooltip] = React.useState(false); - const copyEmail = (e: MouseEvent) => { + const copyEmail = (e: MouseEvent, isSecure: Boolean) => { e.preventDefault(); - copyToClipboard(window.atob(email)); + if(isSecure){ + copyToClipboard(window.atob(email)); + } else { + copyToClipboard(email); + } setShowCopied(true); setShowTooltip(true); }; @@ -119,7 +123,7 @@ const CopyMailTo = ({ copyEmail(e, isSecure)} onMouseOver={toggleTooltip} onMouseOut={toggleTooltip} onFocus={toggleTooltip}