Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a prop for light mode in the tooltip #10

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ You can customize almost every aspect of this component using the below props, o
| Name | Type | Default | Description |
|:-: |--- |--- |--- |
| email | string | none | The email to be copied. |
| theme | string | dark | Use "light" for light background. |
| children | ReactNode | null | Use this if you want to use some custom component inside the anchor tag. |
| defaultTooltip | string | "Copy email address" | Text shown in the tooltip when the user hovers over the link. |
| copiedTooltip | string | "Copied to clipboard!" | Text shown in the tooltip when the user clicks on the link and the text is copied to clipboard. |
Expand Down
16 changes: 10 additions & 6 deletions src/lib/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { MouseEvent } from "react";

type theme = "dark" | "light";

const copyToClipboard = (str: string) => {
const el = document.createElement("textarea"); // Create a <textarea> element
el.value = str; // Set its value to the string that you want copied
Expand All @@ -25,7 +27,7 @@ const containerBaseStyles: React.CSSProperties = {
position: "relative",
};

const tooltipBaseStyles: React.CSSProperties = {
const tooltipBaseStyles = (theme: string): React.CSSProperties => ({
bottom: "26px",
maxWidth: "fit-content",
position: "absolute",
Expand All @@ -36,15 +38,15 @@ const tooltipBaseStyles: React.CSSProperties = {
right: "0px",
boxShadow: "0px 15px 25px rgba(0,0,0,.1),0px 10px 60px rgba(0,0,0,.1)",
fontSize: "12px",
backgroundColor: "black",
color: "white",
backgroundColor: `${theme === 'light' ? 'white' : 'black'}`,
color: `${theme === 'light' ? 'black' : 'white'}`,
padding: "6px 8px",
borderRadius: "5px",
opacity: 0,
transform: "translateY(-5px)",
visibility: "hidden",
transition: "all 0.2s ease-in-out",
};
});

const toolTipVisibleStyles: React.CSSProperties = {
opacity: 1,
Expand All @@ -54,6 +56,7 @@ const toolTipVisibleStyles: React.CSSProperties = {

const CopyMailTo = ({
email,
theme = "dark",
children = null,
defaultTooltip = "Copy email address",
copiedTooltip = "Copied to clipboard!",
Expand All @@ -62,6 +65,7 @@ const CopyMailTo = ({
anchorStyles = {},
}: {
email: string;
theme?: theme;
children?: React.ReactNode;
defaultTooltip?: string;
copiedTooltip?: string;
Expand Down Expand Up @@ -101,9 +105,9 @@ const CopyMailTo = ({
};

const allTooltipStyles = {
...tooltipBaseStyles,
...tooltipBaseStyles(theme),
...tooltipStyles,
...(showTooltip && toolTipVisibleStyles),
...(showTooltip && toolTipVisibleStyles)
};

return (
Expand Down