Skip to content

Commit

Permalink
feat(tooltip): add gutter prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mleralec committed Oct 11, 2023
1 parent 2bf26c0 commit 5248a35
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/Tooltip/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ export type TooltipOptions = {
children: React.ReactNode
content: string | JSX.Element
fixed?: boolean
} & Pick<Ariakit.TooltipStoreProps, 'placement'>
} & Pick<Ariakit.TooltipStoreProps, 'placement'> &
Pick<Ariakit.TooltipOptions, 'gutter'>

export type TooltipProps = CreateWuiProps<'div', TooltipOptions>

export const Tooltip = forwardRef<'div', TooltipProps>(
({ children, content, fixed = false, placement = fixed ? 'top' : 'bottom', ...rest }, ref) => {
const tooltip = Ariakit.useTooltipStore({ placement, animated: 300 })
(
{ children, content, fixed = false, placement = fixed ? 'top' : 'bottom', gutter = 8, ...rest },
ref
) => {
const tooltip = Ariakit.useTooltipStore({ placement, animated: true })
const [position, setPosition] = useState({ x: 0, y: 0 })
const getState = tooltip.getState
const render = tooltip.render
const { getState, render, stopAnimation } = tooltip

const updatePosition = () => {
const { mounted, popoverElement } = getState()
Expand Down Expand Up @@ -63,12 +66,14 @@ export const Tooltip = forwardRef<'div', TooltipProps>(
<>
<Ariakit.TooltipAnchor render={child as ReactElement} store={tooltip} />
<Ariakit.Tooltip
fixed={fixed}
gutter={gutter}
ref={ref}
render={<Box {...rest} />}
store={tooltip}
updatePosition={!fixed ? updatePosition : undefined}
>
<S.FadeIn fixed={fixed} placement={placement}>
<S.FadeIn fixed={fixed} onTransitionEnd={stopAnimation} placement={placement}>
{content}
</S.FadeIn>
</Ariakit.Tooltip>
Expand Down

0 comments on commit 5248a35

Please sign in to comment.