Skip to content

Tracking: extend layout options in Gutenberg #39336

@ramonjd

Description

@ramonjd

This issue will track experimentation, discussion and other output in relation to the extension of Gutenberg's layout capabilities.

Prerequisites

There are some outstanding issues with the current layout implementation we should address as a priority:

The direction

Blocks may opt into Gutenberg’s experimental layout API through their individual block.json files, for example:

"__experimentalLayout": {
    "allowSwitching": false,
    "allowInheriting": false,
    "allowEditing": false,
    "default": {
        "type": "flex",
	"flexWrap": "nowrap"
    }
}

There are presently two layouts: flex and flow. The aim of this tracking issue is to explore approaches that will open up the ability to add and control advanced layouts with blocks that go beyond the block gap, or margin/padding controls.

In #33687 a"layout" is defined as:

a configuration you apply to a container block that changes how its inner blocks are aligned, and also impacts the behavior of these inner blocks (enable/disable some customization options).

The corresponding UI objective is to allow users to choose between a set of layouts and related options in the editor.

Current layout related PRs, issues and other background context

Earlier layout related drafts, experiments and WIPs

Future layout possibilities:

Future layout WIPs and experiments:

Why?

Gutenberg should widen the availability of default (and robust) layout options so that users can structure their sites in various ways.

Rather than provide a panacea for every layout problem, we could offer common patterns that appear, and have proved successful, in modern websites.

It would be preferable to provide an extensible system through which we could add future layouts as well.

Current work

There has been some preliminary discussion around how to refactor existing, and integrate new, layouts into Gutenberg in #38974. That discussion has since evolved into a proposal for a refactor of how the Layout support works in: #40875

So far, the work has been to target the current layout implementation and focussing on the means to register and output styles, while trying to take into account contemporary ideas and explorations surrounding the Style Engine.

The plates are still up in the air and spinning, but some concepts that folks are trying (or will have to try) to reconcile include:

  1. compatibility: layout rules should be portable across themes, and work well in modern devices/browsers
  2. theme.json schema: theme authors should be able to use JSON to determine the layout of their site and blocks.
  3. nomenclature: how layouts will "identify" themselves to the application and in the rendered content, their property names, element classnames and modifiers

What’s next (short term)

Continuation of the experimentation and research phase

With the following goals:

  • Standardize styles and classname generation for the layout support, reduce style duplication
  • General research, read Every Layouts and, if relevant, examine CSS design systems for inspiration
  • Experimentation, for example, what it would take to introduce many of the layouts from
  • Implement and test extensibility
  • Test backwards compatibility
  • Document findings
  • Define incremental tasks.

A further line of inquiry is to research how to provide layout options at the root and inner block level, that is, applying "layout" to a blocks container element (and therefore immediate first-level descendants) and targeting specific inner block "containers".

The relevance of the Style Engine

Integral to the refactor and addition of layout styles to Gutenberg is the Style Engine, which has thus far a few stated goals and many more hopes pinned upon it.

A distilled statement of these goals and hopes might be “to offer a consistent API for generating classnames and rendering CSS for blocks”.

In the context of layouts (and beyond), a centralized way to generate lean, consistent CSS and classnames is important to:

  • Reduce duplication of code, and maximize cacheability
  • Ensure internal and external uniformity and predictability.

One potential path forward is to explore centralising base layout styles output in global styles, and use a centralised set of definitions for the various layout types. This is being explored in #40875.

TODO

This is a short-list attempting to capture some incremental steps toward a centralised approach for outputting layout styles, instead of layout styles being applied one-at-a-time when each individual block is rendered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi[Feature] LayoutLayout block support, its UI controls, and style output.[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions