UNPKG

@atlaskit/tooltip

Version:

A tooltip briefly describes an interactive element on mouse hover or keyboard focus.

37 lines 932 B
export function getVirtualElementFromMousePos(mousePos, { targetElement, tooltipPosition }) { if (tooltipPosition === 'mouse') { return { getBoundingClientRect: () => DOMRect.fromRect({ x: mousePos.clientX, y: mousePos.clientY, width: 0, height: 0 }) }; } const targetRect = targetElement.getBoundingClientRect(); if (tooltipPosition === 'mouse-x') { return { getBoundingClientRect: () => DOMRect.fromRect({ x: mousePos.clientX, y: targetRect.top, width: 0, height: targetRect.height }) }; } if (tooltipPosition === 'mouse-y') { return { getBoundingClientRect: () => DOMRect.fromRect({ x: targetRect.left, y: mousePos.clientY, width: targetRect.width, height: 0 }) }; } throw new Error(`Invalid tooltip position for virtual element: ${tooltipPosition}`); }