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.

24 lines (22 loc) 1.18 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import { css } from "styled-components"; import applyGap from "./applyGap"; import lengthOf from "./lengthOf"; import realCellsCount from "./realCellsCount"; import calculateColumnPlacement from "./calculateColumnPlacement"; import calculateRowPlacement from "./calculateRowPlacement"; /* This functions is applying a proper -ms-grid-column and -ms-grid-row as IE10+ can't resolve auto placement by itself natively */ var autoPlacement = function autoPlacement(childrenCount, columns, rows, columnGap, rowGap) { var columnsCount = realCellsCount(!!columnGap, lengthOf(columns)); var rowsCount = realCellsCount(!!rowGap, lengthOf(rows)); return Array.apply(void 0, _toConsumableArray(Array(childrenCount))).map(function (_, i) { var index = i + 1; var columnIndex = calculateColumnPlacement(index, columnsCount); var rowIndex = calculateRowPlacement(index, columnsCount, rowsCount); return css(["& > *:nth-child(", "){-ms-grid-column:", ";-ms-grid-row:", ";}"], index, applyGap(columnIndex, !!columnGap), applyGap(rowIndex, !!rowGap)); }); }; export default autoPlacement;