-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31544 from software-mansion-labs/@kosmydel/ts/too…
…ltip [TS migration] Migrate 'Tooltip' component to TypeScript
- Loading branch information
Showing
16 changed files
with
211 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {forwardRef} from 'react'; | ||
import ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
|
||
// We can't use the common component for the Tooltip as Web implementation uses DOM specific method | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function Tooltip({children}: ChildrenProps, ref: unknown) { | ||
return children; | ||
} | ||
|
||
Tooltip.displayName = 'Tooltip'; | ||
|
||
export default forwardRef(Tooltip); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {BoundsObserver} from '@react-ng/bounds-observer'; | ||
import React, {useContext, useMemo, useRef} from 'react'; | ||
import {PopoverContext} from '@components/PopoverProvider'; | ||
import BaseTooltip from './BaseTooltip'; | ||
import {TooltipExtendedProps} from './types'; | ||
|
||
function PopoverAnchorTooltip({shouldRender = true, children, ...props}: TooltipExtendedProps) { | ||
const {isOpen, popover} = useContext(PopoverContext); | ||
const tooltipRef = useRef<BoundsObserver>(null); | ||
|
||
const isPopoverRelatedToTooltipOpen = useMemo(() => { | ||
// eslint-disable-next-line @typescript-eslint/dot-notation | ||
const tooltipNode = tooltipRef.current?.['_childNode'] ?? null; | ||
if (isOpen && popover?.anchorRef?.current && tooltipNode && (tooltipNode.contains(popover.anchorRef.current) || tooltipNode === popover.anchorRef.current)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}, [isOpen, popover]); | ||
|
||
if (!shouldRender || isPopoverRelatedToTooltipOpen) { | ||
return children; | ||
} | ||
|
||
return ( | ||
<BaseTooltip | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
ref={tooltipRef} | ||
> | ||
{children} | ||
</BaseTooltip> | ||
); | ||
} | ||
|
||
PopoverAnchorTooltip.displayName = 'PopoverAnchorTooltip'; | ||
|
||
export default PopoverAnchorTooltip; |
Oops, something went wrong.