Skip to content

Flex Layout Iterations #33687

Closed
Closed

Description

@youknowriad

In #33359 we added the possibility for blocks to support multiple layouts: the default "flow" layout and the new "Flex" layout. In the future, we'll be also introducing other layouts like "Grid" or "Absolute positioning container"...

What is a layout?

A layout is 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). Right now, we have two types of "layouts" we can apply to container blocks:

  • Flow layout: This is the default behavior in HTML, meaning if you apply this to a container block, its children are rendered one after the other vertically without any specific CSS styles (it works just like adding divs inside divs). Blocks inside a flow container can be left/right aligned (float) and in this type of layout, you have the possibility to define a "content size" and a "wide size", by defining these, the inner blocks get centered by default inside the "content size" area and they receive new alignments options (full/wide alignments)

  • Flex layout: This is a layout where the container receives a display: flex style. Right now it's opinionated, meaning the inner blocks are positioned horizontally one after the other with a small gap between each block. No alignment options are available for inner blocks inside a "flex container". That said, it is likely that we'll be introducing a number of customizations for this kind of layout. For instance, we could add a config to choose whether the blocks are horizontal or vertical (some argued that flex should be only used for horizontal alignments but it's something we should discuss more). Another option could be the "gap" size, align-items could also be a config option for the layout itself. For the children of this particular layout, we could potentially explore adding positioning tools (like align-self and such).

Layout switching

Generic container blocks like the group are most likely going to require a layout switcher UI to allow users to switch layouts and configure its specific options.

Right now, the initial prototype from #33359 contains a very basic undesigned layout switcher that you can enable by replacing this line with:

"__experimentalLayout": {
	"allowSwitching": true
}

You'll get something like:

125345906-1aee8100-e327-11eb-8d48-95ddf1386281

This area is going to require a better design/wording...

Refactoring blocks to use declarative layouts

Historically, we've added a number of flex horizontal container blocks over time like: Social Links, Buttons, Columns and Navigation blocks. But we did so in a very ad-hoc way, meaning we just added custom CSS and custom customization options to these blocks. Now that we introduced the "layout" config and the "flex layouts", we should consider refactoring some of these blocks to be more declarative and remove the specific treatment we have right now for these blocks.

One technical issue that needs solving though to do that is that right now, the layout block support renders styles in the editor by using the __experimentalLayout prop of the userInnerBlocksProps call, but in frontend it relies on the layout block attribute. For the editor, the current APIs should be enough but for the frontend, these blocks might not allow users to tweak their "layout", meaning the layout attribute might or might not be necessary. We need to find a declarative way in block.json to define the "default layout" of a container block.

Todo List

In terms of design, we need a couple of explorations:

  • Design a good layout switcher.
  • What customization options are going to be needed for the Flex layout. Design the flex container config panel.
  • Should we allow align-self positioning tools for children of flex containers? How to surface these?

In terms of architecture:

  • Refactoring existing horizontal blocks to use the new flex layout.
  • Write some architecture documentation for contributors about the layout and layout types.

Activity

  1. added
    Customization
    [Feature] Design Tools
    Needs Design
    on Jul 26, 2021
  2. mtias commented on Jul 27, 2021

    @mtias
    Member

    Do we need to establish some criteria for when Flex is better over Grid?

  3. youknowriad commented on Jul 28, 2021

    @youknowriad
    ContributorAuthor

    I didn't think much about the Grid layout yet but it seems that "Flex" is easier/simpler when it comes to basic vertical blocks (social icons, navigation, buttons) but Grid would be a better choice for "page layouts", so an option on a generic container/group block (or variation) that you apply at the top level of your template.

    I think what we're missing right now to start exploring Grid, is better understanding/exploration on what needs to be configured at the container level and what alignment/config options to expose on the child blocks. Maybe @jasmussen could help with that a bit. I think we could use a separate issue about the Grid layout to answer these questions:

    • When I apply a "grid" layout to a block, what config options can I have on that block?
    • What config options I have on its children?
    • How does a "grid" layout impact the UI and possible interactions on the inner blocks?
    • Potentially some design mockups about the questions above.
  4. mtias commented on Jul 28, 2021

    @mtias
    Member

    I think the important aspect is that it's not just a different layout property and it's more about who has more control, the parent block or the child blocks when laying things out. And that's something we should take into account early on since it can dictate the kind of tools that get exposed and where (in the container toolbar/inspector or the children toolbar/inspector). Also relevant.

  5. richtabor commented on Sep 5, 2021

    @richtabor
    Member

    I riffed on some ideas as part of a big-picture proposal for the Group block's layout panel. Thoughts? #34558

  6. moved this to ⏱ Not Started in Design Tools Projecton Jan 26, 2022
  7. moved this from ⏱ Not Started to ⏳ In Progress in Design Tools Projecton Jan 26, 2022
  8. moved this from ⏳ In Progress to 🔺 Stale in Design Tools Projecton Feb 2, 2022
  9. mtias commented on Apr 10, 2022

    @mtias
    Member

    @youknowriad where do you think we stand with this one after the latest work on Row, Stack and the transforms menu like #40036 ?

  10. youknowriad commented on Apr 11, 2022

    @youknowriad
    ContributorAuthor

    I think in terms of features for the flex layout itself, we're mostly there. Maybe the only potential addition could be this:

    Should we allow align-self positioning tools for children of flex containers? How to surface these?

    Similar to how "alignments" appear when you chose a "flex" layout for the container, specific flex alignment options could appear in child blocks when you select "flex" as their container.

    That said there are a number of issues in terms of "architecture". Right now, some blocks have "align" block support which only works if container is "flow" and it works by adding an "align" attribute to the block. There are several things we should improve here:

    • "align" is not a reserved attribute name and the framework (block-editor) don't really know anything about it. Some blocks might implement the same behavior using a different attribute.
    • "align" is also not something that translates well in all kind of layouts, I'd love for that attribute to be named something like "position" (or maybe "_position" to avoid collisions with existing third-party attributes) and be understood by the framework. The attribute could store the "alignment" in case of a "flow" parent, and when you move the block to another container that is "flex", it should reset itself. In other words, the "position" attribute only make sense in the context of a given layout container. I hope that makes sense. That said It's also fine to track this separately as it's a tangent here.
  11. jasmussen commented on Apr 11, 2022

    @jasmussen
    Contributor

    One small addition is to consider a matrix-grid like alignment tool, a la what the Cover block has already, for flex containers that allow both vertical and horizontal alignments. Probably worth its own separte issue?

  12. mtias commented on Apr 11, 2022

    @mtias
    Member

    For self-positioning?

  13. jasmussen commented on Apr 11, 2022

    @jasmussen
    Contributor

    Row now has both horizontal and vertical alignments for children in the block toolbar, but not in the inspector:

    Screenshot 2022-04-11 at 11 36 59

    We could potentially use the same interface the Cover block has for aligning. Instead of setting horizontal and vertical separately, it can be a single 9-cell matrix.

  14. youknowriad commented on Apr 11, 2022

    @youknowriad
    ContributorAuthor

    @jasmussen I'm not sure that interface make sense. What's "center": "justify center" or "space between"?

  15. jasmussen commented on Apr 11, 2022

    @jasmussen
    Contributor

    This is how Figma handles it:
    figma

    I recognize the dropdown to choose between "packed" and "space between" isn't the most intuitive. Mostly it's the discrepancy between the vertical tools being available in the block toolbar, but not in the inspector, and if we add them to the inspector as well, we should try to avoid this:

    to avoid

    One alternative is to also have dropdowns in the inspector:
    Alternative

    That just doesn't feel quite as natural as the behavior that exists for Cover, though. 🤔

  16. mtias commented on Apr 11, 2022

    @mtias
    Member

    I was talking about self-align, though — so you can place something at the top of a cover, something else at the bottom, etc, which is not possible with the matrix control on the parent.

  17. jasmussen commented on Apr 11, 2022

    @jasmussen
    Contributor

    Depending on how many of the flex properties we want to support, it can quickly become a lot. Two options:
    One idea

  18. youknowriad commented on Apr 11, 2022

    @youknowriad
    ContributorAuthor

    @jasmussen orientation doesn't make sense for individual blocks inside a container, justify might not make sense either.

  19. jasmussen commented on Apr 11, 2022

    @jasmussen
    Contributor

    Right of course, so potentially this; layout container:
    Container

    Inner block, with justification shown or hidden depending on the block:

    Inner block

    Something like that for a start?

  20. youknowriad commented on Apr 11, 2022

    @youknowriad
    ContributorAuthor

    Yes, I also wonder if it should be on the toolbar. Conceptually it's the alternative to "align left/right/wide/full" that we have for children of "flow" layouts.

  21. jasmussen commented on Apr 11, 2022

    @jasmussen
    Contributor

    Good point, and it illustrates a challenge with the iconography. When the justification icons are used both for inner blocks, and for self, it becomes unclear what they apply to.

    I don't like the following icons, consider them placeholders to illustrate how "align self" icons might need to be different from "justify content" icons. Potentially we keep the group block toolbar simple:
    Container group

    And then you're suggesting some new align-self options in inspector and block toolbar for inner groups, right? Perhaps something like this:

    Inner group

  22. moved this from 🔺 Stale to ⏳ In Progress in Design Tools Projecton Apr 25, 2022
  23. mtias commented on May 23, 2022

    @mtias
    Member

    @youknowriad do you see anything pending here? I think maybe some of the self-align options, which also overlap with the matrix control, but I think it'd be better to extract that into a separate issue. I feel the core work is done here.

  24. youknowriad commented on May 23, 2022

    @youknowriad
    ContributorAuthor

    @mtias 👍 Let's close and do a separate one about self align.

  25. Repository owner moved this from ⏳ In Progress to ✅ Done in Design Tools Projecton May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CustomizationNeeds Design[Feature] Design Tools

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions