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

Columns block: Enable blockGap and vertical margin support #34630

Merged
merged 4 commits into from
Oct 5, 2021

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Sep 8, 2021

Description

Following on from #33991 and the Columns CSS change by @richtabor in #34456, this PR opts the Columns block in to the gap block support control, and also the vertical margin control.

Adjusting block gap allows the user to adjust the space between columns blocks. Depending on where the columns block is placed, and whether or not the theme uses the Layout support, the adjusted block gap value can also change the gap between the selected block and blocks around it. To allow the user to tweak this, the margin control is added, so that the margin can be controlled separately to the gap on inner blocks.

Up for discussion: which controls are good to display by default? Does it make sense to expose blockGap by default, but hide margin? Should we default to both? I'd love to hear feedback on what's best to expose here.

Changes proposed

  • Opt the Columns block in to using the blockGap support
  • Opt the Columns block in to using the margin support for vertical margins
  • Update the gap support label to Block spacing

How has this been tested?

Running TT1-Blocks theme, in the theme.json file, under settings.spacing, enable the blockGap and customMargin controls. For example, here's how that section of my theme.json file looks:

		"spacing": {
			"blockGap": true,
			"customPadding": true,
			"customMargin": true,
			"units": [
				"px",
				"em",
				"rem",
				"vh",
				"vw"
			]
		},
  1. Add a Columns block to a post or page, and try out the blockGap control in the inspector controls.
  2. Try adding the Columns block to different positions in a page or post, and adjust the blockGap value.
  3. In the Dimensions panel, enable the Margin control, and try adjusting the margin to adjust the spacing around the block.
  4. Test in the site editor

Screenshots

columns-block-gap-support.mp4

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested. (manually)
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@andrewserong andrewserong added [Type] Enhancement A suggestion for improvement. [Block] Columns Affects the Columns Block [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Sep 8, 2021
@andrewserong andrewserong self-assigned this Sep 8, 2021
@andrewserong
Copy link
Contributor Author

Joen, I've added you as a reviewer since we've both been working on gap support, please let me know if there are other folks I should ping for feedback, too!

@andrewserong andrewserong linked an issue Sep 8, 2021 that may be closed by this pull request
@jasmussen
Copy link
Contributor

Always happy to review 👌

Nice work on this one. I like that it's a minimal change to the codebase. More than anything this illustrates the need for some thought put into the sidebar panels. We've been talking about Dimensions, Spacing and Layout panels for a bit now, and waffling on which controls go where, and whether perhaps we have only two of the above. For example, gap might be a layout control since it affects the items inside. But then isn't spacing? And if we do have spacing, couldn't block gap be part of that? I know this is something @youknowriad has thought a lot about as well, would love his input.

@richtabor
Copy link
Member

For example, gap might be a layout control since it affects the items inside. But then isn't spacing? And if we do have spacing, couldn't block gap be part of that? I know this is something @youknowriad has thought a lot about as well, would love his input.

Totally agree, and something I started highlighting in #34558. I feel we could condense most of the dimensions type controls into a more global Layout panel, but the tricky part is, that while the Group block has a "Layout" panel, the "Columns" block does not.

Comes down to the idea that perhaps we have a Layout panel that adapts a bit based on the block. For example, perhaps the Group block's layout panel has the "inherit default layout" and "alignments" parts, as well as blockGap — while the Column's block layout panel has the columns count UI, stack on mobile, and blockGap. I'll relay these thoughts on my original issue, but wanted to chime in here.

In other new though — I tested the PR and it works great! :)

Copy link
Contributor

@apeatling apeatling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this and it's working as expected for me. I also agree on thinking about where these settings go.

I'm also concerned about calling this "Block gap" as a setting in this context. I know with the supports mechanism this is difficult, but would it not be better named contextually in situations like this? So calling it "Column gap" here? Not a blocker obviously.

@andrewserong
Copy link
Contributor Author

Thanks for testing @apeatling!

but would it not be better named contextually in situations like this?

That's a great point — I suspect if I were a new user, I'd have no idea what "Block gap" means, but "Column gap" or ("Image gap" in the context of a Gallery block) would be much clearer. I think it'd also help a bit with the "Block gap" control feeling possibly out of place in the Dimensions panel as it is now. With a better name, maybe it'll feel slightly more at home.

In some of the other designs folks have shared (e.g. Joen in this comment #28356 (comment)) I see that the label "Block spacing" has been used, which might be a bit more natural for users?

I really like the suggestion of "Column gap", though, so my preferred option would be to see if we can allow each block that opts-in to the blockGap support to set its own override label (@aaronrobertshaw had a good idea of seeing if we can set this in the theme.json). I think getting the labelling right will be important to the usability of the feature, so I'll dig in a little further and explore out options. Thanks!

@ramonjd
Copy link
Member

ramonjd commented Sep 14, 2021

Nice work!

To allow the user to tweak this, the margin control is added, so that the margin can be controlled separately to the gap on inner blocks.

I like the fact that margin is available if only to override the margin-top: var( --wp--style--block-gap );. I am wondering if we need this rule at all? The columns block stands on its own, as a single row of columns. With margin controls it seems superfluous.

I'd expect a grid block, with multiple rows to spread spacing evenly.

Caveat: I'm probably missing context somewhere.

With margin support:

with-margin-support

Without:

without-margin-support

Do you think it's worth making margin a default control in the panel?

It's not a biggie. As others have mentioned it tests well otherwise!

I think getting the labelling right will be important to the usability of the feature, so I'll dig in a little further and explore out options. Thanks!

Providing the ability to tweak labels in theme.json sounds like a flexible solution. I ask myself though if it will open the doors to JSON bloat.

Gutter seems like a standard term to describe spacing between columns. I'm not sure if it's generic enough to speak to a wider audience though.

It also might connote even distribution of space between column rows, which we won't have until we have a grid block 😆

@andrewserong
Copy link
Contributor Author

Thanks for testing @ramonjd!

I like the fact that margin is available if only to override the margin-top: var( --wp--style--block-gap );. I am wondering if we need this rule at all?

I believe that margin rule comes from the Layout block support styling via #33812. There's some discussion from this comment onwards on that PR that gives a bit more context as to the usage of top margins on child elements to control that particular spacing. As long as that CSS rule is present, I think it's worth us having the margin control in place (even if it's hidden in the menu) so that once we start adjusting the gap value, we can fix the margin in place if we need to. At least, that was my thinking!

Providing the ability to tweak labels in theme.json sounds like a flexible solution. I ask myself though if it will open the doors to JSON bloat.

Quite possibly! I think the idea is that if we can have it in Gutenberg's theme.json for each of the blocks, then individual themes won't need to override it, so hopefully that bloat won't be something that theme authors need to contend with. But maybe block.json is a better place for it? Either way, I'm happy to explore our options. I might do that in a separate PR, though, since the solution will be applicable to each of the opt-ins rather than just the Columns block.

@jasmussen
Copy link
Contributor

In some of the other designs folks have shared (e.g. Joen in this comment #28356 (comment)) I see that the label "Block spacing" has been used, which might be a bit more natural for users?

Block spacing is probably a great thing to start with, as it's agnostic across the blocks on which it's applied. At the moment, the columns block is decidedly desktop-first in its approach to a row of columns, but even now it has a "stack on mobile" option, where columns wrap onto new lines. In that context, and in light of potential intrinsic responsiveness (#34641), block spacing works to indicate it's meant both for vertical and horizontal spacing. "Column spacing" might work as well, but before we add extra conditionals it feels worth it to see if just "Block spacing" feels intuitive enough in use.

@andrewserong andrewserong force-pushed the update/columns-block-to-use-gap-block-support branch from fac8026 to 5c0fb4c Compare September 15, 2021 06:56
@github-actions
Copy link

github-actions bot commented Sep 15, 2021

Size Change: +16 B (0%)

Total Size: 1.07 MB

Filename Size Change
build/block-editor/index.min.js 134 kB -9 B (0%)
build/block-library/index.min.js 146 kB +25 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.19 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 13.9 kB
build/block-editor/style.css 13.9 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 474 B
build/block-library/blocks/button/editor.css 474 B
build/block-library/blocks/button/style-rtl.css 600 B
build/block-library/blocks/button/style.css 600 B
build/block-library/blocks/buttons/editor-rtl.css 315 B
build/block-library/blocks/buttons/editor.css 315 B
build/block-library/blocks/buttons/style-rtl.css 370 B
build/block-library/blocks/buttons/style.css 370 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 206 B
build/block-library/blocks/columns/editor.css 205 B
build/block-library/blocks/columns/style-rtl.css 497 B
build/block-library/blocks/columns/style.css 496 B
build/block-library/blocks/cover/editor-rtl.css 666 B
build/block-library/blocks/cover/editor.css 670 B
build/block-library/blocks/cover/style-rtl.css 1.23 kB
build/block-library/blocks/cover/style.css 1.23 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 977 B
build/block-library/blocks/gallery/editor.css 982 B
build/block-library/blocks/gallery/style-rtl.css 1.6 kB
build/block-library/blocks/gallery/style.css 1.59 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 728 B
build/block-library/blocks/image/editor.css 728 B
build/block-library/blocks/image/style-rtl.css 482 B
build/block-library/blocks/image/style.css 487 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 488 B
build/block-library/blocks/media-text/style.css 485 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 568 B
build/block-library/blocks/navigation-link/editor.css 570 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 300 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/style-rtl.css 195 B
build/block-library/blocks/navigation-submenu/style.css 195 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.72 kB
build/block-library/blocks/navigation/editor.css 1.72 kB
build/block-library/blocks/navigation/style-rtl.css 1.62 kB
build/block-library/blocks/navigation/style.css 1.61 kB
build/block-library/blocks/navigation/view.min.js 2.74 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 198 B
build/block-library/blocks/page-list/style.css 198 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/editor-rtl.css 210 B
build/block-library/blocks/post-author/editor.css 210 B
build/block-library/blocks/post-author/style-rtl.css 182 B
build/block-library/blocks/post-author/style.css 181 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B
build/block-library/blocks/post-comments-form/style.css 140 B
build/block-library/blocks/post-comments/style-rtl.css 360 B
build/block-library/blocks/post-comments/style.css 359 B
build/block-library/blocks/post-content/editor-rtl.css 138 B
build/block-library/blocks/post-content/editor.css 138 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 398 B
build/block-library/blocks/post-featured-image/editor.css 398 B
build/block-library/blocks/post-featured-image/style-rtl.css 143 B
build/block-library/blocks/post-featured-image/style.css 143 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 391 B
build/block-library/blocks/post-template/style.css 392 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 60 B
build/block-library/blocks/post-title/style.css 60 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 378 B
build/block-library/blocks/pullquote/style.css 378 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 262 B
build/block-library/blocks/query-pagination/editor.css 255 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query-title/editor-rtl.css 85 B
build/block-library/blocks/query-title/editor.css 85 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 220 B
build/block-library/blocks/quote/theme.css 222 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 374 B
build/block-library/blocks/search/style.css 375 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 250 B
build/block-library/blocks/separator/style.css 250 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 462 B
build/block-library/blocks/site-logo/editor.css 464 B
build/block-library/blocks/site-logo/style-rtl.css 153 B
build/block-library/blocks/site-logo/style.css 153 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 165 B
build/block-library/blocks/social-link/editor.css 165 B
build/block-library/blocks/social-links/editor-rtl.css 812 B
build/block-library/blocks/social-links/editor.css 811 B
build/block-library/blocks/social-links/style-rtl.css 1.3 kB
build/block-library/blocks/social-links/style.css 1.3 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 636 B
build/block-library/blocks/template-part/editor.css 635 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/editor-rtl.css 90 B
build/block-library/blocks/term-description/editor.css 90 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 853 B
build/block-library/common.css 849 B
build/block-library/editor-rtl.css 9.76 kB
build/block-library/editor.css 9.75 kB
build/block-library/reset-rtl.css 536 B
build/block-library/reset.css 536 B
build/block-library/style-rtl.css 10.4 kB
build/block-library/style.css 10.4 kB
build/block-library/theme-rtl.css 665 B
build/block-library/theme.css 669 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 45.7 kB
build/components/index.min.js 214 kB
build/components/style-rtl.css 15.9 kB
build/components/style.css 15.9 kB
build/compose/index.min.js 10.3 kB
build/core-data/index.min.js 12.4 kB
build/customize-widgets/index.min.js 11.1 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.1 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.45 kB
build/edit-navigation/index.min.js 15.3 kB
build/edit-navigation/style-rtl.css 3.74 kB
build/edit-navigation/style.css 3.74 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.2 kB
build/edit-post/style-rtl.css 7.19 kB
build/edit-post/style.css 7.18 kB
build/edit-site/index.min.js 28.9 kB
build/edit-site/style-rtl.css 5.42 kB
build/edit-site/style.css 5.42 kB
build/edit-widgets/index.min.js 15.7 kB
build/edit-widgets/style-rtl.css 4.1 kB
build/edit-widgets/style.css 4.1 kB
build/editor/index.min.js 37.5 kB
build/editor/style-rtl.css 3.76 kB
build/editor/style.css 3.75 kB
build/element/index.min.js 3.17 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 5.93 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.6 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.3 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.28 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.6 kB
build/server-side-render/index.min.js 1.5 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.74 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@andrewserong
Copy link
Contributor Author

andrewserong commented Sep 15, 2021

Thanks for the feedback @jasmussen!

I was curious to see how we might go about overriding the label, because I was thinking about those other use cases for gap support that might not involve inner blocks (and to see how difficult it might be). I've updated this PR with an exploration:

It seemed to be fairly straightforward to add in a couple of simple functions to use the __experimentalLabel function that can be added to blocks when they're registered. By passing in a blockGap context string, we can return an override for the block. There were a couple of other ideas floated (e.g. use the theme-i18n.json file, or add a filter, which was mentioned here by @oandregal ). Hooking into the label seemed to be an approach that required the least amount of code from within the block, but at the same time, @mtias did mention on a previous PR that we should try to keep the supports as simple as possible, so I'm happy to revert if this approach doesn't seem viable or warranted!

To show what it looks like now, here's the view with the Column spacing override text, and with the Block spacing fallback for blocks that don't provide their own __experimentalLabel with the blockGap context string:

Column spacing Block spacing fallback
image image

One problem with Column spacing versus Column gap is that the former is slightly too long for the single column in the global styles panel (since that panel has more padding than the block inspector sidebar). So if we go with that string, we might need to move the control to be a full width column to avoid truncating the string:

I'm keen to hear what everyone thinks, both for which string to use, and for what's an appropriate approach for overriding a block support's control label from a block's settings. I'm not at all attached to the approach that I included in this PR, so happy to go in another direction or revert as needed 🙂

@jasmussen
Copy link
Contributor

jasmussen commented Sep 15, 2021

Thanks for continuing on this. One instinct I have in exploring new ground is to always do as little as possible and leave as much as possible to followups. That way they can happen if they turn out to be necessary, whereas if we start with too much we don't realize what might have been unnecessary in the first place. In the case of gap, the precedence I keep coming back to is Figma's autolayout, which calls the feature "Spacing between items" — somewhat similarly agnostic to "Block spacing". So it's nice to know that tweaking the label is possible/easy, in case it becomes clear we really do need it.

In the case of the available space, while the following mockup remains subject to change per details being worked on in #34574, it does point to the block spacing control always being a full row, rather than a 50% width column item:

Spacing

In the above, the icon to the right of the slider both serves to indicate which spacing is being adjusted, and as a button to toggle axial controls. Followup territory of course, but it does suggest the full row of space is available.

@@ -79,6 +79,11 @@ export const settings = {
},
],
},
__experimentalLabel( _, { context } ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API sounds very weird to me, using a "block API" to label a block support. Did we consider a config in the block.json file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is pretty weird, particularly now that I've had a chance to sleep on it! I think a config in block.json would be a better way to go about it.

I agree with Joen, though, that it'd be good to try to do the least amount of work here as possible for the Columns block, so in the immediate term, I'm going to revert the label overriding and just set the string to a hard-coded Block spacing for the time being.

If and when we get back to it, I'll take a look at seeing if we can set it in the block.json file. Thanks for taking a look 🙂

@andrewserong
Copy link
Contributor Author

Thanks for the feedback @jasmussen!

One instinct I have in exploring new ground is to always do as little as possible and leave as much as possible to followups. That way they can happen if they turn out to be necessary, whereas if we start with too much we don't realize what might have been unnecessary in the first place.

That's very wise, and I agree, I really like small iterative PRs rather than packing in too much at once. I've reverted the label override behaviour, which we can defer to figuring out further down the track if we need it. I've retained the update to the string so that it now reads Block spacing.

it does point to the block spacing control always being a full row, rather than a 50% width column item

Good to know! Since the label Block spacing fits within the single 50% width column, I've left that styling as-is so that the UnitControl is a comfortable width, rather than stretching on too long. I thought we could take a look at switching to full width when we update the control that we're using when we eventually implement axial controls?

I explored removing the single-column class, but we'd then need to add some CSS to force the UnitControl to an appropriate width, so I left it in place, but here's a screenshot for visibility sake 🙂

Removing single-column class Current state of this PR
image image

Do let me know if you'd like further changes or tweaks, of course!

@apeatling
Copy link
Contributor

I agree with Riad, let's test in the plugin first for a cycle.

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The columns spacing + margin looks good to me. Copy change is also 👍

Oct-05-2021.12-24-44.mp4

✅ I can apply block spacing and margins in the block and site editors. The frontend appears as I'd expect and the styles are applied, e.g,

.wp-block-columns {
    margin-top: 62px;
    margin-bottom: 62px;
    --wp--style--block-gap: 64px;
}

I noticed that I cannot completely clear the margin value from the field.

I've approved this PR as the changes aren't related it appears.

In the Block Editor the value persists until I remove the field or Reset All.

In the Site Editor it persists even after I've Reset All.

columns-margin-reset

Is that expected?

@ramonjd
Copy link
Member

ramonjd commented Oct 5, 2021

I noticed that I cannot completely clear the margin value from the field.

I was just testing this again and it's only when I clear the field and blur out. If I hit the Enter key, the value persists. Maybe we need to handle null values in the blur event of UnitControl? I don't know yet 🤷

@andrewserong
Copy link
Contributor Author

Thanks for testing @ramonjd! I think the different behaviour you're seeing with the margin support is that the BoxControl component that it uses sets isPressEnterToChange on its UnitControl, so to clear the value, you need to hit Enter. For the gap control, where we're using the UnitControl component directly, we haven't set that flag.

I think I have a personal preference to not requiring pressing Enter to commit the value in the BoxControl, but that's probably something for us to look at in a separate PR? I can see an argument for going either way.

@ramonjd
Copy link
Member

ramonjd commented Oct 5, 2021

PressEnterToChange on its UnitControl, so to clear the value, you need to hit Enter. For the gap control, where we're using the UnitControl component directly, we haven't set that flag.

Thanks for confirming! I was looking at mayUpdateUnit() and came across it. I wanted to see if we could do something differently onBlur, but yeah... another PR :)

I think I have a personal preference to not requiring pressing Enter to commit the value in the BoxControl, but that's probably something for us to look at in a separate PR? I can see an argument for going either way.

Definitely. I just wanted to flag it.

I also have a personal preference (or maybe an expectation) that I can clear a form field's value this way, especially if the fields in the same panel behave differently.

Not a blocker for this PR. ✅

@andrewserong
Copy link
Contributor Author

Not a blocker for this PR. ✅

Thanks for confirming 👍

I also have a personal preference (or maybe an expectation) that I can clear a form field's value this way, especially if the fields in the same panel behave differently.

Okay, great, since we both have the same expectation, I'm happy to look into a PR for the margin and padding controls so we can start the discussion of switching it off there.

I'll merge this PR in now. If anyone thinks of other follow-ups we should look at, too, please let me know!

@brylie
Copy link
Contributor

brylie commented Nov 12, 2021

We sometimes need to space elements away from the edges of their parent container, such as when using a full-width Gutenberg block. Will the user also be able to add left and right margins?

E.g., the mockup in issue #24874

image

image

@ramonjd
Copy link
Member

ramonjd commented Nov 14, 2021

Will the user also be able to add left and right margins?

Is this the effect that you're describing?

Nov-15-2021 07-17-27

To achieve the above effect, it's possible to turn left and right margin and padding support on in theme.json, e.g.,

		"spacing": {
			"blockGap": true,
			"margin": true,
			"padding": false,
			"units": [ "px", "em", "rem", "vh", "vw", "%" ]
		},

I guess it depends on the underlying layout styles to whether left and right margins will have any effect however.

For example, the default layout width carries with it the following CSS:

    max-width: 650px;
    margin-left: auto !important;
    margin-right: auto !important;

Screen Shot 2021-11-15 at 7 32 27 am

@brylie
Copy link
Contributor

brylie commented Nov 19, 2021

Is this the effect that you're describing?

Yes! Thanks for the examples too 😃

@MuluhGodson
Copy link

MuluhGodson commented Nov 24, 2021

@ramonjd
I added the settings for custom paddings and margins:

"settings": {
		"spacing": {
			"customPadding": true,
			"customMargin": true,
			"units": [ "px", "em", "rem", "vh", "vw" ]
		}
	}

image

The padding controls display and works correctly. However, I can't see the margin controls. Is there some additional setup to be done?

P.S: I used theme.json v2 syntax but still the same

@brylie
Copy link
Contributor

brylie commented Nov 24, 2021

@MuluhGodson, for clarification, what type of Gutenberg block settings do we see in the example above? It may be that padding is enabled for some blocks but not others?

@MuluhGodson
Copy link

MuluhGodson commented Nov 24, 2021

@MuluhGodson, for clarification, what type of Gutenberg block settings do we see in the example above? It may be that padding is enabled for some blocks but not others?

The settings above are applied globally to all block elements. So each block can have its own padding and margin controls.

@ramonjd
Copy link
Member

ramonjd commented Nov 24, 2021

However, I can't see the margin controls. Is there some additional setup to be done?

👋 @MuluhGodson Which block are you trying to target, and where is the JSON?

I think @brylie has the answer: "It may be that padding is enabled for some blocks but not others?"

Enabling margin and padding globally via theme.json will "enable" margin and padding to used so long as block opt into them using the "supports" object. More info here on that.

So in your theme's theme.json you might have something like this under the "settings" object:

		"spacing": {
			"blockGap": true,
			"margin": true,
			"padding": true,
			"units": [ "px", "em", "rem", "vh", "vw", "%" ]
		},

This "enables" all spacing supports, and the blocks that opt into them via their individual block.json settings will show them. If the block doesn't opt in

You can control individual block settings via theme.json as well by adding an entry to the "blocks" object.

So you could set the spacing controls to show for the core Group Block in theme.json like this (so long as you have the global settings enabled):

		"blocks": {
			"core/group": {
				"spacing": {
					"blockGap": true,
					"margin": true,
					"padding": true,
					"units": [ "px", "em", "rem", "vh", "vw", "%" ]
				},
			}
		}

More information on theme.json over here.

Hope that helps!

@brylie
Copy link
Contributor

brylie commented Nov 24, 2021

Should we be using margin / padding or customMargin / customPadding properties? The block-supports spacing documentation uses margin and padding, while customMargin seems to also work (but not customPadding on whichever block type is depicted above).

@ramonjd
Copy link
Member

ramonjd commented Nov 24, 2021

Should we be using margin / padding or customMargin / customPadding properties?

Since #36155 margin and padding are preferred, though it looks like there's backwards compatibility for the previous custom* properties.

@MuluhGodson
Copy link

Should we be using margin / padding or customMargin / customPadding properties? The block-supports spacing documentation uses margin and padding, while customMargin seems to also work (but not customPadding on whichever block type is depicted above).

theme.json v1 using customPadding / customMargin while v2 removes the custom leaving is as margin / padding however there's backwards compatibility to v1 syntax. I will switch to v2.

@mjamesderocher
Copy link

Is there a way to limit the margin to predefined options? So instead of allowing any size value, there would be choices of say, small, medium, and large that are set in theme.json? This is how text sizing works, and with text, you have the choice to enter a custom value, but can also disable custom values being entered in theme.json.

@ramonjd
Copy link
Member

ramonjd commented Mar 10, 2022

Is there a way to limit the margin to predefined options? So instead of allowing any size value, there would be choices of say, small, medium, and large that are set in theme.json?

👋 This relates to the discussion over at #38998 about standardized tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Columns Affects the Columns Block [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Columns Block Gutter Size Option
9 participants