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.

43 lines (35 loc) 1.59 kB
import { css } from "styled-components"; import { isHorizontal, isVertical } from "./isPosition"; import { isAlignCenter, isAlignEnd, isAlignStart } from "./isAlign"; import { TOOLTIP_ARROW_SIZE, TOOLTIP_PADDING } from "../consts"; // TODO: use tokens for 12px and 7px - paddings and sizeTooltipArrow var resolveTooltipArrowAlign = function resolveTooltipArrowAlign(_ref) { var position = _ref.position, align = _ref.align, tooltipWidth = _ref.tooltipWidth, tooltipHeight = _ref.tooltipHeight, _ref$customArrowAlign = _ref.customArrowAlign, customArrowAlign = _ref$customArrowAlign === void 0 ? 0 : _ref$customArrowAlign; if (isVertical(position)) { if (isAlignCenter(align)) { return css(["left:", "px;"], customArrowAlign || Math.floor(tooltipWidth / 2 - parseFloat(TOOLTIP_ARROW_SIZE))); } if (isAlignStart(align)) { return css(["left:", "px;"], customArrowAlign || parseFloat(TOOLTIP_PADDING)); } if (isAlignEnd(align)) { return css(["right:", "px;"], customArrowAlign || parseFloat(TOOLTIP_PADDING)); } } else if (isHorizontal(position)) { if (isAlignCenter(align)) { return css(["top:", "px;"], customArrowAlign || Math.floor(tooltipHeight / 2 - parseFloat(TOOLTIP_ARROW_SIZE))); } if (isAlignStart(align)) { return css(["top:", "px;"], customArrowAlign || parseFloat(TOOLTIP_PADDING)); } if (isAlignEnd(align)) { return css(["bottom:", "px;"], customArrowAlign || parseFloat(TOOLTIP_PADDING)); } } return null; }; export default resolveTooltipArrowAlign;