@atlaskit/tooltip
Version:
A tooltip briefly describes an interactive element on mouse hover or keyboard focus.
48 lines (47 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getVirtualElementFromMousePos = getVirtualElementFromMousePos;
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));
}