Skip to content

Commit

Permalink
Added tooltip to bottom feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
BhaveshSGupta committed Oct 16, 2020
1 parent 42e390e commit 091d220
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ You can customize almost every aspect of this component using the below props, o
| containerStyles | style object | none | The styles to be applied to the container. |
| tooltipStyles | style object | none | The styles to be applied to the tooltip. |
| anchorStyles | style object | none | The styles to be applied to the anchor. |
| showTooltipAtBottom | boolean | false | This is use to position tooltip to bottom. |

## Development

Expand Down
10 changes: 6 additions & 4 deletions src/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const containerBaseStyles: React.CSSProperties = {
position: "relative",
};

const tooltipBaseStyles = (theme: string): React.CSSProperties => ({
bottom: "26px",
const tooltipBaseStyles = (theme: string, showTooltipAtBottom: boolean): React.CSSProperties => ({
[ showTooltipAtBottom ? "top": "bottom" ]: "26px",
maxWidth: "fit-content",
position: "absolute",
width: "auto",
Expand All @@ -43,7 +43,7 @@ const tooltipBaseStyles = (theme: string): React.CSSProperties => ({
padding: "6px 8px",
borderRadius: "5px",
opacity: 0,
transform: "translateY(-5px)",
transform: `translateY(${showTooltipAtBottom ? "": "-"}5px)`,
visibility: "hidden",
transition: "all 0.2s ease-in-out",
});
Expand All @@ -63,6 +63,7 @@ const CopyMailTo = ({
containerStyles = {},
tooltipStyles = {},
anchorStyles = {},
showTooltipAtBottom = false,
}: {
email: string;
theme?: theme;
Expand All @@ -72,6 +73,7 @@ const CopyMailTo = ({
containerStyles?: React.CSSProperties;
tooltipStyles?: React.CSSProperties;
anchorStyles?: React.CSSProperties;
showTooltipAtBottom?: boolean;
}): JSX.Element => {
const [showCopied, setShowCopied] = React.useState(false);
const [showTooltip, setShowTooltip] = React.useState(false);
Expand Down Expand Up @@ -103,7 +105,7 @@ const CopyMailTo = ({
};

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

0 comments on commit 091d220

Please sign in to comment.