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.

48 lines (35 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _splitToWords = _interopRequireDefault(require("./splitToWords")); var _insertGap = _interopRequireDefault(require("./insertGap")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } /* This function is firstly converting "repeat(3, 1fr) 2fr" to plain format that is compatible with IE For simplicity, the IE compatible format "(1fr)[3]" for repeat is not used Also if gap is defined, it adds gap after each column/row */ var compatibleGridTemplate = function compatibleGridTemplate(cells, gap) { var cellsMap = (0, _splitToWords.default)(cells); var plainCells = cellsMap && cellsMap.map(function (item) { if (/repeat\((.*\))/g.test(item)) { var values = /repeat\((\d+),\s(.*\)?)\)/g.exec(item); return values && Array.apply(void 0, _toConsumableArray(Array(Number(values[1])))).map(function () { return values[2]; }).join(" "); } return item; }).join(" "); if (!gap) { return plainCells; } return (0, _insertGap.default)(plainCells, gap); }; var _default = compatibleGridTemplate; exports.default = _default;