UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

49 lines 1.4 kB
import * as React from 'react'; import { mergeReactProps } from '../../utils/mergeReactProps.js'; import { useAnchorPositioning } from '../../utils/useAnchorPositioning.js'; import { useTooltipRootContext } from '../root/TooltipRootContext.js'; export function useTooltipPositioner(params) { const { keepMounted, mounted } = params; const { open, trackCursorAxis } = useTooltipRootContext(); const { positionerStyles, arrowStyles, anchorHidden, arrowRef, arrowUncentered, renderedSide, renderedAlign } = useAnchorPositioning(params); const getPositionerProps = React.useCallback((externalProps = {}) => { const hiddenStyles = {}; if (keepMounted && !open) { hiddenStyles.pointerEvents = 'none'; } if (trackCursorAxis === 'both') { hiddenStyles.pointerEvents = 'none'; } return mergeReactProps(externalProps, { role: 'presentation', hidden: !mounted, style: { ...positionerStyles, ...hiddenStyles } }); }, [keepMounted, open, trackCursorAxis, mounted, positionerStyles]); return React.useMemo(() => ({ getPositionerProps, arrowStyles, arrowRef, arrowUncentered, side: renderedSide, align: renderedAlign, anchorHidden }), [getPositionerProps, arrowStyles, arrowRef, arrowUncentered, renderedSide, renderedAlign, anchorHidden]); }