@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.
43 lines (32 loc) • 1.33 kB
JavaScript
;
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.ALIGNS.START && canBe[p]) {
return _consts.ALIGNS.START;
}
if (p === _consts.ALIGNS.END && canBe[p]) {
return _consts.ALIGNS.END;
}
return false;
};
var calculateHorizontalPosition = function calculateHorizontalPosition(desiredAnchor, positions) {
var _canBe;
var canBe = (_canBe = {}, _defineProperty(_canBe, _consts.ALIGNS.START, positions.containerLeft + positions.popoverWidth < positions.windowWidth), _defineProperty(_canBe, _consts.ALIGNS.END, positions.containerLeft + positions.containerWidth >= positions.popoverWidth), _canBe);
var possibleAnchor = desiredAnchor.map(function (p) {
return isInside(p, canBe);
}).filter(function (p) {
return typeof p === "string";
});
var posAnchor = possibleAnchor[0];
if (typeof posAnchor === "string") {
return posAnchor;
}
return null;
};
var _default = calculateHorizontalPosition;
exports.default = _default;