@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.
41 lines (34 loc) • 1.64 kB
JavaScript
import { css } from "styled-components";
import { isPositionBottom, isPositionTop, isPositionRight, isPositionLeft } from "./isPosition";
import { TOOLTIP_ARROW_SIZE } from "../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 (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 css(["top:", "px;"], Math.floor(containerTop - tooltipHeight - parseFloat(TOOLTIP_ARROW_SIZE) - (isMultiline ? 8 : 0)));
}
if (isPositionBottom(position)) {
return css(["top:", "px;"], Math.floor(containerTop + containerHeight + parseFloat(TOOLTIP_ARROW_SIZE)));
}
if (isPositionRight(position)) {
return css(["left:", "px;"], Math.floor(containerLeft + containerWidth + parseFloat(TOOLTIP_ARROW_SIZE)));
}
if (isPositionLeft(position)) {
return css(["left:", "px;"], Math.floor(containerLeft - tooltipWidth - parseFloat(TOOLTIP_ARROW_SIZE)));
}
return null;
};
export default resolveContainerPosition;