The `usePopover` hook can help you position an overlay popover relative to the trigger element. You can use it to create tooltips, popovers, and other overlays.
npm i -S react-overlay-trigger
import React from 'react'
import { usePopover } from 'react-overlay-trigger'
const Popover = ({ style, ...rest }) => <span {...rest}>{children}</span>
const { popover, triggerProps } = usePopover(Popover, {
placement: 'right',
clickToggle: true,
})
return (
<>
{popover}
<button {...triggerProps}>click</button>
</>
)
const { popover, triggerProps } = usePopover(Dialog, {
placement: 'right',
clickToggle: true,
})
return (
<>
{popover}
<button {...triggerProps}>click to toggle tips</button>
</>
)
function Tooltip({style, onClose, ...props}, ref) {
return (
<div>
<div>Tooltip content....</div>
<button onClick={onClose}>close</button>
</div>
)
}
const { popover, triggerProps } = usePopover(Dialog, {
placement="top"
toggleHover: true,
toggleFocus: true,
})
return (
<>
{popover}
<button {...triggerProps}>click to open dialog</button>
</>
)
function Dialog({style, onClose, ...props}, ref) {
return (
<div>
<div>Dialog content....</div>
<button onClick={onClose}>close</button>
</div>
)
}
const { popover, triggerProps } = usePopover(Dialog, {
placement: 'center',
clickToggle: true,
})
return (
<>
{popover}
<button {...triggerProps}>click to open dialog</button>
</>
)