@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.
23 lines (21 loc) • 1.06 kB
JavaScript
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
*/
const autoPlacement = (childrenCount, columns, rows, columnGap, rowGap) => {
const columnsCount = realCellsCount(!!columnGap, lengthOf(columns));
const rowsCount = realCellsCount(!!rowGap, lengthOf(rows));
return Array(...Array(childrenCount)).map((_, i) => {
const index = i + 1;
const columnIndex = calculateColumnPlacement(index, columnsCount);
const 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;