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.

48 lines (35 loc) 1.64 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 isInside = function isInside(p, canBe) { if (p === _consts.ALIGNS.START && canBe[p]) { return _consts.ALIGNS.START; } if (p === _consts.ALIGNS.END && canBe[p]) { return _consts.ALIGNS.END; } if (p === _consts.ALIGNS.CENTER && canBe[p]) { return _consts.ALIGNS.CENTER; } return false; }; var calculateHorizontalPosition = function calculateHorizontalPosition(desiredAnchor, positions) { var _canBe; var canBe = (_canBe = {}, (0, _defineProperty2.default)(_canBe, _consts.ALIGNS.START, positions.containerLeft + positions.popoverWidth < positions.windowWidth), (0, _defineProperty2.default)(_canBe, _consts.ALIGNS.END, positions.containerLeft + positions.containerWidth >= positions.popoverWidth), (0, _defineProperty2.default)(_canBe, _consts.ALIGNS.CENTER, positions.containerLeft + positions.containerWidth / 2 - positions.popoverWidth / 2 > 0 && positions.containerLeft + positions.containerWidth / 2 + positions.popoverWidth / 2 < positions.windowWidth), _canBe); var possibleAnchor = desiredAnchor.map(function (p) { return isInside(p, canBe); }).filter(function (p) { return typeof p === "string"; }); if (possibleAnchor[0]) { return possibleAnchor[0]; } return null; }; var _default = calculateHorizontalPosition; exports.default = _default;