@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.
37 lines (28 loc) • 1.28 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { ALIGNS } from "../consts";
var isInside = function isInside(p, canBe) {
if (p === ALIGNS.START && canBe[p]) {
return ALIGNS.START;
}
if (p === ALIGNS.END && canBe[p]) {
return ALIGNS.END;
}
if (p === ALIGNS.CENTER && canBe[p]) {
return ALIGNS.CENTER;
}
return false;
};
var calculateHorizontalPosition = function calculateHorizontalPosition(desiredAnchor, positions) {
var _canBe;
var canBe = (_canBe = {}, _defineProperty(_canBe, ALIGNS.START, positions.containerLeft + positions.popoverWidth < positions.windowWidth), _defineProperty(_canBe, ALIGNS.END, positions.containerLeft + positions.containerWidth >= positions.popoverWidth), _defineProperty(_canBe, 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;
};
export default calculateHorizontalPosition;