11import React , { MouseEvent } from "react" ;
22
3+ type theme = "dark" | "light" ;
4+
35const copyToClipboard = ( str : string ) => {
46 const el = document . createElement ( "textarea" ) ; // Create a <textarea> element
57 el . value = str ; // Set its value to the string that you want copied
@@ -25,7 +27,7 @@ const containerBaseStyles: React.CSSProperties = {
2527 position : "relative" ,
2628} ;
2729
28- const tooltipBaseStyles : React . CSSProperties = {
30+ const tooltipBaseStyles = ( theme : string ) : React . CSSProperties => ( {
2931 bottom : "26px" ,
3032 maxWidth : "fit-content" ,
3133 position : "absolute" ,
@@ -36,15 +38,15 @@ const tooltipBaseStyles: React.CSSProperties = {
3638 right : "0px" ,
3739 boxShadow : "0px 15px 25px rgba(0,0,0,.1),0px 10px 60px rgba(0,0,0,.1)" ,
3840 fontSize : "12px" ,
39- backgroundColor : " black" ,
40- color : " white" ,
41+ backgroundColor : ` ${ theme === 'light' ? 'white' : ' black' } ` ,
42+ color : ` ${ theme === 'light' ? 'black' : ' white' } ` ,
4143 padding : "6px 8px" ,
4244 borderRadius : "5px" ,
4345 opacity : 0 ,
4446 transform : "translateY(-5px)" ,
4547 visibility : "hidden" ,
4648 transition : "all 0.2s ease-in-out" ,
47- } ;
49+ } ) ;
4850
4951const toolTipVisibleStyles : React . CSSProperties = {
5052 opacity : 1 ,
@@ -54,6 +56,7 @@ const toolTipVisibleStyles: React.CSSProperties = {
5456
5557const CopyMailTo = ( {
5658 email,
59+ theme = "dark" ,
5760 children = null ,
5861 defaultTooltip = "Copy email address" ,
5962 copiedTooltip = "Copied to clipboard!" ,
@@ -62,6 +65,7 @@ const CopyMailTo = ({
6265 anchorStyles = { } ,
6366} : {
6467 email : string ;
68+ theme ?: theme ;
6569 children ?: React . ReactNode ;
6670 defaultTooltip ?: string ;
6771 copiedTooltip ?: string ;
@@ -101,9 +105,9 @@ const CopyMailTo = ({
101105 } ;
102106
103107 const allTooltipStyles = {
104- ...tooltipBaseStyles ,
108+ ...tooltipBaseStyles ( theme ) ,
105109 ...tooltipStyles ,
106- ...( showTooltip && toolTipVisibleStyles ) ,
110+ ...( showTooltip && toolTipVisibleStyles )
107111 } ;
108112
109113 return (
0 commit comments