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.

64 lines (49 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalize = exports.normalizeSpacing = void 0; var _rtl = require("../utils/rtl"); var _layout = require("../utils/layout"); var _consts = require("../utils/layout/consts"); const normalizeSpacing = (el, theme) => { const tokens = (0, _consts.TOKENS)(theme); if (el !== "none") { return ` margin-${(0, _rtl.left)({ theme })}: -${tokens[el]}; margin-top: -${tokens[el]}; & > * { margin-${(0, _rtl.left)({ theme })}: ${tokens[el]}; margin-top: ${tokens[el]}; } `; } return ""; }; exports.normalizeSpacing = normalizeSpacing; // TODO: kinda weird, but it's well known problem in flow with Object.entries const normalize = object => ({ theme }) => { if (!object) return null; return Object.entries(object).reduce((acc, [key, val]) => { if (key === "justify") { return [...acc, (0, _layout.formatCSS)("justify-content", (0, _layout.getJustify)(val))]; } if (key === "align") { return [...acc, (0, _layout.formatCSS)("align-items", (0, _layout.getAlign)(val))]; } if (key === "spacing") { return [...acc, normalizeSpacing(val, theme)]; } if (val) { return [...acc, (0, _layout.formatCSS)(key, val)]; } return acc; }, []); }; exports.normalize = normalize;