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

Try using variable for root padding value #39926

Closed
wants to merge 25 commits into from

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Mar 31, 2022

What?

  • Adds a setting to theme.json so themes can opt in to the new behaviour of root padding
  • Adds a default non-zero value for root padding
  • Outputs that value as a custom property on the root element
  • Allows full-width blocks to compensate for that value with negative margins

Why?

Partly fixes #35607 - only addresses the root block part of the equation. #39871 deals with full width in nested blocks.
Fixes #35884 for themes that opt into this change.

Themes shouldn't have to add their own rules to make full width alignments work properly.

How?

First, we're setting a default padding value in theme.json. It can be overridden by any user-set padding in the global styles interface.

Then, on the server side, we set top and bottom padding to the root container, but left and right padding to the direct children of root. This is so that those children still stretch full width as expected, but their children get the effects of the padding.

On the site editor side, the direct children of root container get the left/right padding applied, so they still appear as full-width. (If we wanted to only apply full-width to some of the root children, maybe we could add padding to the root and enable the align control on them so they could be set manually? And add negative margins to alignfull blocks)

On the post editor side, the root container also gets its left/right padding, and any alignfull children are fixed with negative margins.

Testing Instructions

  1. Add "useRootVariables": true to the settings of your theme's theme.json to enable these changes.
  2. Add a few layout blocks (e.g. Group) to the post and the site editor
  3. Make some of those blocks full width
  4. Check that there's a default padding value in both editors and front end, and full width blocks behave as expected
  5. Change root padding value in the site editor by going to Global Styles > Layout > Padding
  6. Check that new padding value works in both editors and front end.
  7. Check that removing "useRootVariables": true from theme.json reverts to the previous behaviour.

Screenshots or screencast

ezgif com-gif-maker (5)

@github-actions
Copy link

github-actions bot commented Mar 31, 2022

Size Change: +5.46 kB (0%)

Total Size: 1.24 MB

Filename Size Change
build/block-editor/index.min.js 150 kB -312 B (0%)
build/block-editor/style-rtl.css 15 kB -140 B (-1%)
build/block-editor/style.css 15 kB -138 B (-1%)
build/block-library/blocks/comments-query-loop/editor-rtl.css 0 B -95 B (removed) 🏆
build/block-library/blocks/comments-query-loop/editor.css 0 B -95 B (removed) 🏆
build/block-library/blocks/cover/style-rtl.css 1.53 kB -1 B (0%)
build/block-library/blocks/cover/style.css 1.53 kB -1 B (0%)
build/block-library/blocks/latest-posts/style-rtl.css 463 B +16 B (+4%)
build/block-library/blocks/latest-posts/style.css 462 B +16 B (+4%)
build/block-library/blocks/navigation/style-rtl.css 1.95 kB +14 B (+1%)
build/block-library/blocks/navigation/style.css 1.94 kB +14 B (+1%)
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB +133 B (+5%) 🔍
build/block-library/blocks/post-comments/style-rtl.css 527 B +16 B (+3%)
build/block-library/blocks/post-comments/style.css 527 B +16 B (+3%)
build/block-library/editor-rtl.css 10.2 kB -2 B (0%)
build/block-library/editor.css 10.3 kB -2 B (0%)
build/block-library/index.min.js 179 kB +2.19 kB (+1%)
build/block-library/style-rtl.css 11.5 kB +41 B (0%)
build/block-library/style.css 11.5 kB +38 B (0%)
build/blocks/index.min.js 47.1 kB +72 B (0%)
build/components/index.min.js 227 kB +4.39 kB (+2%)
build/components/style-rtl.css 15 kB +41 B (0%)
build/components/style.css 15 kB +42 B (0%)
build/compose/index.min.js 11.4 kB +225 B (+2%)
build/core-data/index.min.js 14.6 kB +36 B (0%)
build/customize-widgets/index.min.js 11 kB -5 B (0%)
build/data/index.min.js 7.66 kB -991 B (-11%) 👏
build/dom/index.min.js 4.59 kB +14 B (0%)
build/edit-navigation/index.min.js 15.8 kB -10 B (0%)
build/edit-post/index.min.js 30.1 kB -37 B (0%)
build/edit-post/style-rtl.css 7.02 kB -85 B (-1%)
build/edit-post/style.css 7.02 kB -84 B (-1%)
build/edit-site/index.min.js 47.7 kB +199 B (0%)
build/edit-widgets/index.min.js 16.3 kB -45 B (0%)
build/editor/index.min.js 38.4 kB -53 B (0%)
build/editor/style-rtl.css 3.67 kB -39 B (-1%)
build/editor/style.css 3.67 kB -36 B (-1%)
build/element/index.min.js 4.3 kB +12 B (0%)
build/nux/index.min.js 2.1 kB -19 B (-1%)
build/preferences/index.min.js 1.32 kB +121 B (+10%) ⚠️
build/rich-text/index.min.js 11.2 kB +12 B (0%)
build/widgets/index.min.js 7.21 kB -5 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.77 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 6.51 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-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 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/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 445 B
build/block-library/blocks/button/editor.css 445 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 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 127 B
build/block-library/blocks/comment-template/style.css 127 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 546 B
build/block-library/blocks/cover/editor.css 547 B
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 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 353 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 961 B
build/block-library/blocks/gallery/editor.css 964 B
build/block-library/blocks/gallery/style-rtl.css 1.51 kB
build/block-library/blocks/gallery/style.css 1.51 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 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 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 529 B
build/block-library/blocks/image/style.css 535 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 199 B
build/block-library/blocks/latest-posts/editor.css 198 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 708 B
build/block-library/blocks/navigation-link/editor.css 706 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 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 375 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/view.min.js 395 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 69 B
build/block-library/blocks/post-comments-form/editor.css 69 B
build/block-library/blocks/post-comments-form/style-rtl.css 521 B
build/block-library/blocks/post-comments-form/style.css 521 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-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 721 B
build/block-library/blocks/post-featured-image/editor.css 721 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 323 B
build/block-library/blocks/post-template/style.css 323 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 369 B
build/block-library/blocks/query/editor.css 369 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 397 B
build/block-library/blocks/search/style.css 398 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 140 B
build/block-library/blocks/separator/editor.css 140 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 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 759 B
build/block-library/blocks/site-logo/editor.css 759 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 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.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 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 504 B
build/block-library/blocks/table/editor.css 504 B
build/block-library/blocks/table/style-rtl.css 625 B
build/block-library/blocks/table/style.css 625 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 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 149 B
build/block-library/blocks/template-part/editor.css 149 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 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 993 B
build/block-library/common.css 990 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/theme-rtl.css 689 B
build/block-library/theme.css 694 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/customize-widgets/style-rtl.css 1.39 kB
build/customize-widgets/style.css 1.39 kB
build/data-controls/index.min.js 663 B
build/date/index.min.js 32 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/edit-navigation/style-rtl.css 4.05 kB
build/edit-navigation/style.css 4.05 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-site/style-rtl.css 7.95 kB
build/edit-site/style.css 7.93 kB
build/edit-widgets/style-rtl.css 4.41 kB
build/edit-widgets/style.css 4.4 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 6.62 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.83 kB
build/keycodes/index.min.js 1.41 kB
build/list-reusable-blocks/index.min.js 1.75 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.94 kB
build/notices/index.min.js 957 B
build/nux/style-rtl.css 751 B
build/nux/style.css 749 B
build/plugins/index.min.js 1.98 kB
build/preferences-persistence/index.min.js 2.16 kB
build/primitives/index.min.js 949 B
build/priority-queue/index.min.js 628 B
build/react-i18n/index.min.js 704 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.69 kB
build/reusable-blocks/index.min.js 2.24 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.52 kB
build/token-list/index.min.js 668 B
build/url/index.min.js 1.99 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 280 B
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.07 kB

compressed-size-action

'--wp--style--padding-top' => array( 'spacing', 'padding', 'top' ),
'--wp--style--padding-right' => array( 'spacing', 'padding', 'right' ),
'--wp--style--padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
'--wp--style--padding-left' => array( 'spacing', 'padding', 'left' ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why this only seems to affect the root styles 🤔

"right": "17px",
"bottom": "17px",
"left": "17px"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "padding" object is the only real addition to this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this like a demo padding that applies to all themes? won't this be a breaking change for existing themes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I guess it could be if the theme doesn't define any root padding. I was mainly thinking of a fix for #35884, but perhaps that should be post editor specific.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this is problem for themes that aren't opting in to site padding. I think we'll need to add it programatically.

@@ -319,6 +319,11 @@
}
}

.is-root-container > .alignfull {
margin-right: calc(var(--wp--style--padding-right) * -1);
margin-left: calc(var(--wp--style--padding-left) * -1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we should have a fallback value here in case the variable doesn't exist.

'--wp--style--padding-top': {
value: [ 'spacing', 'padding', 'top' ],
support: [ 'spacing', 'padding' ],
rootOnly: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels super hacky, but without it these styles get applied to all blocks that have padding set on them. Any ideas welcome!

Copy link
Member

@ramonjd ramonjd Apr 1, 2022

Choose a reason for hiding this comment

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

Should global styles also output these vars for specific blocks?

I bumped the padding value of the Group block in global styles and I see this in the global-styles-inline-css style tag:

body {
	...
	--wp--style--padding-top: 173px;
	--wp--style--padding-right: 173px;
	--wp--style--padding-bottom: 173px;
	--wp--style--padding-left: 173px;
	--wp--style--block-gap: 1.5rem;
}
...
.wp-block-group {
	--wp--style--padding-top: 142px;
	--wp--style--padding-right: 142px;
	--wp--style--padding-bottom: 142px;
	--wp--style--padding-left: 142px;
}

The editor reflects the changes but the frontend doesn't, because, I guess, we'd need to either update the blocks' CSS to use these vars or print it on the fly somewhere in the backend.

On a related note, gap also gets special treatment in WP_Theme_JSON_Gutenberg via 'blockGap' => 'top',, the effect of which is that --wp--style--block-gap is only rendered at the "top" (or root) level in global styles. Effectively the body tag.

But we also want block-level global styles, when set, to override any root value. It's something we're trying resolve over at #39870

It seems like we do need some sort of flag that says "Hey, this property only lives at the root level, so output its style rule in the body tag and nowhere else".

I'm not sure what that would look like yet, maybe a const VALID_TOP_LEVEL_STYLES in WP_Theme_JSON_Gutenberg that explicitly defines root-level-only styles 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should global styles also output these vars for specific blocks?

Oooooh no it shouldn't! It's actually outputting the variables instead of the properties in the front end now, and that's messing with some of the negative margin calculations 😫

It seems like we do need some sort of flag that says "Hey, this property only lives at the root level, so output its style rule in the body tag and nowhere else".

Yup, we definitely need something like this. I was playing around with it on the editor side here, not realising it would also be needed on the server side.

I'm not sure what that would look like yet, maybe a const VALID_TOP_LEVEL_STYLES in WP_Theme_JSON_Gutenberg that explicitly defines root-level-only styles

Can we make do with the "top" value in VALID_STYLES solution we have currently? What shortcomings do you see with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I made some changes that should fix the block-level global styles issue.

The thing with padding is that we only need it to be a variable at the root level, so we can easily apply it to all the places we need it: as padding on full-width root level blocks, or as negative margin on their full-width children. I'm not sure if block gap works exactly like that? (I only read through the code of #39870 today, but will look at it more in-depth on Monday).

Copy link
Member

Choose a reason for hiding this comment

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

The thing with padding is that we only need it to be a variable at the root level, so we can easily apply it to all the places we need it: as padding on full-width root level blocks, or as negative margin on their full-width children. I'm not sure if block gap works exactly like that?

Block gap is a smidge different, for sure.

Support for gap in non root-level global styles was removed, and in sanitized() it's being excluded from the non-root level blocks and elements in the merged theme json. That means that, right now, there's no need to worry about whether the styles will be correctly output.

The side-effect of that removal was that block-level global styles cannot define gap values; this side-effect was, I believe, unintended. This is the "bug" that #39870 is trying to address.

This is a long-winded way of saying that I'd like to take block gap in the same direction you're taking padding 😄 so I think there might be similarities...

Copy link
Contributor

@scruffian scruffian Apr 7, 2022

Choose a reason for hiding this comment

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

There are many cases where we might want the site padding to match other parts of the site - for example the gaps between navigation items, template parts and galleries etc. This is an important consideration in theme design - if these spaces all defaulted to something that matched it would mean that designs would look good without needing to tweak all these things individually as we do today cc @kjellr @beafialho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are many cases where we might want the site padding to match other parts of the site - for example the gaps between navigation items, template parts and galleries etc.

That would be a theme level decision though, wouldn't it? I'd imagine the theme would set a global spacing variable and use it to set both root and block padding (or gap, or whatever else) in theme.json and in the theme stylesheet.

The root padding we're dealing with here is a top-level style so it's only attached to the body. This PR changes the output from a straightforward padding declaration to a custom property, mainly so we can use its value to offset full-width blocks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's a theme level decision, but I think its the kind of thing that having a good default for would really help - for example if this setting defaulted to --wp--style--block-gap then all these spacing elements would match by default.

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, I see!

I changed the default values here to use the block gap variable - does that work better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that look good!

@@ -190,6 +191,10 @@ function getStylesDeclarations( blockStyles = {} ) {
[]
);

if ( isRoot ) {
return output;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a total hack 😅 to avoid the output of actual padding properties by the style engine logic below. Might be better to work out a way of getting the style engine to output the variables instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with the hack here, personally — it shouldn't be too hard to migrate the logic over to a separate file in the style engine package after the fact in a follow-up if you don't want to worry about it in this PR.

@jasmussen
Copy link
Contributor

Nice one, thanks so much for taking this on, it's an important quality of life fix for block themes!

Question: does it only work with root level full-wide blocks, though? I can't seem to get it to work in this featured image use case, where the featured image is part of post content:
root padding

@MaggieCabrera
Copy link
Contributor

/cc @WordPress/block-themers

nodesWithStyles.forEach( ( { selector, styles } ) => {
const declarations = getStylesDeclarations( styles );
const isRoot = ROOT_BLOCK_SELECTOR === selector;
const declarations = getStylesDeclarations( styles, isRoot );
Copy link
Member

Choose a reason for hiding this comment

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

@tellthemachines
Copy link
Contributor Author

Thanks for testing this @jasmussen! I'm not sure I fully get what's going on in that gif 😅 How does the Query Loop go inside the Post Content? Could you share some basic steps to set up that scenario?

does it only work with root level full-wide blocks, though?

This PR only addresses root level padding, and its effects on full width blocks that are direct children either of wp-site-blocks or of the post content. There's a separate effort over at #39871 for adjustments to padding/full width in nested blocks (where full width is expected to be relative to a container block and not the viewport). I should have mentioned that in the PR description 🤦

@tellthemachines
Copy link
Contributor Author

One thing that's not working quite as expected here is the top/bottom padding values added to editor-styles-wrapper in the site editor: when changing the root padding in global styles, they only update on page refresh. I'm pretty sure the rule adding those styles is coming from the block editor settings, but I haven't found where it gets added to the settings yet. Any tips on that appreciated!

@jasmussen
Copy link
Contributor

Thanks for testing this @jasmussen! I'm not sure I fully get what's going on in that gif 😅 How does the Query Loop go inside the Post Content? Could you share some basic steps to set up that scenario?

I haven't been following too closely recent changes to post content or query loop, but here's a GIF walking through activating the empty theme and then selecting the singular template and seeing the issue:

steps

But I see the issue even if I drag the Query loop outside of the Post Content block:

Screenshot 2022-04-01 at 08 22 33

This PR only addresses root level padding, and its effects on full width blocks that are direct children either of wp-site-blocks or of the post content. There's a separate effort over at #39871 for adjustments to padding/full width in nested blocks (where full width is expected to be relative to a container block and not the viewport). I should have mentioned that in the PR description 🤦

Oh! My mistake. Ignore everything I said above 🙈

Thanks for working on this!

'margin-right' => array( 'spacing', 'margin', 'right' ),
'margin-bottom' => array( 'spacing', 'margin', 'bottom' ),
'margin-left' => array( 'spacing', 'margin', 'left' ),
'padding' => array( 'spacing', 'padding' ),
Copy link
Member

Choose a reason for hiding this comment

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

Should we give the same treatment to 'padding'?

If I add a padding value to theme.json,

                "spacing": {
                        "blockGap": "1.5rem",
                        "padding": "88px"
                },

I see the following:

body {
	padding: 88px;
	--wp--style--block-gap: 1.5rem;
}

Not sure what the intention is here, but If there were another CSS var for a single padding value, e.g., --wp--style--root--padding, we could use it as a fallback, e.g.,

padding-top: var(--wp--style--root--padding-top, var(--wp--style--root--padding))

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, good point, if the theme just sets "padding" my carefully crafted logic will fail 😂 😭

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We won't be able to use --wp--style--root--padding directly as a fallback though, because it might be a multi-value format e.g. 32px 42px. Not quite sure how best to handle that - is that something that we've solved for gap already?

Copy link
Member

Choose a reason for hiding this comment

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

We won't be able to use --wp--style--root--padding directly as a fallback though, because it might be a multi-value format e.g. 32px 42px.

Oh, excellent point. 😆 Good catch.

I'm not sure splitting by ' ' would be robust enough (I tried in an old gap commit and was told the same).

As for gap, the gap value can be an array, so we check for that and split the values accordingly.

See: https://github.com/WordPress/gutenberg/blob/trunk/lib/block-supports/layout.php#L70

Otherwise we assume string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, here we'll always have a string so that won't work.

If we could identify which of the variables are set, we could maybe output different styles accordingly, but I'm not sure how that would work on the editor side (the whole editor side of this PR is still quite iffy though, so maybe a solution will present itself in time)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking better of this, we always need to know the specific values for left and right padding because we need them for the negative margins on full width blocks. For that we need to separate the multi-value padding string into its component parts, so I think we'll have to do it the messy way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code below to separate out the values from a shorthand padding declaration. This currently only works on the server side; looking into how to implement it for the editor now.

* @return {Array} An array of style declarations.
*/
function getStylesDeclarations( blockStyles = {} ) {
function getStylesDeclarations( blockStyles = {}, isRoot = false ) {
Copy link
Member

Choose a reason for hiding this comment

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

Ignorable observation: would it make sense to keep the selector arg consistent with how we're doing in the compute_style_properties() PHP method?

That is, passing the selector and doing the check inside this method?

ROOT_BLOCK_SELECTOR === selector

}

// If a variable value is added to the root, the corresponding property should be removed.
foreach ( $root_variable_duplicates as $duplicate ) {
Copy link
Member

@ramonjd ramonjd Apr 4, 2022

Choose a reason for hiding this comment

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

I've been playing with an alternative for block gap, in which I've created a second array const ROOT_PROPERTIES_METADATA that contains all the possible root properties.

In this case it would look like this:

const ROOT_PROPERTIES_METADATA = array(
    // all the rest here...
    // except "padding", "padding-top" etc, which are replaced by the following CSS vars
    '--wp--style--root--padding' => array( 'spacing', 'padding' ),
    '--wp--style--root--padding-top' => array( 'spacing', 'padding', 'top' ),
    '--wp--style--root--padding-right' => array( 'spacing', 'padding', 'right' ),
    '--wp--style--root--padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
    '--wp--style--root--padding-left' => array( 'spacing', 'padding', 'left' ),
);

Then the only change to compute_style_properties() method would be:

f ( null === $properties ) {
    $properties =  static::ROOT_BLOCK_SELECTOR === $selector ? static::ROOT_PROPERTIES_METADATA : static::PROPERTIES_METADATA;
}

Just noting for reference! It might be completely bonkers.

Seems to work for padding at least 😆 but haven't battle tested it yet. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooooh that's a great idea! Much neater logic.

'margin-right' => array( 'spacing', 'margin', 'right' ),
'margin-bottom' => array( 'spacing', 'margin', 'bottom' ),
'margin-left' => array( 'spacing', 'margin', 'left' ),
'padding' => array( 'spacing', 'padding' ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code below to separate out the values from a shorthand padding declaration. This currently only works on the server side; looking into how to implement it for the editor now.

.is-root-container > .alignfull {
margin-right: calc(var(--wp--style--root--padding-right) * -1);
margin-left: calc(var(--wp--style--root--padding-left) * -1);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where it gets really tricky to handle shorthand padding values. Perhaps we can add this rule in dynamically somewhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not wrong it's not possible to have "align full" in the site editor (or any editor) unless there's a layout defined in the root which only happens in the post editor if the theme.json has "layout" key right? Makes me wonder if this should be moved to the edit-post or something like that to explain its purpose (maybe add a comment)

'--wp--style--padding-top': {
value: [ 'spacing', 'padding', 'top' ],
support: [ 'spacing', 'padding' ],
rootOnly: true,
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, thanks for the reminder @jasmussen ! I'd forgotten about the overlay special case. Do you know of anywhere else where we might need to apply root padding?

@jasmussen
Copy link
Contributor

Do you know of anywhere else where we might need to apply root padding?

Nothing comes to mind, but I would note that I could see the overlay having a variety of behaviors some time the future, such as being an overlay that opens from the right and scrims the content, or a modal in the center. So it might not always need root padding. That is, it's probably fine to set it by default, and then let the user customize that padding on the modal overlay directly — and definitely a future concern, nothing for this PR, just context.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Here are a few things I noticed.

I'm using a full aligned image inside a group block with a layout defined.

  • If I put my group block at the root level, everything works as expected on the frontend
  • In the site editor root blocks I don't see any padding around random root blocks (not sure why).
  • If I make my group block a template part, the full width images are not stretched anymore in the frontend.

In my singular template, I have a "post-content" block with layout but it's inside a group block to be able to apply some styling (background... and add some content after it...)

When I do that, full width aligned images in a post are not full width in the frontend, I can see the root padding around them.

"right": "17px",
"bottom": "17px",
"left": "17px"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this like a demo padding that applies to all themes? won't this be a breaking change for existing themes?

.is-root-container > .alignfull {
margin-right: calc(var(--wp--style--root--padding-right) * -1);
margin-left: calc(var(--wp--style--root--padding-left) * -1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not wrong it's not possible to have "align full" in the site editor (or any editor) unless there's a layout defined in the root which only happens in the post editor if the theme.json has "layout" key right? Makes me wonder if this should be moved to the edit-post or something like that to explain its purpose (maybe add a comment)

} else if ( !! properties && isString( styleValue ) && rootOnly ) {
const separateValues = styleValue.split( ' ' );

const sortedBoxValues = {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this default value about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably decide on a fallback value if neither theme nor user provides one; I just used 17px throughout this PR to make debugging easier. But here, I guess it could be 0 or even null, because we always fill in a value for all the properties below.

@tellthemachines
Copy link
Contributor Author

Thanks for testing @youknowriad !

In the site editor root blocks I don't see any padding around random root blocks (not sure why).

That was a bug with variable names being kebab-cased, I've fixed it now.

If I make my group block a template part, the full width images are not stretched anymore in the frontend.

This PR is only dealing with full-aligned blocks that are direct children of root blocks. When the group is wrapped in a template part, it's no longer a root block so the styles don't apply anymore.Non-root full width layouts are being addressed in #39871, as they require a different logic (I think; at least I haven't found a way to address both simultaneously 😅 )

When I do that, full width aligned images in a post are not full width in the frontend, I can see the root padding around them.

That's the same problem as above with the nesting. I'm hoping that we might also be able to address that scenario in #39871. Will look into it better tomorrow!

@scruffian
Copy link
Contributor

One note for people testing this - almost every theme already contains CSS to control this, so you will likely see some conflicts between that CSS and this PR unless you test with emptytheme. That's not to say we shouldn't test with other themes - we need to, to check that there aren't any regressions...

@scruffian
Copy link
Contributor

I tested this with TT2 and on Archeo using this PR. It doesn't seem to be working correctly. Full width items aren't going to the browser edge, and don't have the correct padding applied.

I see the problem in the single post template - the post content template has the "inherit default" property set, but then the CSS only targets direct children of .wp-site-blocks, not children of other blocks that inherit the default layout. I'm not sure if this was always an issue or if the rebase introduced it. I'm happy to help work on it if that would be useful?

@ramonjd
Copy link
Member

ramonjd commented Apr 27, 2022

I'm not sure if this was always an issue or if the rebase introduced it.

Thanks for spending time on this. It's possible I borked something during the merge with trunk. It was a bit hairy due to all the compat changes for WordPress 6.0. I'll compare with a26beda and see if I can spot any omissions

I'm happy to help work on it if that would be useful

That would be very useful, thank you! 😄 @tellthemachines is taking a break so it'd be great to keep this one rolling.

@ramonjd
Copy link
Member

ramonjd commented Apr 28, 2022

It was a bit hairy due to all the compat changes for WordPress 6.0. I'll compare with a26beda and see if I can spot any omissions

I couldn't find anything glaring (I checked every change since the merge).

The only spot I'm suspicious about is the root CSS here: https://github.com/WordPress/gutenberg/pull/39926/files#diff-1654d2da9097b71ac77806bbc505483b794371e8a2ff3ba152ec8610c2663ec6R438

The main challenge was merging after 49e4a4f... so maybe something needs to be updated to take into account that commit.

@jffng
Copy link
Contributor

jffng commented Apr 28, 2022

Full width items aren't going to the browser edge, and don't have the correct padding applied.

I gave the latest version and can verify this on TT2. To add a little more context:

As @scruffian mentions, this PR only targets direct children of wp-site-blocks, i.e.

.wp-site-blocks > * > .alignfull

TT2's templates wrap the post content block inside of another group block. This is for good reason — to include a main element on the page, required for accessibility. This means alignfull blocks that are direct children of post content are actually two levels deep:

.wp-site-blocks > main.wp-group > .wp-block-post-content > .alignfull

The current alignment CSS in TT2 gets around this by being more general with its selector:

.wp-site-blocks .alignfull

@scruffian
Copy link
Contributor

scruffian commented Apr 28, 2022

TT2's templates wrap the post content block inside of another group block. This is for good reason — to include a main element on the page, required for accessibility. This means alignfull blocks that are direct children of post content are actually two levels deep:

I added a commit to address this. It would be great if more people could test to find other issues that I missed :). Feel free to revert if it breaks stuff.

Copy link
Contributor

@jffng jffng left a comment

Choose a reason for hiding this comment

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

I added a commit to address this.

Tested a variety of scenarios and full width patterns in TT2, looking good to me. Would love to try this out in the wild and see how it works in practice, also safer that it's opt in under the "useRootVariables" setting.

@@ -372,7 +372,7 @@ protected function get_block_classes( $style_nodes ) {
if ( $use_root_vars ) {
$block_rules .= '.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); }';
$block_rules .= '.wp-site-blocks > * { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }';
$block_rules .= '.wp-site-blocks > * > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }';
$block_rules .= '.wp-site-blocks > * .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); width: unset; }';
Copy link
Contributor

Choose a reason for hiding this comment

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

This basically targets all align full blocks at all levels. I'm not sure that's what we want, I thought this was only about the top level ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

The aim of the PR originally was just top level blocks and those inside post content. Blocks inside post content weren't working which is why I added this line. I know this will broaden the scope of the CSS, but this is the CSS that we have been using in all block themes, so it seems fairly safe to try.

@@ -240,6 +241,8 @@
}
},
"styles": {
"spacing": { "blockGap": "24px" }
"spacing": {
"blockGap": "24px"
Copy link
Contributor

Choose a reason for hiding this comment

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

I removed the default padding from here as it would impact all themes, which would be a problem.

@scruffian
Copy link
Contributor

I spent quite a bit of time on this today. In the end I took the CSS we currently use in block themes and then adapted it. This means we use the class names for several blocks that have different behaviours (columns, cover and group). I think it's necessary to give these specific blocks a different behaviour as we need to stop the content from touching the edges in these blocks.

I'd be grateful to hear what others think. Can this also replace #39871?

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.

Thanks a lot for picking this up and running with it @scruffian 🙇

It's mainly working as expected for me (aside from the doubling up on padding styles in body and .wp-site-blocks).

I'd be keen to hear from @youknowriad and others on whether the additional padding-specific changes in theme json class are okay, or whether they have the potential to create barriers to future refactoring.

It seems like it addresses a big headache for theme authors, so I think the tradeoffs could be worth it.

if ( $use_root_vars ) {
$block_rules .= '.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); }';

$block_rules .= '.wp-site-blocks,
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we need to remove the padding applied directly to .wp-site-blocks

The padding set in theme.json and global styles are also set in the root selector (body) via static::to_ruleset above.

Screen Shot 2022-05-02 at 1 28 50 pm

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for testing. I don't think they are applied to body, only the variables are defined on the body. In your screenshot one section is the vertical padding and the other is the horizontal padding :)

);

$declarations = array_merge( $declarations, $all_properties );

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if it's been brought up yet, but this is a lot of bespoke code for root padding values future iterations. I'm not sure where we'd put it in future iterations.

I'm not saying it's a blocker, just curious to learn whether we need a separate processing method for root block selectors to keep these methods uncluttered.

I'd speculate that root style CSS vars could be useful elsewhere, e.g., --wp--style--root--block-gap

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I agree a separate method for root selectors might make this tidier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done!

@scruffian
Copy link
Contributor

I squashed and rebased this and moved it to #40926 to keep the history here in tact. I think it's in a good place.

@scruffian scruffian force-pushed the try/root-padding-fix branch from dd60c36 to 0218267 Compare May 26, 2022 09:59
@scruffian
Copy link
Contributor

I removed my commits from this so the original intent is clear.

@scruffian
Copy link
Contributor

I tried combining this PR with #39871. The problem is that the way this works at the moment in trunk is that the outermost block that has "inherit default layout" has to cancel out the padding set on the root. This is challenging because the outermost block to "inherit default layout" is often not a child of ".wp-site-blocks".

If we want to keep this behaviour, I think what we need is to find a way to determine if a block is wrapped in other "inherit default layout" blocks. If it isn't then it is the outermost block and needs to have negative margins to counter the root padding.

@tellthemachines
Copy link
Contributor Author

Closing this PR as #42034 has an updated version of the same solution.

tellthemachines added a commit that referenced this pull request Jul 1, 2022
@scruffian scruffian deleted the try/root-padding-fix branch July 1, 2022 06:36
tellthemachines added a commit that referenced this pull request Jul 1, 2022
tellthemachines added a commit that referenced this pull request Jul 6, 2022
tellthemachines added a commit that referenced this pull request Jul 8, 2022
tellthemachines added a commit that referenced this pull request Jul 11, 2022
tellthemachines added a commit that referenced this pull request Jul 12, 2022
tellthemachines added a commit that referenced this pull request Jul 15, 2022
* Layout blockGap: Try using classnames to support block-level gap in theme.json

Try implementing partially in editor

Try adding block classname to the container class to deal with specificity, remove fallback gap

Add fallback gap styles rendered at root

Move changes to theme.json class 'up' to 6-1 file

Fix rendering block-level blockGap set in the block's attributes in the post editor

Implement changes in site editor / global styles comparable to PHP changes

Try moving some of the layout definitions to theme.json

Move layout style generation to a separate function

Implement theme.json definitions approach in the site editor, ensure styles load correctly in the post editor

Remove class duplication, use classname stored in theme.json instead of hard-coded classname

Support split row/column values at the block level, and include output of the legacy CSS variable for backwards compatibility

Ensure CSS variable is only output if gap support is opted-in

Tweak tests

Whitespace fix

Update test

Remove duplication block class from server-rendered output, update snapshot

Fix failing PHP test

Attempt to fix PHP test again

Manually fix snapshot

Fix PHP linting issue

Linting

Reorganise rules in theme.json

Remove dead code

Render base styles and only output container classes and styles if unique values are generated

Move blockGap styles in global styles to a separate getLayoutStyles function

Move layout_definitions up so that it's always available to base styles

Linting fixes

Update test snapshot

Add baseStyles output to global styles

Remove test snapshot

Update layout supports to return a CSS string instead of a component, add check that string is non-empty before outputting container classnames and style tags

Update flex layout to only output styles if unique values are set

Fix is-root-container styling in post editor

Update flex/flow layouts to look up layout definitions to generate gap styling

Move blockGap JS logic to a shared utility function, add tests

Add test in case layoutDefinitions is undefined

Add minimal tests that flex and flow layouts that don't contain non-default values return empty strings

Fix rebase in 6-1.php file

Consolidate JS layout classnames generation

Further consolidate classname generation

Implement outputting non-default layout gap for classic themes

Update fallback gap logic so that block themes that opt-out of blockGap but opt-in to wp-block-styles still get flex layout gap styles

Fix Columns fallback gap styles in classic themes

Ensure base layout styles are available in the editor for classic themes

Fix root gap value

Fix linting issues

Fix linting issue

Add a phpunit test for outputting layout styles based on layout definitions in theme.json

Add additional tests, ensure base styles are still output so that alignments continue to function

Remove todo items

Add layout selector regex, css declaration check

Add additional logical margin properties to allow list

Fix flex-wrap rule in JS version of flex layout

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

Rename default_layout to global_layout_settings

Rename blockGapStyles to spacingStyles

Fix rebase issues

Fix linting issues

Fix linting again

* Ensure blockGap controls are not exposed in global styles when experimental skip serializiation is used.

This ensures that the Gallery block is not exposed in the global styles UI, as its blockGap values are proceeded individually at the block level. Support for the Gallery block in global styles will be looked into in future follow-ups.

* Fix linting issue

* Implement fallback behaviour in site editor where default flex gap is still rendered in themes without blockGap but with wp-block-styles

* Remove connection to wp-block-styles so that fallback flex layout styles are always output

* Update resolver class to add an empty blockGap placeholder for a block, if it provides a default blockGap value

* Layout blockGap: Try using classnames to support block-level gap in theme.json

Try implementing partially in editor

Try adding block classname to the container class to deal with specificity, remove fallback gap

Add fallback gap styles rendered at root

Move changes to theme.json class 'up' to 6-1 file

Fix rendering block-level blockGap set in the block's attributes in the post editor

Implement changes in site editor / global styles comparable to PHP changes

Try moving some of the layout definitions to theme.json

Move layout style generation to a separate function

Implement theme.json definitions approach in the site editor, ensure styles load correctly in the post editor

Remove class duplication, use classname stored in theme.json instead of hard-coded classname

Support split row/column values at the block level, and include output of the legacy CSS variable for backwards compatibility

Ensure CSS variable is only output if gap support is opted-in

Tweak tests

Whitespace fix

Update test

Remove duplication block class from server-rendered output, update snapshot

Fix failing PHP test

Attempt to fix PHP test again

Manually fix snapshot

Fix PHP linting issue

Linting

Reorganise rules in theme.json

Remove dead code

Render base styles and only output container classes and styles if unique values are generated

Move blockGap styles in global styles to a separate getLayoutStyles function

Move layout_definitions up so that it's always available to base styles

Linting fixes

Update test snapshot

Add baseStyles output to global styles

Remove test snapshot

Update layout supports to return a CSS string instead of a component, add check that string is non-empty before outputting container classnames and style tags

Update flex layout to only output styles if unique values are set

Fix is-root-container styling in post editor

Update flex/flow layouts to look up layout definitions to generate gap styling

Move blockGap JS logic to a shared utility function, add tests

Add test in case layoutDefinitions is undefined

Add minimal tests that flex and flow layouts that don't contain non-default values return empty strings

Fix rebase in 6-1.php file

Consolidate JS layout classnames generation

Further consolidate classname generation

Implement outputting non-default layout gap for classic themes

Update fallback gap logic so that block themes that opt-out of blockGap but opt-in to wp-block-styles still get flex layout gap styles

Fix Columns fallback gap styles in classic themes

Ensure base layout styles are available in the editor for classic themes

Fix root gap value

Fix linting issues

Fix linting issue

Add a phpunit test for outputting layout styles based on layout definitions in theme.json

Add additional tests, ensure base styles are still output so that alignments continue to function

Remove todo items

Add layout selector regex, css declaration check

Add additional logical margin properties to allow list

Fix flex-wrap rule in JS version of flex layout

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

Rename default_layout to global_layout_settings

Rename blockGapStyles to spacingStyles

Fix rebase issues

Fix linting issues

Fix linting again

* Reuse most of the logic from #39926

* Don't accept string values

* Apply root padding only on blocks with content width

* Apply linting changes

* Fix rebase error

* Actually fix rebase

* Add global padding toggle to layout-less blocks

* Support custom block padding.

* Output alignfull styles only when needed.

* Toggle should only appear when needed.

* Add context to comments about string value support

* Interpret preset padding value for negative margin

* Don't show toggle on blocks without content size.

* Change setting name.

* Improve preset processing logic

* Reset padding when no content size applies.

* Update style engine class to match trunk

* Fix string check

* Fix preset values in the editor.

* Fix string check

* Remove useGlobalPadding attribute

* Replace padding with spacing in function parameter

* Default root padding setting to false.

* Dodgy fix for Cover block

* Add test for get_styles_for_block function

* Check for padding setting before adding classname.

* Don't output vars if setting is off

* Test default output without setting enabled.

* Update lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php

No humorous string values allowed

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Remove empty line.

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants