UNPKG

@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.

40 lines (31 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _consts = require("../consts"); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } 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, _consts.POSITIONS.LEFT, containerLeftPure - tooltipWidth - _consts.TOOLTIP_ARROW_SIZE > 0), _defineProperty(_ref2, _consts.POSITIONS.RIGHT, containerLeftPure + containerWidth + tooltipWidth + _consts.TOOLTIP_ARROW_SIZE < windowWidth), _defineProperty(_ref2, _consts.POSITIONS.TOP, containerTopPure - tooltipHeight > 0), _defineProperty(_ref2, _consts.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; }; var _default = calculateTooltipPosition; exports.default = _default;