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

Consistent dimension controls across blocks. #28356

Open
4 of 23 tasks
youknowriad opened this issue Jan 20, 2021 · 13 comments
Open
4 of 23 tasks

Consistent dimension controls across blocks. #28356

youknowriad opened this issue Jan 20, 2021 · 13 comments

Comments

@youknowriad
Copy link
Task lists! Give feedback
Contributor

@youknowriad youknowriad commented Jan 20, 2021

This is a sub part of #27331

The tools to configure the spacing of a block are among some of the most incoherent tools we offer, with controls usually scattered across different panels and standalone tools. (See #23770, #24874, #26368, #22956, #14747.)

The proposed dimensions panel emerges as the consolidation of controls relating to the space a block occupies on the page. This includes but is not exhausted by height, padding, width, possibly alignment, and so on. Much like the typography panel, these controls are not always going to be present for every block, so it’s important individual controls can be toggled on and off as required, and that blocks can expose those that are considered default options based on configuration. The focus in this exercise is to test how the different controls ought to be laid out.

Screenshot 2021-01-20 at 12 46 00

Let's try to split the work needed to achieve the proposed output in these mockups:

Height Control

  • Build a block support flag (client and server) to enable "height" controls for blocks. The flag should automatically add a "height" attribute to the block, add the UI to the "Dimensions" panel, and apply the style automatically to the wrapper.
  • Global styles support.
  • Enable the height control flag in some experimental blocks (FSE blocks)
  • Migrate the adhoc "height" attributes and UI we might have in exiting blocks.
  • Decide whether it should be opt-in (with potential smart defaults depending on the container) or opt-out for block authors and enable the flag for all the desired blocks.

Question Should the height attribute be its own block attribute or should it be part of the "style" attribute.

Width Control

I'm not talking here about the "full width"/"wide width" UI here but more about the "width" control we have right now in some blocks like "column" or "button". Basically the equivalent of the height control shown as an input.

  • Build a block support flag (client and server) to enable "width" controls for blocks. The flag should automatically add a "width" attribute to the block, add the UI to the "Dimensions" panel, and apply the style automatically to the wrapper.
  • Global styles support.
  • Enable the control flag in some experimental blocks (FSE blocks)
  • Migrate the adhoc "width" attributes we might have in exiting blocks.
  • Decide whether it should be opt-in (with potential smart defaults depending on the container) or opt-out for block authors and enable the flag for all the desired blocks.

Question Should the attribute be its own block attribute or should it be part of the "style" attribute.

Padding

We do have an existing support flag for padding, so we need to adapt it to work consistently to the other controls.

  • Make sure the padding flag works in both client and server #30332
  • Enable the control flag in experimental blocks (FSE blocks)
  • Decide whether it should be opt-in (with potential smart defaults depending on the container) or opt-out for block authors and enable the flag for all the desired blocks.

Margin

The primary focus for this is to provide a spacing option between the blocks that can work globally.

  • Build a block support flag (client and server) to enable "margin" controls for blocks. The flag should automatically add a "margin" attribute to the block, add the UI to the "Dimensions" panel, and apply the style automatically to the wrapper. #30608
  • Global styles support.
  • Enable the margin control flag in some experimental blocks (FSE blocks)
  • Decide whether it should be opt-in (with potential smart defaults depending on the container) or opt-out for block authors and enable the flag for all the desired blocks.

Block Alignments

What we call block alignments is the "full width"/"wide width" UI shown in the mockups and sometimes it can include "left/right"... We do have a support flag for these called "align" but it has a few issues: It's not used consistently in blocks, some blocks have their own custom "align" support. Another problem is that it uses the "align" attribute which might have a different meaning in some other blocks.

The other issue here is that this control only make sense in the "default" layout (Meaning if the container is just a normal vertical list of blocks). In different layouts like the "flex" layout (which already exists in the code base but in an implicit way using the "orientation" prop), these alignments don't make any sense.

I think here we need to be more generic and instead of talking about "block alignments" we should just talk about "position". So inside a "default" layout container, the values can be "wide"/"full"/"left"/"right"/"center"/"none" but inside a "flex horizontal" container, these values don't apply and inside an "absolute container", we might have "x and y", inside a "grid" container we might have something else (rows, columns)

So I think what's important here at the moment is to scale down the scope to the "default" layout but we keep in mind how this attribute should or shouldn't translate to other future layouts.

Based on this, here's what I think should be the plan here:

  • Build a block support flag (client and server) to enable "position" controls for blocks. The flag should automatically add a "position" attribute to the block, add the UI to the "Dimensions" panel, and apply the classname automatically to the wrapper. The UI should only show up if we're inside a "default" layout container otherwise it doesn't.
  • Make sure that the"position" doesn't persist when moving blocks to a container with a different layout type
  • Global styles support.
  • Automatically set the layout to "flex-horizontal" for blocks that pass orientation="horizontal" to their InnerBlocks.
  • Enable the control flag in experimental blocks (FSE blocks)
  • Decide whether it should be opt-in or opt-out for block authors and enable the flag for all the desired blocks.
@youknowriad
Copy link
Contributor Author

@youknowriad youknowriad commented Mar 29, 2021

Started working on some of these. First thing is adding padding block support to dynamic blocks.

@youknowriad
Copy link
Contributor Author

@youknowriad youknowriad commented Mar 30, 2021

Started working on the margin block support in #30371

@youknowriad
Copy link
Contributor Author

@youknowriad youknowriad commented Mar 30, 2021

Padding server-side support flag is now merged.

@aristath
Copy link
Member

@aristath aristath commented Apr 2, 2021

Have we considered using a box-model control like the one browsers have in their dev tools?
box-model

Using something like that we could have padding, margin, borders, all in one, using a familiar UI, and we can definitely toggle features on/off by making some of the values editable...
A couple of years ago I built something similar for the customizer and it was pretty convenient at the time
kirki-box-model
Visually it was meh, but that's easy to fix... functionally it was intuitive and accessible

@jasmussen
Copy link
Contributor

@jasmussen jasmussen commented Apr 13, 2021

I ran into needing a margin today. This will be such an important tool to build great patterns.

@priethor
Copy link
Contributor

@priethor priethor commented Apr 20, 2021

As @jasmussen says, margin support seems to be one recurring tool required by many theme blocks to build rich patterns.

@carolinan
Copy link
Contributor

@carolinan carolinan commented May 12, 2021

I saw that a PR for adding support for margins to the site title block was merged.
If this is now implemented, shouldn't margin controls be enabled by default for all blocks?

@jasmussen
Copy link
Contributor

@jasmussen jasmussen commented May 12, 2021

If this is now implemented, shouldn't margin controls be enabled by default for all blocks?

I'm conflicted here. On the one hand, I deeply want this feature for better patterns. On the other hand, the current margin controls are very clunky, and there isn't a #27331 inspired design for how we surface margin/spacing in a user-friendly way yet. For example while we might know by heart the difference between margin and padding, this is not necessarily obvious for the average user — so do we put margin and padding behind a segmented control? Do we take up space and have controls for both visible at the same time? Is there an alternative that better abstracts the controls? It's a difficult design, and every feature we surface adds weight, even if it's a collapsed-by-default panel.

Question: can we enable margin support for all blocks through theme.json and markup, without surfacing the UI for it yet? While not the most obvious interface for building patterns, at least it would be technically unblocked as we refine the UI for it.

@aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented May 26, 2021

Margin block support was added in #30608.

I'm also starting to work on updating the spacing support panel into the proposed "Dimensions" panel. Once I have that in place, the plan is I'll add height and width support to that.

@aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Jun 3, 2021

There is a proof of concept up for the Dimensions panel in #32392.

It focuses on adding a new component that can easily be reused across multiple block supports. The individual block support controls for margin and padding can be updated as the G2 component matching the design gets imported in the near future.

The linked PR uses the new component to convert the current Spacing support panel into the basis for the new Dimensions panel. I'll be adding height and width support to it soon.

@mtias mtias mentioned this issue Jul 15, 2021
54 tasks
@mtias
Copy link
Contributor

@mtias mtias commented Aug 16, 2021

@jasmussen I've been thinking a bit about how we name and express these tools, because it seems we have three related but distinct elements: a layout panel, a spacing pane, and a dimensions panel. I'm not sure it makes sense to couple spacing with dimensions (padding/margin with width/height).

@aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Aug 17, 2021

I'd be happy to update the padding/margin support to appear again under a "Spacing" panel again. I can address that in the next day or so unless further discussion is required?

@mtias
Copy link
Contributor

@mtias mtias commented Aug 17, 2021

Let's see first if that is indeed what makes the most sense — @jasmussen @shaunandrews @pablohoneyhoney for thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants