@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.
51 lines (40 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _styledComponents = require("styled-components");
var _isPosition = require("./isPosition");
var _consts = require("../consts");
var resolveContainerPosition = function resolveContainerPosition(_ref) {
var position = _ref.position,
containerTop = _ref.containerTop,
containerLeft = _ref.containerLeft,
containerHeight = _ref.containerHeight,
containerWidth = _ref.containerWidth,
tooltipHeight = _ref.tooltipHeight,
contentHeight = _ref.contentHeight,
tooltipWidth = _ref.tooltipWidth,
theme = _ref.theme;
if ((0, _isPosition.isPositionTop)(position)) {
/*
Needed, otherwise the top position is incorrectly positioned due to missing 8 pixels.
It's produced by tooltipPadding.js helper that changes the padding based on the actual height -
if it's one-line or multi-line.
*/
var isMultiline = contentHeight > Math.floor(parseFloat(theme.orbit.lineHeightTextNormal));
return (0, _styledComponents.css)(["top:", "px;"], Math.floor(containerTop - tooltipHeight - parseFloat(_consts.TOOLTIP_ARROW_SIZE) - (isMultiline ? 8 : 0)));
}
if ((0, _isPosition.isPositionBottom)(position)) {
return (0, _styledComponents.css)(["top:", "px;"], Math.floor(containerTop + containerHeight + parseFloat(_consts.TOOLTIP_ARROW_SIZE)));
}
if ((0, _isPosition.isPositionRight)(position)) {
return (0, _styledComponents.css)(["left:", "px;"], Math.floor(containerLeft + containerWidth + parseFloat(_consts.TOOLTIP_ARROW_SIZE)));
}
if ((0, _isPosition.isPositionLeft)(position)) {
return (0, _styledComponents.css)(["left:", "px;"], Math.floor(containerLeft - tooltipWidth - parseFloat(_consts.TOOLTIP_ARROW_SIZE)));
}
return null;
};
var _default = resolveContainerPosition;
exports.default = _default;