grid = ({ gridSideLength, cellSize, children }) => {
const cells = new Array(gridSideLength ** 2).fill().map((_, i) => {
const x = i % gridSideLength * cellSize;
const y = Math.floor(i / gridSideLength) * cellSize;
return (
svg`
<g transform="translate(${x}, ${y})">
<rect
x="${padding}"
y="${padding}"
height="${cellSize - padding * 2}"
width="${cellSize - padding * 2}"
fill="#ffffff"
stroke="steelblue"
/>
${children({ gridSideLength, cellSize })()}
</g>
`
);
});
const width = cellSize * gridSideLength;
const height = cellSize * gridSideLength;
return (
svg`
<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
${cells}
</svg>
`
)
};