-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 inherit content size to base styles #42664
Changes from all commits
fcfce15
2e9719f
8f219a1
3addf03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -736,16 +736,31 @@ function( $pseudo_selector ) use ( $selector ) { | |
} | ||
} | ||
|
||
/* | ||
* Reset default browser margin on the root body element. | ||
* This is set on the root selector **before** generating the ruleset | ||
* from the `theme.json`. This is to ensure that if the `theme.json` declares | ||
* `margin` in its `spacing` declaration for the `body` element then these | ||
* user-generated values take precedence in the CSS cascade. | ||
* @link https://github.com/WordPress/gutenberg/issues/36147. | ||
*/ | ||
if ( static::ROOT_BLOCK_SELECTOR === $selector ) { | ||
$block_rules .= 'body { margin: 0; }'; | ||
/* | ||
* Reset default browser margin on the root body element. | ||
* This is set on the root selector **before** generating the ruleset | ||
* from the `theme.json`. This is to ensure that if the `theme.json` declares | ||
* `margin` in its `spacing` declaration for the `body` element then these | ||
* user-generated values take precedence in the CSS cascade. | ||
* @link https://github.com/WordPress/gutenberg/issues/36147. | ||
*/ | ||
$block_rules .= 'body { margin: 0;'; | ||
|
||
/* | ||
* If there are content and wide widths in theme.json, output them | ||
* as custom properties on the body element so all blocks can use them. | ||
*/ | ||
if ( isset( $settings['layout']['contentSize'] ) && $settings['layout']['contentSize'] || isset( $settings['layout']['wideSize'] ) && $settings['layout']['wideSize'] ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just another idle thought from working on #42544, would it be worth moving this block to the bottom of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, that makes total sense! I've transferred most of this logic to #42763 where I'm trying to solve the problem via a new layout type. It's working neatly so far because it makes the extra classname/selector unnecessary. If we decide not to go forward with that approach, I'll go on with this one, otherwise it's easier to apply this feedback directly on the other one 😄 |
||
$content_size = isset( $settings['layout']['contentSize'] ) ? $settings['layout']['contentSize'] : $settings['layout']['wideSize']; | ||
$content_size = static::is_safe_css_declaration( 'max-width', $content_size ) ? $content_size : 'initial'; | ||
$wide_size = isset( $settings['layout']['wideSize'] ) ? $settings['layout']['wideSize'] : $settings['layout']['contentSize']; | ||
$wide_size = static::is_safe_css_declaration( 'max-width', $wide_size ) ? $wide_size : 'initial'; | ||
$block_rules .= '--wp--style--global--content-size: ' . $content_size . ';'; | ||
$block_rules .= '--wp--style--global--wide-size: ' . $wide_size . ';'; | ||
Comment on lines
+759
to
+760
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since theme.json settings aren't run through |
||
} | ||
|
||
$block_rules .= '}'; | ||
} | ||
|
||
// 2. Generate and append the rules that use the general selector. | ||
|
@@ -1264,7 +1279,7 @@ protected function get_layout_styles( $block_metadata ) { | |
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support. | ||
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() ); | ||
$layout_definitions = _wp_array_get( $this->theme_json, array( 'settings', 'layout', 'definitions' ), array() ); | ||
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, and child combinator selectors. | ||
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors. | ||
|
||
// Gap styles will only be output if the theme has block gap support, or supports a fallback gap. | ||
// Default layout gap styles will be skipped for themes that do not explicitly opt-in to blockGap with a `true` or `false` value. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason I really like this line removal. To me it makes the whole behaviour in this PR feel like the layout support is a bit more logical and less magical, so it's nice we can remove this! 👍