Skip to content

Commit

Permalink
Try moving the default value to sit under the blockGap key in spacing…
Browse files Browse the repository at this point in the history
…, updated useCustomSides to support an object
  • Loading branch information
andrewserong committed May 19, 2022
1 parent a9dd741 commit a2cc158
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
}

$fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', '__experimentalDefaultValues', 'blockGap' ), '0.5em' );
$fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', 'default' ), '0.5em' );

// If a block's block.json skips serialization for spacing or spacing.blockGap,
// don't apply the user-defined value to the styles.
Expand Down
10 changes: 8 additions & 2 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const useIsDimensionsDisabled = ( props = {} ) => {
* @param {string} blockName Block name.
* @param {string} feature The feature custom sides relate to e.g. padding or margins.
*
* @return {Object} Sides supporting custom margin.
* @return {string[]} Sides supporting custom margin.

This comment has been minimized.

Copy link
@andrewserong

andrewserong May 19, 2022

Author Contributor

It turns out I believe this was always an array of strings, so just updated the type here, too.

*/
export function useCustomSides( blockName, feature ) {
const support = getBlockSupport( blockName, SPACING_SUPPORT_KEY );
Expand All @@ -172,7 +172,13 @@ export function useCustomSides( blockName, feature ) {
return;
}

return support[ feature ];
if ( Array.isArray( support[ feature ] ) ) {
return support[ feature ];
}

if ( support[ feature ]?.sides ) {
return support[ feature ].sides;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export default {
const fallbackValue =
getBlockSupport( blockName, [
'spacing',
'__experimentalDefaultValues',
'blockGap',
'default',
] ) || '0.5em';

const hasBlockGapStylesSupport = blockGapSupport !== null;
Expand Down
7 changes: 3 additions & 4 deletions packages/block-library/src/columns/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
}
},
"spacing": {
"blockGap": true,
"blockGap": {
"default": "2em"
},
"margin": [ "top", "bottom" ],
"padding": true,
"__experimentalDefaultControls": {
"padding": true
},
"__experimentalDefaultValues": {
"blockGap": "2em"
}
},
"__experimentalLayout": {
Expand Down

0 comments on commit a2cc158

Please sign in to comment.