From 1cebdc68527ba9b9d6ea8b422cc8b8a6777a82b0 Mon Sep 17 00:00:00 2001 From: Pavel Klibani Date: Tue, 13 Feb 2024 15:17:02 +0100 Subject: [PATCH] fixup! fixup! fixup! Feat(web-react): Tooltip can be opened by hover --- .../web-react/src/components/Tooltip/TooltipModern.tsx | 4 ++-- packages/web-react/src/components/Tooltip/useFloating.ts | 8 ++++---- .../components/TooltipModern/demo/TooltipDismissible.tsx | 2 +- .../TooltipModern/demo/TooltipDismissibleViaJS.tsx | 9 ++++++++- .../src/components/TooltipModern/demo/TooltipHover.tsx | 1 - .../TooltipModern/demo/TooltipWithFloatingUI.tsx | 1 - packages/web-react/src/types/tooltip.ts | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/web-react/src/components/Tooltip/TooltipModern.tsx b/packages/web-react/src/components/Tooltip/TooltipModern.tsx index 37f45c0b8e..e24842852d 100644 --- a/packages/web-react/src/components/Tooltip/TooltipModern.tsx +++ b/packages/web-react/src/components/Tooltip/TooltipModern.tsx @@ -20,7 +20,7 @@ const TooltipModern = (props: TooltipModernProps) => { isOpen = false, onToggle, placement: tooltipPlacement, - triggers = ['click', 'hover'], + trigger = ['click', 'hover'], ...rest } = props; @@ -65,7 +65,7 @@ const TooltipModern = (props: TooltipModernProps) => { tooltipArrowWidth, tooltipMaxWidth, tooltipPlacement, - triggers, + trigger, }); useDeprecationMessage({ diff --git a/packages/web-react/src/components/Tooltip/useFloating.ts b/packages/web-react/src/components/Tooltip/useFloating.ts index 84819a4d20..94531cdc0f 100644 --- a/packages/web-react/src/components/Tooltip/useFloating.ts +++ b/packages/web-react/src/components/Tooltip/useFloating.ts @@ -32,7 +32,7 @@ type UseTooltipUIProps = { tooltipArrowWidth?: number; tooltipMaxWidth?: number; tooltipPlacement?: Placement; - triggers?: ('click' | 'hover')[]; + trigger?: ('click' | 'hover')[]; }; // Convert a string or array of strings to an array of strings (for placements) @@ -54,15 +54,15 @@ export const useFloating = (props: UseTooltipUIProps) => { sizeProp, tooltipArrowWidth = 0, tooltipPlacement, - triggers, + trigger, } = props; const [maxWidth, setMaxWidth] = useState(undefined); const [isClicked, setIsClicked] = useState(false); const mainAxisOffset = cornerOffset + tooltipArrowWidth; - const isHoverEnabled = triggers?.includes('hover'); - const isClickEnabled = triggers?.includes('click'); + const isHoverEnabled = trigger?.includes('hover'); + const isClickEnabled = trigger?.includes('click'); // Floating UI library settings const { x, y, refs, context, placement, middlewareData } = useFloatingUI({ diff --git a/packages/web-react/src/components/TooltipModern/demo/TooltipDismissible.tsx b/packages/web-react/src/components/TooltipModern/demo/TooltipDismissible.tsx index 416581dbd7..eea3b25121 100644 --- a/packages/web-react/src/components/TooltipModern/demo/TooltipDismissible.tsx +++ b/packages/web-react/src/components/TooltipModern/demo/TooltipDismissible.tsx @@ -13,7 +13,7 @@ const TooltipDismissible = () => { onToggle={setOpen} placement="right" isDismissible - triggers={['click']} + trigger={['click']} > I have a tooltip 😎 Close me diff --git a/packages/web-react/src/components/TooltipModern/demo/TooltipDismissibleViaJS.tsx b/packages/web-react/src/components/TooltipModern/demo/TooltipDismissibleViaJS.tsx index b0d2a715e3..eea25e6f64 100644 --- a/packages/web-react/src/components/TooltipModern/demo/TooltipDismissibleViaJS.tsx +++ b/packages/web-react/src/components/TooltipModern/demo/TooltipDismissibleViaJS.tsx @@ -13,7 +13,14 @@ const TooltipDismissibleViaJS = () => { return (

Saves data to local storage.

- + I have a tooltip 😎 Close me diff --git a/packages/web-react/src/components/TooltipModern/demo/TooltipHover.tsx b/packages/web-react/src/components/TooltipModern/demo/TooltipHover.tsx index c5662db654..8247665d52 100644 --- a/packages/web-react/src/components/TooltipModern/demo/TooltipHover.tsx +++ b/packages/web-react/src/components/TooltipModern/demo/TooltipHover.tsx @@ -12,7 +12,6 @@ const TooltipHover = () => { isOpen={open} onToggle={setOpen} placement="right" - triggers={['click', 'hover']} flipFallbackPlacements={['left', 'top-start', 'bottom-start']} > I have a tooltip 😎 diff --git a/packages/web-react/src/components/TooltipModern/demo/TooltipWithFloatingUI.tsx b/packages/web-react/src/components/TooltipModern/demo/TooltipWithFloatingUI.tsx index d538bf3d3d..495ad2ac89 100644 --- a/packages/web-react/src/components/TooltipModern/demo/TooltipWithFloatingUI.tsx +++ b/packages/web-react/src/components/TooltipModern/demo/TooltipWithFloatingUI.tsx @@ -129,7 +129,6 @@ const TooltipWithFloatingUI = () => { flipFallbackPlacements={suggestedFallbackPlacement} enableShifting={shift} enableSizing={size} - triggers={['click', 'hover']} > I have a tooltip 😎 diff --git a/packages/web-react/src/types/tooltip.ts b/packages/web-react/src/types/tooltip.ts index 199ea9da6a..96436fd23b 100644 --- a/packages/web-react/src/types/tooltip.ts +++ b/packages/web-react/src/types/tooltip.ts @@ -48,5 +48,5 @@ export interface SpiritTooltipModernProps extends TooltipModernProps, ChildrenPr enableSizing?: boolean; flipFallbackAxisSideDirection?: 'none' | 'start' | 'end'; flipFallbackPlacements?: Placement | Placement[]; - triggers?: ('click' | 'hover')[]; + trigger?: ('click' | 'hover')[]; }