Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flex Layout Iterations #33687

Closed
3 of 5 tasks
Tracked by #33447
youknowriad opened this issue Jul 26, 2021 · 20 comments
Closed
3 of 5 tasks
Tracked by #33447

Flex Layout Iterations #33687

youknowriad opened this issue Jul 26, 2021 · 20 comments
Labels
Customization Issues related to Phase 2: Customization efforts [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Needs Design Needs design efforts.

Comments

@youknowriad
Copy link
Contributor

youknowriad commented Jul 26, 2021

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.
@youknowriad youknowriad added Customization Issues related to Phase 2: Customization efforts [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jul 26, 2021
@youknowriad youknowriad added the Needs Design Needs design efforts. label Jul 26, 2021
@mtias
Copy link
Member

mtias commented Jul 27, 2021

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

@youknowriad
Copy link
Contributor Author

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.

@mtias
Copy link
Member

mtias commented Jul 28, 2021

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.

@ghost
Copy link

ghost commented Jul 28, 2021

I really like where this is going. From a UX perspective, I think that Webflow does an excellent job with their Grid/Flex layout interfaces.

@richtabor
Copy link
Member

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

@mtias
Copy link
Member

mtias commented Apr 10, 2022

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

@youknowriad
Copy link
Contributor Author

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.

@jasmussen
Copy link
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?

@mtias
Copy link
Member

mtias commented Apr 11, 2022

For self-positioning?

@jasmussen
Copy link
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.

@youknowriad
Copy link
Contributor Author

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

@jasmussen
Copy link
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. 🤔

@mtias
Copy link
Member

mtias commented Apr 11, 2022

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.

@jasmussen
Copy link
Contributor

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

@youknowriad
Copy link
Contributor Author

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

@jasmussen
Copy link
Contributor

jasmussen commented Apr 11, 2022

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?

@youknowriad
Copy link
Contributor Author

youknowriad commented Apr 11, 2022

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.

@jasmussen
Copy link
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

@apeatling apeatling moved this from 🔺 Stale to ⏳ In Progress in Design Tools Project Apr 25, 2022
@mtias
Copy link
Member

mtias commented May 23, 2022

@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.

@youknowriad
Copy link
Contributor Author

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

@mtias mtias closed this as completed May 23, 2022
Repository owner moved this from ⏳ In Progress to ✅ Done in Design Tools Project May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customization Issues related to Phase 2: Customization efforts [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Needs Design Needs design efforts.
Projects
Status: Done
Development

No branches or pull requests

4 participants