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.

48 lines (41 loc) 1.67 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import { left } from "../utils/rtl"; import { getAlign, getJustify, formatCSS } from "../utils/layout"; import { TOKENS } from "../utils/layout/consts"; export var normalizeSpacing = function normalizeSpacing(el, theme) { var tokens = TOKENS(theme); if (el !== "none") { return "\n margin-".concat(left({ theme: theme }), ": -").concat(tokens[el], ";\n margin-top: -").concat(tokens[el], ";\n\n & > * {\n margin-").concat(left({ theme: theme }), ": ").concat(tokens[el], ";\n margin-top: ").concat(tokens[el], ";\n }\n "); } return ""; }; // TODO: kinda weird, but it's well known problem in flow with Object.entries export var normalize = function normalize(object) { return function (_ref) { var theme = _ref.theme; if (!object) return null; return Object.entries(object).reduce(function (acc, _ref2) { var _ref3 = _slicedToArray(_ref2, 2), key = _ref3[0], val = _ref3[1]; if (key === "justify") { return [].concat(_toConsumableArray(acc), [formatCSS("justify-content", getJustify(val))]); } if (key === "align") { return [].concat(_toConsumableArray(acc), [formatCSS("align-items", getAlign(val))]); } if (key === "spacing") { return [].concat(_toConsumableArray(acc), [normalizeSpacing(val, theme)]); } if (val) { return [].concat(_toConsumableArray(acc), [formatCSS(key, val)]); } return acc; }, []); }; };