overleaf/services/web/frontend/js/shared/components/tooltip.tsx
ilkin-overleaf 41a706108c Merge pull request #11941 from overleaf/ii-recompile-tooltip
[web] Recompile tooltip fix

GitOrigin-RevId: da3282b9da0133f5b6ec84c4453bd6ab19b739af
2023-03-01 09:02:53 +00:00

51 lines
1.2 KiB
TypeScript

import { cloneElement } from 'react'
import {
OverlayTrigger,
OverlayTriggerProps,
Tooltip as BSTooltip,
} from 'react-bootstrap'
import { callFnsInSequence } from '../../utils/functions'
type OverlayProps = Omit<OverlayTriggerProps, 'overlay'> & {
shouldUpdatePosition?: boolean // Not officially documented https://stackoverflow.com/a/43138470
}
export type TooltipProps = {
description: React.ReactNode
id: string
overlayProps?: OverlayProps
tooltipProps?: BSTooltip.TooltipProps
children: React.ReactElement
}
function Tooltip({
id,
description,
children,
tooltipProps,
overlayProps,
}: TooltipProps) {
const hideTooltip = (e: React.MouseEvent) => {
if (e.currentTarget instanceof HTMLElement) {
e.currentTarget.blur()
}
}
return (
<OverlayTrigger
overlay={
<BSTooltip id={`${id}-tooltip`} {...tooltipProps}>
{description}
</BSTooltip>
}
{...overlayProps}
placement={overlayProps?.placement || 'top'}
>
{cloneElement(children, {
onClick: callFnsInSequence(children.props.onClick, hideTooltip),
})}
</OverlayTrigger>
)
}
export default Tooltip