Skip to content

Commit 29e1790

Browse files
authored
Added a prop for light mode in the tooltip (#10)
1 parent be5aaf5 commit 29e1790

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ You can customize almost every aspect of this component using the below props, o
5050
| Name | Type | Default | Description |
5151
|:-: |--- |--- |--- |
5252
| email | string | none | The email to be copied. |
53+
| theme | string | dark | Use "light" for light background. |
5354
| children | ReactNode | null | Use this if you want to use some custom component inside the anchor tag. |
5455
| defaultTooltip | string | "Copy email address" | Text shown in the tooltip when the user hovers over the link. |
5556
| copiedTooltip | string | "Copied to clipboard!" | Text shown in the tooltip when the user clicks on the link and the text is copied to clipboard. |

src/lib/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { MouseEvent } from "react";
22

3+
type theme = "dark" | "light";
4+
35
const 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

4951
const toolTipVisibleStyles: React.CSSProperties = {
5052
opacity: 1,
@@ -54,6 +56,7 @@ const toolTipVisibleStyles: React.CSSProperties = {
5456

5557
const 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

Comments
 (0)