Personal-site/components/Layout.js

30 lines
722 B
JavaScript
Raw Normal View History

2020-06-14 11:47:02 +00:00
import React from "react";
import PropTypes from "prop-types";
import styles from "./modules/Layout.module.css";
export default function Layout(props) {
const childrenArray = React.Children.toArray(props.children);
let gridItems = [];
let otherChild = [];
for (let i in childrenArray) {
if (i <= 1) {
gridItems.push(childrenArray[i]);
} else {
otherChild.push(childrenArray[i]);
}
}
return (
<div className={styles.grid}>
<div className={styles.gridItem}>{gridItems[0]}</div>
<div className={`${styles.gridItem} ${styles.darkbg}`}>
{gridItems[1]}
</div>
{otherChild}
</div>
);
}
Layout.propTypes = {
children: PropTypes.node.isRequired,
};