@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.
66 lines (47 loc) • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getWrap = exports.getShrink = exports.getGrow = exports.getDirection = exports.getJustify = exports.getAlign = exports.formatCSS = exports.isDefined = void 0;
var _consts = require("./consts");
const isDefined = prop => typeof prop !== "undefined";
exports.isDefined = isDefined;
const evaluateProp = (prop, positive, negative) => {
if (isDefined(prop)) return prop ? positive : negative;
return "";
};
const formatCSS = (key, value) => `${key}: ${value};`;
exports.formatCSS = formatCSS;
const getAlign = align => {
const tokens = {
[_consts.ALIGNS.START]: "flex-start",
[_consts.ALIGNS.END]: "flex-end",
[_consts.ALIGNS.CENTER]: "center",
[_consts.ALIGNS.STRETCH]: "stretch",
[_consts.ALIGNS.BASELINE]: "baseline"
};
return align && tokens[align];
};
exports.getAlign = getAlign;
const getJustify = justify => {
const tokens = {
[_consts.JUSTIFY.START]: "flex-start",
[_consts.JUSTIFY.END]: "flex-end",
[_consts.JUSTIFY.CENTER]: "center",
[_consts.JUSTIFY.BETWEEN]: "space-between",
[_consts.JUSTIFY.AROUND]: "space-around"
};
return justify && tokens[justify];
};
exports.getJustify = getJustify;
const getDirection = direction => {
if (!direction) return "";
return Object.values(_consts.DIRECTIONS).indexOf(direction) !== -1 ? direction : _consts.DIRECTIONS.ROW;
};
exports.getDirection = getDirection;
const getGrow = grow => evaluateProp(grow, "1", "0");
exports.getGrow = getGrow;
const getShrink = shrink => evaluateProp(shrink, "1", "0");
exports.getShrink = getShrink;
const getWrap = wrap => evaluateProp(wrap, "wrap", "nowrap");
exports.getWrap = getWrap;