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.

44 lines (32 loc) 1.43 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 isInside = function isInside(p, canBe) { if (p === _consts.POSITIONS.TOP && canBe[p]) { return _consts.POSITIONS.TOP; } if (p === _consts.POSITIONS.BOTTOM && canBe[p]) { return _consts.POSITIONS.BOTTOM; } return false; }; var calculateVerticalPosition = function calculateVerticalPosition(desiredPositions, pos) { var _canBe; var canBe = (_canBe = {}, _defineProperty(_canBe, _consts.POSITIONS.TOP, pos.containerTop - pos.popoverHeight > pos.windowScrollTop), _defineProperty(_canBe, _consts.POSITIONS.BOTTOM, pos.containerTop - pos.windowScrollTop + pos.containerHeight + pos.popoverHeight < pos.windowHeight), _canBe); var possiblePositions = desiredPositions.map(function (p) { return isInside(p, canBe); }).filter(function (p) { return typeof p === "string"; }); // ordering in POSITIONS const is important var posPosition = possiblePositions[0]; if (typeof posPosition === "string") { return posPosition; } return _consts.POSITIONS.BOTTOM; }; var _default = calculateVerticalPosition; exports.default = _default;