Skip to content

Instantly share code, notes, and snippets.

@martinwairegi
Created July 5, 2022 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinwairegi/3e06e5632fe85cd95db6f787226e4253 to your computer and use it in GitHub Desktop.
Save martinwairegi/3e06e5632fe85cd95db6f787226e4253 to your computer and use it in GitHub Desktop.
// IMPORTS /////////////////////////////////////////////////////////////////////////
import React from "react";
import styled from "styled-components";
// Components
import GridBlock from "./GridBlock";
export default function Grid(props) {
const grid = props.grid;
const GridContainer = styled.div`
position: absolute;
left: 0px;
top 0px;
border: 5px solid white;
display: inline-block;
`;
const gridRows = [];
const GridRowContainer = styled.div`
display: flex;
`;
let blockKey = 0;
let gridRowKey = 0;
for (
let heightIndex = 0;
heightIndex < grid.height;
heightIndex++, gridRowKey++
) {
const gridRowBlocks = [];
for (
let widthIndex = 0;
widthIndex < grid.width;
widthIndex++, blockKey++
) {
gridRowBlocks[widthIndex] = (
<GridBlock
key={blockKey}
size={grid.blockSize}
color={grid.RGBs[widthIndex][heightIndex]}
/>
);
}
gridRows[heightIndex] = (
<GridRowContainer key={gridRowKey}>{gridRowBlocks}</GridRowContainer>
);
}
return <GridContainer>{gridRows}</GridContainer>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment