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.

46 lines (44 loc) 1.83 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; exports.__esModule = true; exports.default = void 0; var _styledComponents = require("styled-components"); var _getSpacing = _interopRequireDefault(require("./getSpacing")); var _getProperty = _interopRequireDefault(require("./getProperty")); var _rtl = require("../../utils/rtl"); var _consts = require("../../utils/layout/consts"); const getDirectionSpacingTemplate = direction => { switch (direction) { case _consts.DIRECTIONS.ROW: return "0 __spacing__ 0 0"; case _consts.DIRECTIONS.COLUMNREVERSE: return "__spacing__ 0 0 0"; case _consts.DIRECTIONS.ROWREVERSE: return "0 0 0 __spacing__"; default: return "0 0 __spacing__ 0"; } }; const getGap = ({ index, devices }) => props => { const spacing = (0, _getProperty.default)("spacing", { index, devices }, props); const direction = (0, _getProperty.default)("direction", { index, devices }, props); const gap = spacing && direction && (0, _getSpacing.default)(props.theme)[spacing]; const margin = spacing && direction && String(getDirectionSpacingTemplate(direction)).replace("__spacing__", (0, _getSpacing.default)(props.theme)[spacing]); // workaround to make it work on Safari iOS < 14.1 // TODO: remove that after dropping support for iOS < 14.1 if (props.flex) { return (0, _styledComponents.css)(["gap:", ";@supports (-webkit-touch-callout:none) and (not (translate:none)){& > *:not(:last-child){margin:", " !important;}}"], gap, margin && (0, _rtl.rtlSpacing)(margin)); } return (0, _styledComponents.css)(["& > *{margin:", "!important;&:last-child{margin:0 !important;}}"], margin && (0, _rtl.rtlSpacing)(margin)); }; var _default = getGap; exports.default = _default;