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 11, 2020
1 parent be5aaf5 commit 38662e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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
12 changes: 7 additions & 5 deletions src/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const containerBaseStyles: React.CSSProperties = {
position: "relative",
};

const tooltipBaseStyles: React.CSSProperties = {
bottom: "26px",
const tooltipBaseStyles = (showTooltipAtBottom: boolean): React.CSSProperties => ({
[ showTooltipAtBottom ? "top": "bottom" ]: "26px",
maxWidth: "fit-content",
position: "absolute",
width: "auto",
Expand All @@ -41,10 +41,10 @@ const tooltipBaseStyles: 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",
};
});

const toolTipVisibleStyles: React.CSSProperties = {
opacity: 1,
Expand All @@ -60,6 +60,7 @@ const CopyMailTo = ({
containerStyles = {},
tooltipStyles = {},
anchorStyles = {},
showTooltipAtBottom = false,
}: {
email: string;
children?: React.ReactNode;
Expand All @@ -68,6 +69,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 @@ -101,7 +103,7 @@ const CopyMailTo = ({
};

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

0 comments on commit 38662e9

Please sign in to comment.