From #488, there was broad agreement in favour of a JSX-based API. I've started spiking a set of layout components.
Abandoning the Grid components
I have moved away from the existing Grid component API for a few reasons:
- The columns / spans abstraction is confusing and hard to remember. It expects the developer to know how many columns are available at each breakpoint.
- It provides an unnecessarily high granularity of control, making the API weighty for no good reason.
- The name "Grid" is confusing and means too many things.
- It tries (and fails) to be a one-stop solution for all layouts.
Layout spiking
A number of developers and designers have kindly shared layouts that they are currently working on. Over the last few days I've built a number of them, noting layout similarities and patterns.
- Checkout flow
- Consents flow
- Thank you flow
- Article on web
- Showcase in Editions
As a result of this spike, I've identified 5 new layout components that, when combined, can be used to build (nearly) all of these layouts.
- Container
- Stack
- Columns / Column
- Tiles
- Hide
This work has been greatly inspired by awesome open source component libraries such as Braid and Chakra-UI.
Container
<Container>
<article></article>
</Container>
The Container centres the page content and applies a width that corresponds to the grid at the current breakpoint.
Stack
<Stack>
<div></div>
<div></div>
<div></div>
</Stack>
Children will be stacked one on top of the other.
Columns / Column
<Columns>
<Column width={1/4}></Column>
<Column width={1/4}></Column>
<Column></Column>
</Columns>
Columns will be arranged side by side on a single row, with the specified width.
width
: If no value is provided, the column width will be fluid (i.e. take up remaining space, divided between all fluid columns).
Tiles
<Tiles columns={3}>
<div></div>
<div></div>
<div></div>
<div></div>
</Tiles>
Items will be arranged with equal width and spacing with the specified number of columns, wrapping onto a new row as necessary.
Hide
<Hide above="tablet">
<MobileNavigation />
</Hide>
<Hide below="desktop">
<DesktopNavigation />
</Hide>
Hide a component above or below a certain breakpoint
Request for comments
The exact API for each of these components is yet to be finalised. I'll request input for this, component-by-component at a later date.
I'd like to know whether this approach is something that would work for you and your team, and would solve most of your common layout issues? Also if you can think of any more components or abstractions that would be useful, please add them to this issue.