-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
BlockGap: Add support for spacing presets #43296
Changes from all commits
2d5ff2f
8b978d1
2f1d687
a7562f1
55a62f4
8bfbd94
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 |
---|---|---|
|
@@ -793,8 +793,6 @@ function( $pseudo_selector ) use ( $selector ) { | |
} | ||
|
||
if ( static::ROOT_BLOCK_SELECTOR === $selector ) { | ||
$block_gap_value = _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' ); | ||
|
||
if ( $use_root_padding ) { | ||
$block_rules .= '.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); }'; | ||
$block_rules .= '.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }'; | ||
|
@@ -808,8 +806,10 @@ function( $pseudo_selector ) use ( $selector ) { | |
|
||
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null; | ||
if ( $has_block_gap_support ) { | ||
$block_rules .= '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }'; | ||
$block_rules .= ".wp-site-blocks > * + * { margin-block-start: $block_gap_value; }"; | ||
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) ); | ||
ramonjd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$block_rules .= '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }'; | ||
$block_rules .= ".wp-site-blocks > * + * { margin-block-start: $block_gap_value; }"; | ||
|
||
// For backwards compatibility, ensure the legacy block gap CSS variable is still available. | ||
$block_rules .= "$selector { --wp--style--block-gap: $block_gap_value; }"; | ||
} | ||
|
@@ -1308,14 +1308,14 @@ protected function get_layout_styles( $block_metadata ) { | |
$block_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), null ); | ||
} | ||
} else { | ||
$block_gap_value = _wp_array_get( $node, array( 'spacing', 'blockGap' ), null ); | ||
$block_gap_value = static::get_property_value( $node, array( 'spacing', 'blockGap' ) ); | ||
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. I think we need this also in Without it the body CSS rule with custom var isn't parsed:
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. that will be what is breaking the gallery probably as it relies on 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. Nice one, thanks for catching that! I'll update 👍 Good eyes! 🦅 👀 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. I've updated in 2f1d687, and the Gallery block appears to be working now. I also removed the It looks like the site editor was already parsing the value for the JS side of things, but let me know if you encounter any other issues! 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. A question: should the following block style in theme.json have any effect? "core/gallery": {
"spacing": {
"blockGap": "var:preset|spacing|80"
}
} 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.
No, the Gallery block isn't supported in global styles yet since it uses an ad hoc implementation for gap. But it's flagged in the Layout design tools consistency issue. |
||
} | ||
|
||
// Support split row / column values and concatenate to a shorthand value. | ||
if ( is_array( $block_gap_value ) ) { | ||
if ( isset( $block_gap_value['top'] ) && isset( $block_gap_value['left'] ) ) { | ||
$gap_row = $block_gap_value['top']; | ||
$gap_column = $block_gap_value['left']; | ||
$gap_row = static::get_property_value( $node, array( 'spacing', 'blockGap', 'top' ) ); | ||
$gap_column = static::get_property_value( $node, array( 'spacing', 'blockGap', 'left' ) ); | ||
$block_gap_value = $gap_row === $gap_column ? $gap_row : $gap_row . ' ' . $gap_column; | ||
} else { | ||
// Skip outputting gap value if not all sides are provided. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { | |
* Internal dependencies | ||
*/ | ||
import { __unstableUseBlockRef as useBlockRef } from '../components/block-list/use-block-props/use-block-refs'; | ||
import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils'; | ||
import useSetting from '../components/use-setting'; | ||
import { AXIAL_SIDES, SPACING_SUPPORT_KEY, useCustomSides } from './dimensions'; | ||
import { cleanEmptyObject } from './utils'; | ||
|
@@ -54,8 +55,12 @@ export function getGapBoxControlValueFromStyle( blockGapValue ) { | |
|
||
const isValueString = typeof blockGapValue === 'string'; | ||
return { | ||
top: isValueString ? blockGapValue : blockGapValue?.top, | ||
left: isValueString ? blockGapValue : blockGapValue?.left, | ||
top: isValueString | ||
? getSpacingPresetCssVar( blockGapValue ) | ||
ramonjd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: getSpacingPresetCssVar( blockGapValue?.top ), | ||
left: isValueString | ||
? getSpacingPresetCssVar( blockGapValue ) | ||
: getSpacingPresetCssVar( blockGapValue?.left ), | ||
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. This is not a blocker, and I'm not sure there's much to be done about it in this PR anyway. When updating a single axial value we overwrite both top and left values: .wp-block-social-links.is-layout-flex {
gap: var(--wp--preset--spacing--40) var(--wp--preset--spacing--20);
} The fallback value differs between the editor and the frontend: .editor-styles-wrapper .wp-block-social-links.wp-container-37 {
gap: 0 7px;
}
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. Oh, good catch. Let's look at adding some consistency there in a follow-up. 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 thinking about this a little more, unfortunately, because we're concatenating to the single 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. Ahhh I see. Maybe I don't know either! 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. Thanks @ramonjd, I was leaning slightly toward Does that sound reasonable to you as a short-term fix? 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. Sounds great, thanks for doing that! 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. Works a treat, thanks! |
||
}; | ||
} | ||
|
||
|
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.
It looks like
_wp_array_get
is returningnull
fornull
values.So, an incoming
$gap_value
ofarray(2) { ["top"]=> NULL ["left"]=> string(4) "38px" }
Will result in a
$combined_gap_value
of38px
.Steps to reproduce:
The editor produces the following CSS:
The frontend
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.
Sorry, ignore this. I refreshed the editor and I can't reproduce any more.
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.
🤭
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.
Okay, cool. We can always do more detailed testing with this behaviour once we've got the spacing controls in there, I imagine it'll make testing a little easier since we'll be doing less manual fiddling with markup values 🤔
Thanks for all the testing here!