@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.
49 lines (42 loc) • 1.12 kB
JavaScript
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 "";
};
// TODO: kinda weird, but it's well known problem in flow with Object.entries
export const normalize = object => ({
theme
}) => {
if (!object) return null;
return Object.entries(object).reduce((acc, [key, val]) => {
if (key === "justify") {
return [...acc, formatCSS("justify-content", getJustify(val))];
}
if (key === "align") {
return [...acc, formatCSS("align-items", getAlign(val))];
}
if (key === "spacing") {
return [...acc, normalizeSpacing(val, theme)];
}
if (val) {
return [...acc, formatCSS(key, val)];
}
return acc;
}, []);
};