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

Add layout content size controls to global styles #42309

Merged
merged 7 commits into from
Jul 20, 2022

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Jul 11, 2022

What?

Adds content size and wide size controls to global styles, under "Layout"

Why?

Fixes #35955.

How?

  • Enables contentSize and wideSize in ROOT_BLOCK_SUPPORTS;
  • Adds controls to Dimensions panel in the root Layout section of Global Styles sidebar.

Testing Instructions

  1. In the global styles panel, go to Layout and check that Content and Wide size inputs are visible under "Dimensions".
  2. Add values to those fields and check that content sizes update sitewide.
  3. Check that values can be reset from the kebab menu in the Dimensions panel.

Screenshots or screencast

Screen Shot 2022-07-15 at 5 45 23 pm

Screen Shot 2022-07-15 at 5 45 16 pm

@github-actions
Copy link

github-actions bot commented Jul 11, 2022

Size Change: +702 B (0%)

Total Size: 1.26 MB

Filename Size Change
build/block-editor/index.min.js 153 kB +143 B (0%)
build/block-library/blocks/post-comments-form/style-rtl.css 493 B -2 B (0%)
build/block-library/blocks/post-comments-form/style.css 493 B -2 B (0%)
build/block-library/blocks/template-part/editor-rtl.css 235 B +57 B (+32%) 🚨
build/block-library/blocks/template-part/editor.css 235 B +57 B (+32%) 🚨
build/block-library/common-rtl.css 1.01 kB +20 B (+2%)
build/block-library/common.css 1 kB +21 B (+2%)
build/block-library/editor-rtl.css 10.3 kB +26 B (0%)
build/block-library/editor.css 10.3 kB +26 B (0%)
build/block-library/index.min.js 184 kB -374 B (0%)
build/block-library/style-rtl.css 11.7 kB -1 B (0%)
build/block-library/style.css 11.7 kB -1 B (0%)
build/components/index.min.js 230 kB +169 B (0%)
build/components/style-rtl.css 14 kB -28 B (0%)
build/components/style.css 14 kB -30 B (0%)
build/edit-post/index.min.js 30.5 kB +9 B (0%)
build/edit-site/index.min.js 54.2 kB +561 B (+1%)
build/edit-site/style-rtl.css 8.24 kB +15 B (0%)
build/edit-site/style.css 8.23 kB +16 B (0%)
build/editor/index.min.js 41.3 kB +20 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 982 B
build/annotations/index.min.js 2.76 kB
build/api-fetch/index.min.js 2.26 kB
build/autop/index.min.js 2.14 kB
build/blob/index.min.js 475 B
build/block-directory/index.min.js 6.58 kB
build/block-directory/style-rtl.css 990 B
build/block-directory/style.css 991 B
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 14.6 kB
build/block-editor/style.css 14.6 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 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 103 B
build/block-library/blocks/audio/style.css 103 B
build/block-library/blocks/audio/theme-rtl.css 110 B
build/block-library/blocks/audio/theme.css 110 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 59 B
build/block-library/blocks/avatar/style.css 59 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 441 B
build/block-library/blocks/button/editor.css 441 B
build/block-library/blocks/button/style-rtl.css 543 B
build/block-library/blocks/button/style.css 543 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 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 103 B
build/block-library/blocks/code/style.css 103 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 187 B
build/block-library/blocks/comment-template/style.css 185 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 95 B
build/block-library/blocks/comments/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 615 B
build/block-library/blocks/cover/editor.css 616 B
build/block-library/blocks/cover/style-rtl.css 1.55 kB
build/block-library/blocks/cover/style.css 1.55 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 110 B
build/block-library/blocks/embed/theme.css 110 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 253 B
build/block-library/blocks/file/style.css 254 B
build/block-library/blocks/file/view.min.js 346 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 948 B
build/block-library/blocks/gallery/editor.css 950 B
build/block-library/blocks/gallery/style-rtl.css 1.53 kB
build/block-library/blocks/gallery/style.css 1.53 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 333 B
build/block-library/blocks/group/editor.css 333 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 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 327 B
build/block-library/blocks/html/editor.css 329 B
build/block-library/blocks/image/editor-rtl.css 736 B
build/block-library/blocks/image/editor.css 737 B
build/block-library/blocks/image/style-rtl.css 627 B
build/block-library/blocks/image/style.css 630 B
build/block-library/blocks/image/theme-rtl.css 110 B
build/block-library/blocks/image/theme.css 110 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 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 463 B
build/block-library/blocks/latest-posts/style.css 462 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 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 493 B
build/block-library/blocks/media-text/style.css 490 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 705 B
build/block-library/blocks/navigation-link/editor.css 703 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation-submenu/view.min.js 423 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.96 kB
build/block-library/blocks/navigation/style.css 1.95 kB
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB
build/block-library/blocks/navigation/view.min.js 443 B
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 363 B
build/block-library/blocks/page-list/editor.css 363 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 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 260 B
build/block-library/blocks/paragraph/style.css 260 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments/editor-rtl.css 77 B
build/block-library/blocks/post-comments/editor.css 77 B
build/block-library/blocks/post-comments/style-rtl.css 632 B
build/block-library/blocks/post-comments/style.css 630 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 605 B
build/block-library/blocks/post-featured-image/editor.css 605 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 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 282 B
build/block-library/blocks/post-template/style.css 282 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 80 B
build/block-library/blocks/post-title/style.css 80 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 370 B
build/block-library/blocks/pullquote/style.css 370 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 221 B
build/block-library/blocks/query-pagination/editor.css 211 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/editor-rtl.css 365 B
build/block-library/blocks/query/editor.css 364 B
build/block-library/blocks/quote/style-rtl.css 213 B
build/block-library/blocks/quote/style.css 213 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 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 385 B
build/block-library/blocks/search/style.css 386 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 233 B
build/block-library/blocks/separator/style.css 233 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 464 B
build/block-library/blocks/shortcode/editor.css 464 B
build/block-library/blocks/site-logo/editor-rtl.css 708 B
build/block-library/blocks/site-logo/editor.css 708 B
build/block-library/blocks/site-logo/style-rtl.css 192 B
build/block-library/blocks/site-logo/style.css 192 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 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.39 kB
build/block-library/blocks/social-links/style.css 1.38 kB
build/block-library/blocks/spacer/editor-rtl.css 322 B
build/block-library/blocks/spacer/editor.css 322 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 494 B
build/block-library/blocks/table/editor.css 494 B
build/block-library/blocks/table/style-rtl.css 611 B
build/block-library/blocks/table/style.css 609 B
build/block-library/blocks/table/theme-rtl.css 175 B
build/block-library/blocks/table/theme.css 175 B
build/block-library/blocks/tag-cloud/style-rtl.css 226 B
build/block-library/blocks/tag-cloud/style.css 227 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/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 561 B
build/block-library/blocks/video/editor.css 563 B
build/block-library/blocks/video/style-rtl.css 159 B
build/block-library/blocks/video/style.css 159 B
build/block-library/blocks/video/theme-rtl.css 110 B
build/block-library/blocks/video/theme.css 110 B
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/theme-rtl.css 695 B
build/block-library/theme.css 700 B
build/block-serialization-default-parser/index.min.js 1.11 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 47.1 kB
build/compose/index.min.js 11.7 kB
build/core-data/index.min.js 14.7 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.4 kB
build/customize-widgets/style.css 1.4 kB
build/data-controls/index.min.js 653 B
build/data/index.min.js 7.99 kB
build/date/index.min.js 32 kB
build/deprecated/index.min.js 507 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.69 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 4.02 kB
build/edit-navigation/style.css 4.03 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/style-rtl.css 6.97 kB
build/edit-post/style.css 6.97 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.35 kB
build/edit-widgets/style.css 4.35 kB
build/editor/style-rtl.css 3.65 kB
build/editor/style.css 3.65 kB
build/element/index.min.js 4.27 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 6.75 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.64 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.77 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.78 kB
build/keycodes/index.min.js 1.38 kB
build/list-reusable-blocks/index.min.js 1.74 kB
build/list-reusable-blocks/style-rtl.css 835 B
build/list-reusable-blocks/style.css 835 B
build/media-utils/index.min.js 2.93 kB
build/notices/index.min.js 953 B
build/nux/index.min.js 2.05 kB
build/nux/style-rtl.css 732 B
build/nux/style.css 728 B
build/plugins/index.min.js 1.94 kB
build/preferences-persistence/index.min.js 2.22 kB
build/preferences/index.min.js 1.3 kB
build/primitives/index.min.js 933 B
build/priority-queue/index.min.js 612 B
build/react-i18n/index.min.js 696 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.68 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.1 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.53 kB
build/token-list/index.min.js 644 B
build/url/index.min.js 3.61 kB
build/vendors/react-dom.min.js 38.5 kB
build/vendors/react.min.js 4.34 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.19 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Oh, this is testing quite nicely so far! I was wondering at first if the HStack component might help simplify things a bit versus the Flex component (it doesn't seem to need the children the be FlexItems?), but I don't think it helps directly with the icon positioning. Shame that UnitControl's positioning doesn't appear to neatly allow additional elements at the same vertical position as the input field 🤔

The UI here also demonstrates nicely a point you made in the root CSS PR that these controls seem to fit logically with padding and other dimensions controls, they look good alongside each other, all under a Layout panel. Not sure what that means for future iterations of the block level inspector controls, but at least from my perspective, these controls look nicely at home in this panel! 👍

Not really related to this PR, but I noticed while testing that the Reset to Defaults button in the dropdown correctly resets the values, but not the ToolsPanel state — so the ellipsis menu thinks that the value is still customised. It doesn't appear to actually cause any issues so probably not something to worry about in this PR, but just thought I'd mention it:

2022-07-12 17 03 02

@tellthemachines
Copy link
Contributor Author

Thanks for testing @andrewserong ! I hadn't thought of HStack; I tried it but as you mentioned the icon positioning isn't quite right. It's working well with Flex now that I added alignment, but I suspect that's mostly because of the div wrapper that FlexItem adds around it 😅

As a side note, we can use the as prop on FlexItem to render children without the div, but for some reason doing that with Icon strips out the contents of the svg element. Seems like a bug, will test further.

Another option would be to add styles directly instead of using these components, and that would allow us to make micro-adjustments to margins as needed.

Not really related to this PR, but I noticed while testing that the Reset to Defaults button in the dropdown correctly resets the values, but not the ToolsPanel state — so the ellipsis menu thinks that the value is still customised. It doesn't appear to actually cause any issues so probably not something to worry about in this PR, but just thought I'd mention it:

Ah, well spotted! Testing on trunk, it seems like the global reset doesn't change the padding value in the input either - it does reset it, but the number only disappears after save and refresh. Might be best to look into that behaviour separately.

@tellthemachines
Copy link
Contributor Author

Update: opened #42380 for FlexItem swallowing its children.

@tellthemachines tellthemachines force-pushed the add/content-size-in-global-styles branch from 8b73485 to bd6e4af Compare July 15, 2022 07:05
@tellthemachines tellthemachines marked this pull request as ready for review July 15, 2022 07:43
@tellthemachines tellthemachines added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jul 15, 2022
Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

The positioning in the UI's looking good now @tellthemachines! Do we need to add the explanatory text from the editor UI for the content/wide sizes, too?

Updating the content and wide size at the root level is working well, but the reset behaviour is still a bit unreliable for me. Also, I found an edge case with blocks that don't display content/wide size, and added a comment about the weird ToolsPanel menu behaviour — unfortunately I couldn't quite work out what's going on there 🤔

Another thought is that the resetAll function passed to the ToolsPanel should probably include the reset calls for the content and wide sizes, too... but probably only if the showContentSizeControl and showWideSizeControl variables are truthy?

Happy to do more testing!

@@ -141,6 +178,66 @@ export default function DimensionsPanel( { name } ) {

return (
<ToolsPanel label={ __( 'Dimensions' ) } resetAll={ resetAll }>
<Flex>
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this row might need to be behind a check for showContentSizeControl || showSideSizeControl, otherwise in the Layout panel at the block level, there is a larger space due to the gap surrounding the empty Flex component:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yes, definitely!

name
);

const hasContentSizeValue = () => !! contentSizeValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Taking another look at this check, I'm wondering if part of the issue with the ToolsPanel menu state is that if the contentSizeValue matches the value after reset, then this will return true. So if my content width is set to 840px and I change it to 900px and then reset it, the value here is 840px, and so the menu item thinks there's still a custom value?

That said, there seems to be something else funny going on, because when I first load the site editor, the ToolsPanel seems to be showing padding as customised, too 🤔

image

The weird behaviour does appear to be on trunk, too, so not sure if it's worth attempting to fix now? I think on trunk it's a little less visible because it seems to be working fine at the block level, and we currently only have the Padding dimensions control made visible at the root level 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

So if my content width is set to 840px and I change it to 900px and then reset it, the value here is 840px, and so the menu item thinks there's still a custom value?

It appears that the menu is reflecting exactly what the hasContentSizeValue callback is telling it. Any truthy value for contentSizeValue is going to state that the ToolsPanelItem has a customized value.

If I understand the situation correctly, there's always a root value so the logic here needs to be more nuanced. It should be checking if the user has set a value i.e. check the style value from the user origin rather than the merged styles aka all origin.

The border panel checks the user origin border styles to reflect the whether the user has customized any values e.g. const [ userBorderStyles ] = useStyle( 'border', name, 'user' );

It would be a worthwhile follow up to give these global styles panels an audit to check they all behave appropriately. I know things have evolved rapidly here on multiple fronts so its entirely possible a few gremlins crept in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking for user styles makes sense! Updated.

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this @tellthemachines 👍

In terms of the content/width size, it is testing pretty well for me. I hit similar issues as @andrewserong however with the new controls/panel behaviour.

Before digging too deep into things, it might be worth highlighting here a recent issue found that impacts resetting input control based components for which @stokesman already has a fix up for in #42484.

Cherry picking the fix from that PR fixed a couple of resetting issues encountered while testing this one.

Not really related to this PR, but I noticed while testing that the Reset to Defaults button in the dropdown correctly resets the values, but not the ToolsPanel state

Global Styles' option to "reset to defaults" clears all the values independently. Given it happens outside the ToolsPanel callbacks there is nothing to trigger its internal state update. (Would it be too hacky to force a new ToolsPanel when the global styles are reset?)

In some past discussions it was raised that clearing a value from the field could be a customization and therefore we couldn't really catch the fact the field was empty and automatically remove the customized status reflected in the panel menu. The thinking at the time was that this wasn't a real issue. I'm not sure if that needs revisiting though via a follow-up.

Long story, short. I don't think the "reset to defaults" issue should block this PR at all.

I've also left a couple of other inline comments that might help smooth out the customized value display or reduce some markup. Hope that helps.

Comment on lines 184 to 190
<FlexItem>
<ToolsPanelItem
label={ __( 'Content size' ) }
hasValue={ hasContentSizeValue }
onDeselect={ resetContentSizeValue }
isShownByDefault={ true }
>
Copy link
Contributor

Choose a reason for hiding this comment

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

ToolsPanelItem is polymorphic as well so you should be able to just add the as={ FlexItem } to it right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhh thanks hadn't thought of that!

name
);

const hasContentSizeValue = () => !! contentSizeValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

So if my content width is set to 840px and I change it to 900px and then reset it, the value here is 840px, and so the menu item thinks there's still a custom value?

It appears that the menu is reflecting exactly what the hasContentSizeValue callback is telling it. Any truthy value for contentSizeValue is going to state that the ToolsPanelItem has a customized value.

If I understand the situation correctly, there's always a root value so the logic here needs to be more nuanced. It should be checking if the user has set a value i.e. check the style value from the user origin rather than the merged styles aka all origin.

The border panel checks the user origin border styles to reflect the whether the user has customized any values e.g. const [ userBorderStyles ] = useStyle( 'border', name, 'user' );

It would be a worthwhile follow up to give these global styles panels an audit to check they all behave appropriately. I know things have evolved rapidly here on multiple fronts so its entirely possible a few gremlins crept in.

@tellthemachines
Copy link
Contributor Author

Thanks for the reviews, folks!

Do we need to add the explanatory text from the editor UI for the content/wide sizes, too?

I think the text we see currently in the block Layout panel ("Customize the width for all elements that are assigned to the center or wide columns.") is a bit confusing even in the block context, and more so here because we're setting widths site-wide here, so "customize" in this case just means "set a new global value". Is it just me? Perhaps we should rethink that copy, and think of a specific one for this global control. Would something like "Set the width of the main content area" work here?

Also, I found an edge case with blocks that don't display content/wide size

Was that the Flex markup showing, or did I miss something else?

Before digging too deep into things, it might be worth highlighting here a recent #42455 found that impacts resetting input control based components for which @stokesman already has a fix up for in #42484.

Ah, good to know! If that one gets merged soon I'll rebase this PR.

Would it be too hacky to force a new ToolsPanel when the global styles are reset?

I'm not sure. Thinking about the UX, it's unlikely someone will go into the individual reset panels after resetting all, unless the global reset didn't work? Maybe we can look at that as a separate task and consider the options.

One thing I'm not sure about: currently, these controls only display if the theme has contentSize/wideSize set in its theme.json. Is this the desired state of things? Or do we want it to be possible to set content widths even if the theme doesn't support them?

@aaronrobertshaw
Copy link
Contributor

One thing I'm not sure about: currently, these controls only display if the theme has contentSize/wideSize set in its theme.json. Is this the desired state of things? Or do we want it to be possible to set content widths even if the theme doesn't support them?

My understanding is that one of the features of theme.json is that it allows theme authors to lock down what is available in the Global Styles UI. For example, they could lock down editing color palettes, prevent users from applying custom borders etc.

If a theme has not opted to set contentSize/wideSize is that a choice not to expose them to users? Alternatively, should we have explicit settings properties in the theme.json to flag whether custom contentSize or wideSize values are accepted and the UI shown? I'm thinking along the lines of customFontSize.

@andrewserong
Copy link
Contributor

Is it just me?

Not just you! I find it confusing, too. If it's too awkward to do here, perhaps tweaking how and when we display explanatory information for this feature is best explored in a follow-up / separate PR at some stage? But I quite like "Set the width of the main content area" personally 👍

Was that the Flex markup showing, or did I miss something else?

Nope, that was all!

Alternatively, should we have explicit settings properties in the theme.json to flag whether custom contentSize or wideSize values are accepted and the UI shown?

Oh, that's an interest idea. I don't think I'd even really thought of locking down this part of the UI (I'd mostly been thinking about when themes want to lock down the post editor, rather than global styles). Perhaps a boolean in theme settings that defaults to true (that it's always editable) and then the theme can set it to false if need be? Personally I like the idea of folks being able to edit content / wide widths in any theme (along the lines of "designing in the site editor"), but yeah, it might be good to consider theme builder's requirements here 🤔

@tellthemachines
Copy link
Contributor Author

My understanding is that one of the features of theme.json is that it allows theme authors to lock down what is available in the Global Styles UI.

Hmmm, in that case it would make sense for themes be able to both set content sizes and stop users from overriding them. If so, and if

Alternatively, should we have explicit settings properties in the theme.json to flag whether custom contentSize or wideSize values are accepted and the UI shown?

this should probably also apply to the individual block controls, right?

And if we had something like this, we needn't assume that a theme without content sizes doesn't want users to be able to set them at all.

@tellthemachines
Copy link
Contributor Author

Update on the description: I tried to add a paragraph inside the ToolsPanel as indicated in the component readme example but it doesn't work with the styling:

Screen Shot 2022-07-20 at 11 54 31 am

I've created #42543 to report what seems to be a ToolsPanel bug.

I guess we can add the description as a separate PR once the issue is fixed?

I'm thinking the bit about allowing themes to explicitly control whether content and wide sizes are editable can also be tackled separately, as it'll probably generate a bit of discussion 😅

If that's the case, I think all other feedback on this PR has been addressed!

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

If that's the case, I think all other feedback on this PR has been addressed!

Yes, this PR is working nicely for me now, and I agree I think adding messaging and figuring out the appropriate behaviour for showing/hiding the controls are good candidates for follow-up PRs.

✅ Adjusting content and wide width is now treated in the ToolsPanel menu as a changed value if a user set value exists
✅ Clearing each value in the menu individually works correctly
✅ Clearing via the Reset all option works correctly for these two values
✅ Styling and behaviour of the Dimensions panel at the block level in global styles is as on trunk

LGTM, thanks for all the follow-up tweaks! 🎉

@aaronrobertshaw
Copy link
Contributor

I think we might be overcomplicating the addition of these controls to the panel. 🤔

Am I correct in understanding that the wrapping Flex was only to make the two controls share the same row in the panel?

The ToolsPanel has a two-column grid primarily for this purpose. ToolsPanelItem components default to spanning both columns given that was the majority use-case at the time the design was being implemented.

The same way the FlexItem currently provides a wrapper to assist in the icon positioning, a simple wrapper could be added within a HStack to achieve the same result. Not much of a difference but does mean slightly less fluff in the markup.

Finally, for the help text, this is a bit of an edge case. Normally, help text would relate to a single control and be included as a child within the ToolsPanelItem. Within the block editor inspector controls we don't have a lot of panels beginning with a description like some of the Global Styles panels so there hasn't been anything baked into the ToolsPanel for that.

In the example diff below I added a simple span-columns class for the global styles that could be shared across any top-level non-ToolsPanelItem components.

Click for example diff
diff --git a/packages/edit-site/src/components/global-styles/dimensions-panel.js b/packages/edit-site/src/components/global-styles/dimensions-panel.js
index a2f8822d66..e7af30623c 100644
--- a/packages/edit-site/src/components/global-styles/dimensions-panel.js
+++ b/packages/edit-site/src/components/global-styles/dimensions-panel.js
@@ -6,10 +6,10 @@ import {
 	__experimentalToolsPanel as ToolsPanel,
 	__experimentalToolsPanelItem as ToolsPanelItem,
 	__experimentalBoxControl as BoxControl,
+	__experimentalHStack as HStack,
 	__experimentalUnitControl as UnitControl,
 	__experimentalUseCustomUnits as useCustomUnits,
-	Flex,
-	FlexItem,
+	__experimentalView as View,
 } from '@wordpress/components';
 import { __experimentalUseCustomSides as useCustomSides } from '@wordpress/block-editor';
 import { Icon, positionCenter, stretchWide } from '@wordpress/icons';
@@ -193,65 +193,59 @@ export default function DimensionsPanel( { name } ) {
 	return (
 		<ToolsPanel label={ __( 'Dimensions' ) } resetAll={ resetAll }>
 			{ ( showContentSizeControl || showWideSizeControl ) && (
-				<Flex>
-					{ showContentSizeControl && (
-						<ToolsPanelItem
-							as={ FlexItem }
-							label={ __( 'Content size' ) }
-							hasValue={ hasUserSetContentSizeValue }
-							onDeselect={ resetContentSizeValue }
-							isShownByDefault={ true }
-						>
-							<Flex align="flex-end">
-								<FlexItem>
-									<UnitControl
-										label={ __( 'Content' ) }
-										labelPosition="top"
-										__unstableInputWidth="80px"
-										value={ contentSizeValue || '' }
-										onChange={ ( nextContentSize ) => {
-											setContentSizeValue(
-												nextContentSize
-											);
-										} }
-										units={ units }
-									/>
-								</FlexItem>
-								<FlexItem>
-									<Icon icon={ positionCenter } />
-								</FlexItem>
-							</Flex>
-						</ToolsPanelItem>
-					) }
-
-					{ showWideSizeControl && (
-						<ToolsPanelItem
-							as={ FlexItem }
-							label={ __( 'Wide size' ) }
-							hasValue={ hasUserSetWideSizeValue }
-							onDeselect={ resetWideSizeValue }
-							isShownByDefault={ true }
-						>
-							<Flex align="flex-end">
-								<FlexItem>
-									<UnitControl
-										label={ __( 'Wide' ) }
-										labelPosition="top"
-										__unstableInputWidth="80px"
-										value={ wideSizeValue || '' }
-										onChange={ ( nextWideSize ) => {
-											setWideSizeValue( nextWideSize );
-										} }
-										units={ units }
-									/>
-								</FlexItem>
-								<FlexItem>
-									<Icon icon={ stretchWide } />
-								</FlexItem>
-							</Flex>
-						</ToolsPanelItem>
-					) }
-				</Flex>
+				<span className="span-columns">
+					Set the width of the main content area.
+				</span>
+			) }
+			{ showContentSizeControl && (
+				<ToolsPanelItem
+					className="single-column"
+					label={ __( 'Content size' ) }
+					hasValue={ hasUserSetContentSizeValue }
+					onDeselect={ resetContentSizeValue }
+					isShownByDefault={ true }
+				>
+					<HStack alignment="flex-end">
+						<UnitControl
+							label={ __( 'Content' ) }
+							labelPosition="top"
+							__unstableInputWidth="80px"
+							value={ contentSizeValue || '' }
+							onChange={ ( nextContentSize ) => {
+								setContentSizeValue( nextContentSize );
+							} }
+							units={ units }
+						/>
+						<View>
+							<Icon icon={ positionCenter } />
+						</View>
+					</HStack>
+				</ToolsPanelItem>
+			) }
+			{ showWideSizeControl && (
+				<ToolsPanelItem
+					className="single-column"
+					label={ __( 'Wide size' ) }
+					hasValue={ hasUserSetWideSizeValue }
+					onDeselect={ resetWideSizeValue }
+					isShownByDefault={ true }
+				>
+					<HStack alignment="flex-end">
+						<UnitControl
+							label={ __( 'Wide' ) }
+							labelPosition="top"
+							__unstableInputWidth="80px"
+							value={ wideSizeValue || '' }
+							onChange={ ( nextWideSize ) => {
+								setWideSizeValue( nextWideSize );
+							} }
+							units={ units }
+						/>
+						<View>
+							<Icon icon={ stretchWide } />
+						</View>
+					</HStack>
+				</ToolsPanelItem>
 			) }
 			{ showPaddingControl && (
 				<ToolsPanelItem
diff --git a/packages/edit-site/src/components/sidebar/style.scss b/packages/edit-site/src/components/sidebar/style.scss
index b3992b7774..41960d3ee0 100644
--- a/packages/edit-site/src/components/sidebar/style.scss
+++ b/packages/edit-site/src/components/sidebar/style.scss
@@ -60,6 +60,10 @@
 	grid-column: span 1;
 }
 
+.edit-site-global-styles-sidebar .components-tools-panel .span-columns {
+	grid-column: 1 / -1;
+}
+
 .edit-site-global-styles-sidebar__blocks-group {
 	padding-top: $grid-unit-30;
 	border-top: $border-width solid $gray-200;

After applying the above diff, this is what I get:

Screen Shot 2022-07-20 at 3 07 51 pm

One thing to note is that the panel's CSS grid means spacing between the "Set the width of the main content area." text and the related controls. That might not be desired so please take the suggested diff with a grain of salt.

If nothing else, I hope that helps illustrate a different approach to adding controls via the ToolsPanel.

@tellthemachines
Copy link
Contributor Author

In the example diff below I added a simple span-columns class for the global styles that could be shared across any top-level non-ToolsPanelItem components.

Oooh I see that works well! Would be good to add some tips along those lines to the ToolsPanel readme. Also please feel free to push that diff to this branch 😄

@aaronrobertshaw
Copy link
Contributor

Also please feel free to push that diff to this branch

Done 👍

Would be good to add some tips along those lines to the ToolsPanel readme.

I'll make that happen 🙂

@paaljoachim
Copy link
Contributor

paaljoachim commented Jul 24, 2022

Dropping by for a quick look.
Viewing the initial gif I see that reset option has been hidden away behind the 3 dots menu.
This is though very hidden away. Having the option as it was earlier fully visible made it clear that it is possible to reset the values that have been added. Having it inside the 3 dot menu it is easy to think that the option has been removed.

Some options are natural to add inside the 3 dot menu. Other options should in general always be visible.

@femkreations femkreations added the Needs User Documentation Needs new user documentation label Sep 3, 2022
@andrewserong andrewserong added the [Feature] Layout Layout block support, its UI controls, and style output. label Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Layout Layout block support, its UI controls, and style output. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow users to edit the "default layout" in the Global Styles panel
5 participants