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.

35 lines (34 loc) 998 B
import { left } from "../utils/rtl"; import { getAlign, getJustify, formatCSS } from "../utils/layout"; import { TOKENS } from "../utils/layout/consts"; export const normalizeSpacing = (el, theme) => { const tokens = TOKENS(theme); if (el !== "none") { return ` margin-${left({ theme })}: -${tokens[el]}; margin-top: -${tokens[el]}; & > * { margin-${left({ theme })}: ${tokens[el]}; margin-top: ${tokens[el]}; } `; } return ""; }; export const normalize = object => ({ theme }) => { if (!object) return null; return Object.keys(object).reduce((acc, key) => { const val = object[key]; if (key === "spacing") return [...acc, normalizeSpacing(val, theme)]; if (key === "justify") return [...acc, formatCSS("justify-content", getJustify(val))]; if (key === "align") return [...acc, formatCSS("align-items", getAlign(val))]; if (val) return [...acc, formatCSS(key, val)]; return acc; }, []); };