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.

36 lines (34 loc) 1.21 kB
import { ALIGNS, JUSTIFY, DIRECTIONS } from "./consts"; export const isDefined = prop => typeof prop !== "undefined"; const evaluateProp = (prop, positive, negative) => { if (isDefined(prop)) return prop ? positive : negative; return ""; }; export const formatCSS = (key, value) => `${key}: ${value};`; export const getAlign = align => { const tokens = { [ALIGNS.START]: "flex-start", [ALIGNS.END]: "flex-end", [ALIGNS.CENTER]: "center", [ALIGNS.STRETCH]: "stretch", [ALIGNS.BASELINE]: "baseline" }; return align && tokens[align]; }; export const getJustify = justify => { const tokens = { [JUSTIFY.START]: "flex-start", [JUSTIFY.END]: "flex-end", [JUSTIFY.CENTER]: "center", [JUSTIFY.BETWEEN]: "space-between", [JUSTIFY.AROUND]: "space-around" }; return justify && tokens[justify]; }; export const getDirection = direction => { if (!direction) return ""; return Object.values(DIRECTIONS).indexOf(direction) !== -1 ? direction : DIRECTIONS.ROW; }; export const getGrow = grow => evaluateProp(grow, "1", "0"); export const getShrink = shrink => evaluateProp(shrink, "1", "0"); export const getWrap = wrap => evaluateProp(wrap, "wrap", "nowrap");