UNPKG

@atlaskit/tooltip

Version:

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

42 lines 1.18 kB
export function getVirtualElementFromMousePos(mousePos, _ref) { var targetElement = _ref.targetElement, tooltipPosition = _ref.tooltipPosition; if (tooltipPosition === 'mouse') { return { getBoundingClientRect: function getBoundingClientRect() { return DOMRect.fromRect({ x: mousePos.clientX, y: mousePos.clientY, width: 0, height: 0 }); } }; } var targetRect = targetElement.getBoundingClientRect(); if (tooltipPosition === 'mouse-x') { return { getBoundingClientRect: function getBoundingClientRect() { return DOMRect.fromRect({ x: mousePos.clientX, y: targetRect.top, width: 0, height: targetRect.height }); } }; } if (tooltipPosition === 'mouse-y') { return { getBoundingClientRect: function getBoundingClientRect() { return DOMRect.fromRect({ x: targetRect.left, y: mousePos.clientY, width: targetRect.width, height: 0 }); } }; } throw new Error("Invalid tooltip position for virtual element: ".concat(tooltipPosition)); }