-
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
Block Spacing: using spacing controls for block gap values to support presets in the UI #43466
Conversation
5e3291c
to
f994ee5
Compare
Size Change: +233 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
Update: I've added in support for the Gallery block's ad hoc implementation of gap so that the gap calculations work nicely with the parsed spacing values. The final task will be to swap out the controls in global styles for the spacing controls UI, which I'll look into tomorrow. |
fa98a43
to
87a69b5
Compare
@@ -79,7 +79,7 @@ export const PRESET_METADATA = [ | |||
}, | |||
{ | |||
path: [ 'spacing', 'spacingSizes' ], | |||
valueKey: 'spacingSizes', | |||
valueKey: 'size', |
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 valueKey
is used in global styles to point to the key to be used to retrieve the value for a particular preset. So in this case it should be size
. Let me know if anyone knows if it needs to be set to spacingSizes
for any other use cases, though!
// unless filtered. | ||
( value ) => !! value && /\d/.test( value ) | ||
) | ||
if ( values === undefined || values === null ) { |
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.
Thanks @andrewserong, this all tested well for me. It worked as expected for:
✅ Group block in the post editor, adjusting spacing of child blocks (flow/constrained ✅Column block in the post editor, adjusting spacing between columns (flex layout with a single non-axial value)
✅ Social Icons block in the post editor, adjusting spacing between icons, including split row / column values (flex layout with axial sides)
✅ Gallery block in the post editor, adjusting spacing between images, including split row / column values
✅ With 0 position values
✅ With custom values
✅ In root block spacing in global styles
✅ In block-level spacing controls in global styles
✅ With settings.spacing.spacingScale.steps set to the default (7)
✅ With settings.spacing.spacingScale.steps set to 10 so that it uses the select list of options
✅ With settings.spacing.spacingScale.steps set to 0 so that it uses the BoxControl for axial sides and UnitControl for non-axial
✅ With settings.spacing.customSpacingSize to false
Excellent, thanks for the detailed testing @glendaviesnz! 🙇 I'll merge this in now since I think folks working on TwentyTwentyThree theme are waiting for it. I can follow up next week if we run into any odd edge cases with it! |
What?
Update the block spacing (
blockGap
) controls to use the new spacing controls UI — this enables setting block spacing via spacing presets in addition to custom values. See previous related work in margin (#43246) and padding (#42173).Why?
To ensure consistency with across spacing UI elements and allow themes to have control over spacing presets, and have that control be reflected in the UI controls for block spacing.
How?
SpacingSizesControl
when spacing sizes are availablegetGapCSSValue
fromgetGapBoxControlValueFromStyle
(the latter should be raw values, where the former is better suited for outputting the final parsed value — this ensures that the non-parsed value is stored in block comment markup)SpacingSizesControl
componentSpacingSizesControl
to match a passed in value to an existing preset if one exists (theuseStyle
hook in global styles always returns the value for the preset instead of thevar:
form of the preset name)Testing Instructions
I ran into a fair few edge cases while implementing this and made some tweaks as I went, so hopefully the below testing instructions should provided a thorough overview of the different conditions under which the block spacing controls are available.
0
position values are output correctly in the editor and on the site front end9px
rather than a preset) work correctly in the editor and on the site front endWork through the above testing conditions with the following settings in theme.json
settings.spacing.spacingScale.steps
set to the default (7) so that the range control is used to slide between preset valuessettings.spacing.spacingScale.steps
set to10
so that it uses the select list of optionssettings.spacing.spacingScale.steps
set to0
so that it uses the BoxControl for axial sides (e.g. Social Icons and Gallery) and UnitControl for non-axial (Columns, Group, root block spacing in global styles)settings.spacing.customSpacingSize
tofalse
so that custom options aren't available (you'll need to havesteps
set to at least 1 in order for this setting to work)Screenshots or screencast
This also includes a fix for when the custom view only displays a single side, so there is no Unlink button (we need to pass a
gridColumn: 1
rule to theUnitControl
wrapper:Block Spacing controls:
block-gap-with-spacing-controls.mp4