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.

42 lines (32 loc) 1.69 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _consts = require("../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 = {}, (0, _defineProperty2.default)(_ref2, _consts.POSITIONS.LEFT, containerLeftPure - tooltipWidth - _consts.TOOLTIP_ARROW_SIZE > 0), (0, _defineProperty2.default)(_ref2, _consts.POSITIONS.RIGHT, containerLeftPure + containerWidth + tooltipWidth + _consts.TOOLTIP_ARROW_SIZE < windowWidth), (0, _defineProperty2.default)(_ref2, _consts.POSITIONS.TOP, containerTopPure - tooltipHeight > 0), (0, _defineProperty2.default)(_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;