@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
31 lines (25 loc) • 1.36 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { POSITIONS, TOOLTIP_ARROW_SIZE } from "../consts";
var getPossiblePositions = function getPossiblePositions(_ref) {
var _ref2;
var containerTopPure = _ref.containerTopPure,
containerLeftPure = _ref.containerLeftPure,
containerHeight = _ref.containerHeight,
containerWidth = _ref.containerWidth,
tooltipWidth = _ref.tooltipWidth,
tooltipHeight = _ref.tooltipHeight,
windowWidth = _ref.windowWidth,
windowHeight = _ref.windowHeight;
return _ref2 = {}, _defineProperty(_ref2, POSITIONS.LEFT, containerLeftPure - tooltipWidth - TOOLTIP_ARROW_SIZE > 0), _defineProperty(_ref2, POSITIONS.RIGHT, containerLeftPure + containerWidth + tooltipWidth + TOOLTIP_ARROW_SIZE < windowWidth), _defineProperty(_ref2, POSITIONS.TOP, containerTopPure - tooltipHeight > 0), _defineProperty(_ref2, POSITIONS.BOTTOM, containerTopPure + containerHeight + tooltipHeight < windowHeight), _ref2;
};
var calculateTooltipPosition = function calculateTooltipPosition(positions, dimensions) {
var possiblePositions = getPossiblePositions(dimensions);
var position = positions.find(function (p) {
return possiblePositions[p];
});
if (typeof position === "string") {
return position;
}
return null;
};
export default calculateTooltipPosition;