Hi everyone!
We’ve had discussions with many of you about building a new Grid element powered by the CSS grid spec. This topic is both a status update, and an invitation to discuss the progress to-date. Because of time contraints, we’ve moved forward with beta testing even though this element has not been completed.
General Considerations
- We’re trying to build a CSS grid spec powered Element allowing you add and manage cells within that grid and use it as a basis for you page layouts.
- CSS Grid is incredibly powerful and allows for complex layouts. We’re trying to strike the right balance of providing access to that power, while providing the most approachable user experience.
- Nothing mentioned here is finalized. We just wanted to provide a development update on the element and get your feedback in a few areas.
Behavior
- You can add a Grid element by dragging it in from the library. It will also be an option under the “Content Layout Element” preference which turns it into the default child of newly created sections.
- Once a Grid is added, in the preview you will see “Choose a Grid Preset” (similar to the new Row element) along with a list of several starting points with varying degrees of complexity.
- Choosing a preset will add the correct number of cells, and preconfigure everything to have a nice looking grid at all breakpoints.
- You can inspect the Grid element, or the individual Cell elements and change their appearance
- Cells are similar to the existing Column and Container elements. They support drag and drop for child elements.
- Per the CSS spec, there are two layers to consider. First, Grids must have a “Template” (we’ll also refer to this as the “Grid tracks”) which determines the valid locations where cells can be placed. The second is the cells themselves which sit inside the template.
- The Grid template will be customizable at every breakpoint.
- If you stick to the included presets, you won’t need to learn the CSS grid specification.
- If you want to make your own grids, or heavily customize the presets you will need to have an understanding of how CSS grids work.
Progress
The first screenshot shows Inspecting the Grid element we are currently working with. Notice how we have six cells, and the Column Template has three values, and the Row Template is auto
. These templates are directly piped into the generated styles.
The three Column Template The 150px
means the first column is always 150px. The 1fr
units to follow mean the next to columns should be 1 fractional unit each - essentially it means make 2 more columns to fill the remaining space. By setting a single row to auto
it tell the grid to repeat the same column arrangement over and over.
By default all cells will flow into the next available position in the grid tracks. But by inspecting the cells you can override the cell coordinates.
You can also change how the Cell’s DOM element is aligned to the track. For example, we could make the first cell span multiple rows and delete the 6th cell. Now we have a fixed 150px sidebar, and four variable width cells that fill the rest of the screen.
As you can already tell, this setup allows for a great deal of power when laying out grids, but does lean a bit heavier into assuming you know how Grids work under the hood. To alleviate this, we’ve been working on UI that can be turned on as an overlay in the preview area. You would still need to setup the grid templates (handled automatically by the preset chosen initially) but you would be able to control cell placement and sizing.
Challenges
The biggest challenge we’ve encountered, and the primary reason for excluding this element from the beta is the drag/drop interface. It is incredibly complicated to manage the underlying grid tracks, allow cells to be moved around with drag/drop while also maintaining an accurate visual preview. We’ve not ruled out the possibility, it will just take more time to get it right.
Feedback
- How do you feel about the overall approach?
- Do you feel like any key functionality to an element of this nature has gone unrepresented?
- Are there any grid presets that come to mind that you feel would be useful options out of the box?