From e353eef1855f3c2f66937644a4173e01de05d134 Mon Sep 17 00:00:00 2001 From: dkmyta Date: Sun, 27 Oct 2024 13:28:54 -0600 Subject: [PATCH 1/2] Components: add hoverShow prop to IconTooltip --- .../components/icon-tooltip/index.tsx | 29 ++++++++++++++++++- .../icon-tooltip/stories/index.stories.tsx | 11 +++++++ .../components/icon-tooltip/types.ts | 5 ++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/projects/js-packages/components/components/icon-tooltip/index.tsx b/projects/js-packages/components/components/icon-tooltip/index.tsx index c64b6e74309dd..9e70380a248ae 100644 --- a/projects/js-packages/components/components/icon-tooltip/index.tsx +++ b/projects/js-packages/components/components/icon-tooltip/index.tsx @@ -38,12 +38,14 @@ const IconTooltip: React.FC< IconTooltipProps > = ( { children, popoverAnchorStyle = 'icon', forceShow = false, + hoverShow = false, wide = false, inline = true, shift = false, } ) => { const POPOVER_HELPER_WIDTH = 124; const [ isVisible, setIsVisible ] = useState( false ); + const [ hoverTimeout, setHoverTimeout ] = useState( null ); const hideTooltip = useCallback( () => setIsVisible( false ), [ setIsVisible ] ); const toggleTooltip = useCallback( e => { @@ -78,8 +80,33 @@ const IconTooltip: React.FC< IconTooltipProps > = ( { const isForcedToShow = isAnchorWrapper && forceShow; + const handleMouseEnter = useCallback( () => { + if ( hoverShow ) { + if ( hoverTimeout ) { + clearTimeout( hoverTimeout ); + setHoverTimeout( null ); + } + setIsVisible( true ); + } + }, [ hoverShow, hoverTimeout ] ); + + const handleMouseLeave = useCallback( () => { + if ( hoverShow ) { + const id = setTimeout( () => { + setIsVisible( false ); + setHoverTimeout( null ); + }, 100 ); + setHoverTimeout( id ); + } + }, [ hoverShow ] ); + return ( -
+
{ ! isAnchorWrapper && (