diff --git a/src/components/LayoutSingleColumn/LayoutSingleColumn.css b/src/components/LayoutSingleColumn/LayoutSingleColumn.css new file mode 100644 index 00000000..be8e54a1 --- /dev/null +++ b/src/components/LayoutSingleColumn/LayoutSingleColumn.css @@ -0,0 +1,18 @@ +@import '../../marketplace.css'; + +.root { + display: flex; + flex-direction: column; + min-height: 100vh; +} + +.layoutWrapperMain { + /* Use all available space parent element (aka root) can give */ + flex-grow: 1; + + /* Expand to the full remaining width of the viewport */ + display: flex; + flex-direction: column; + width: 100% + +} diff --git a/src/components/LayoutSingleColumn/LayoutSingleColumn.js b/src/components/LayoutSingleColumn/LayoutSingleColumn.js new file mode 100644 index 00000000..9a162a40 --- /dev/null +++ b/src/components/LayoutSingleColumn/LayoutSingleColumn.js @@ -0,0 +1,73 @@ +/** + * LayoutSingleColumn needs to have 3-4 children: + * LayoutWrapperTopbar, LayoutWrapperSideNav, LayoutWrapperMain, and possibly LayoutWrapperFooter. + */ +import React from 'react'; +import PropTypes from 'prop-types'; +import classNames from 'classnames'; +import { LayoutWrapperTopbar, LayoutWrapperMain, LayoutWrapperFooter } from '../../components'; + +import css from './LayoutSingleColumn.css'; + +const prepareChildren = children => { + const childrenCount = React.Children.count(children); + if (!(childrenCount === 3 || childrenCount === 4)) { + throw new Error( + `Menu needs to have 2 - 3 children: + LayoutWrapperTopbar, and LayoutWrapperMain, + and optionally LayoutWrapperFooter.` + ); + } + + const childrenMap = {}; + + React.Children.forEach(children, child => { + if (child.type === LayoutWrapperTopbar) { + childrenMap.layoutWrapperTopbar = child; + } else if (child.type === LayoutWrapperMain) { + // LayoutWrapperMain needs different rootClassName + const childWithAddedCSS = React.cloneElement(child, { + rootClassName: css.layoutWrapperMain, + }); + childrenMap.layoutWrapperMain = childWithAddedCSS; + } else if (child.type === LayoutWrapperFooter) { + childrenMap.layoutWrapperFooter = child; + } else { + throw new Error( + `LayoutSingleColumn has an unknown child. + Only LayoutWrapperTopbar, LayoutWrapperMain, LayoutWrapperFooter are allowed.` + ); + } + }); + return childrenMap; +}; + +const LayoutSingleColumn = props => { + const { className, rootClassName, children } = props; + const preparedChildren = prepareChildren(children); + const classes = classNames(rootClassName || css.root, className); + const maybeFooter = preparedChildren.layoutWrapperFooter || null; + + return ( +