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.

67 lines (49 loc) 2.15 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.normalize = exports.normalizeSpacing = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _rtl = require("../utils/rtl"); var _layout = require("../utils/layout"); var _consts = require("../utils/layout/consts"); var normalizeSpacing = function normalizeSpacing(el, theme) { var tokens = (0, _consts.TOKENS)(theme); if (el !== "none") { return "\n margin-".concat((0, _rtl.left)({ theme: theme }), ": -").concat(tokens[el], ";\n margin-top: -").concat(tokens[el], ";\n\n & > * {\n margin-").concat((0, _rtl.left)({ theme: theme }), ": ").concat(tokens[el], ";\n margin-top: ").concat(tokens[el], ";\n }\n "); } return ""; }; exports.normalizeSpacing = normalizeSpacing; // TODO: kinda weird, but it's well known problem in flow with Object.entries 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 = (0, _slicedToArray2.default)(_ref2, 2), key = _ref3[0], val = _ref3[1]; if (key === "justify") { return [].concat((0, _toConsumableArray2.default)(acc), [(0, _layout.formatCSS)("justify-content", (0, _layout.getJustify)(val))]); } if (key === "align") { return [].concat((0, _toConsumableArray2.default)(acc), [(0, _layout.formatCSS)("align-items", (0, _layout.getAlign)(val))]); } if (key === "spacing") { return [].concat((0, _toConsumableArray2.default)(acc), [normalizeSpacing(val, theme)]); } if (val) { return [].concat((0, _toConsumableArray2.default)(acc), [(0, _layout.formatCSS)(key, val)]); } return acc; }, []); }; }; exports.normalize = normalize;