Skip to content

Commit

Permalink
Merge pull request #227 from deriv-com/aizad/FEQ-2469/update-tooltip
Browse files Browse the repository at this point in the history
Aizad/FEQ-2469/Improved Tooltip
  • Loading branch information
shayan-deriv authored Jul 16, 2024
2 parents d2bf5a9 + 380215c commit 91f34a7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/components/Tooltip/Tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
left: -4px;
}

// Hide Tooltip
.deriv-tooltip[data-popper-reference-hidden] {
visibility: hidden;
pointer-events: none;

> .deriv-tooltip__arrow,
.deriv-tooltip__arrow::before {
visibility: hidden;
pointer-events: none;
}
}

// Tooltip Trigger Class
.deriv-tooltip__trigger {
cursor: pointer;
Expand Down
23 changes: 14 additions & 9 deletions src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import "./Tooltip.scss";
type AsElement = "a" | "div" | "button";
type TooltipVariantType = "error" | "general";
export type TooltipProps<T extends AsElement> = ComponentProps<T> & {
as: T;
as?: T;
tooltipContainerClassName?: string;
tooltipContent: ReactNode;
tooltipOffset?: number;
tooltipPosition?: Placement;
variant?: "general" | "error";
hideTooltip?: boolean;
};

const TooltipVariantClass: Record<TooltipVariantType, string> = {
Expand All @@ -38,20 +39,22 @@ const TooltipVariantClass: Record<TooltipVariantType, string> = {
* @param {number} tooltipOffset - The distance between the tooltip and the content.
* @param {React.ReactNode} [icon] - The icon to display. This can be any React node.
* @param {string} [href] - The URL the link points to. Required and applicable only when `as` is "a".
* @param {string} tooltipColor - The background color of the tooltip. Defaults to '#D6DADB'.
* @param {string} tooltipContent - The content to display inside the tooltip.
* @param {string} [tooltipContainerClassName] - Optional class name for the tooltip container.
* @param {TooltipVariantType} [variant="general"] - The variant of the tooltip, which can be "general" or "error".
* @param {boolean} [hideTooltip=false] - If true, the tooltip will not be displayed.
*
* @example
* // To render a button with a tooltip
* <YourComponent as="button" tooltipContent="Save" tooltipPosition="bottom">
* <Tooltip as="button" tooltipContent="Save" tooltipPosition="bottom">
* Save
* </YourComponent>
* </Tooltip>
*
* @example
* // To render a link with a tooltip and an icon
* <YourComponent as="a" href="https://example.com" tooltipContent="Go to Example" tooltipPosition="right" icon={<YourIcon />}>
* <Tooltip as="a" href="https://example.com" tooltipContent="Go to Example" tooltipPosition="right" icon={<YourIcon />}>
* Visit Example.com
* </YourComponent>
* </Tooltip>
*
* @returns {JSX.Element} The rendered component.
*/
Expand All @@ -62,13 +65,14 @@ export const Tooltip = forwardRef<
>(
(
{
as,
as = "div",
children,
hideTooltip = false,
tooltipContainerClassName,
tooltipContent,
tooltipPosition = "auto",
variant = "general",
tooltipOffset = 8,
tooltipPosition = "top",
variant = "general",
...rest
},
ref,
Expand All @@ -90,6 +94,7 @@ export const Tooltip = forwardRef<
name: "offset",
options: { offset: [0, tooltipOffset] },
},
{ name: "hide", enabled: hideTooltip },
],
},
);
Expand Down
4 changes: 4 additions & 0 deletions stories/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const meta: Meta = {
options: ["general", "error"],
},
},
hideTooltip: {
description: "Hide the tooltip.",
control: { type: "boolean" },
},
},
parameters: { layout: "centered" },
tags: ["autodocs"],
Expand Down

0 comments on commit 91f34a7

Please sign in to comment.