From 5576ffb2db716e1279bd45148a4a0e23adfa51c9 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Mon, 15 Aug 2022 15:27:10 +1000 Subject: [PATCH] BlockGap: Try adding axial gap option to global styles (#42490) --- .../global-styles/dimensions-panel.js | 79 ++++++++++++++++--- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/dimensions-panel.js b/packages/edit-site/src/components/global-styles/dimensions-panel.js index 6ef47674881078..9a31f59ee4828a 100644 --- a/packages/edit-site/src/components/global-styles/dimensions-panel.js +++ b/packages/edit-site/src/components/global-styles/dimensions-panel.js @@ -104,7 +104,7 @@ function filterValuesBySides( values, sides ) { } function splitStyleValue( value ) { - // Check for shorthand value ( a string value ). + // Check for shorthand value (a string value). if ( value && typeof value === 'string' ) { // Convert to value for individual sides for BoxControl. return { @@ -118,6 +118,25 @@ function splitStyleValue( value ) { return value; } +function splitGapValue( value ) { + // Check for shorthand value (a string value). + if ( value && typeof value === 'string' ) { + // Convert to value for individual sides for BoxControl. + return { + top: value, + right: value, + bottom: value, + left: value, + }; + } + + return { + ...value, + right: value?.left, + bottom: value?.top, + }; +} + // Props for managing `layout.contentSize`. function useContentSizeProps( name ) { const [ contentSizeValue, setContentSizeValue ] = useSetting( @@ -218,12 +237,29 @@ function useMarginProps( name ) { // Props for managing `spacing.blockGap`. function useBlockGapProps( name ) { const [ gapValue, setGapValue ] = useStyle( 'spacing.blockGap', name ); + const gapValues = splitGapValue( gapValue ); + const setGapValues = ( nextBoxGapValue ) => { + if ( ! nextBoxGapValue ) { + setGapValue( null ); + } + setGapValue( { + top: nextBoxGapValue?.top, + left: nextBoxGapValue?.left, + } ); + }; + const gapSides = useCustomSides( name, 'blockGap' ); + const isAxialGap = + gapSides && gapSides.some( ( side ) => AXIAL_SIDES.includes( side ) ); const resetGapValue = () => setGapValue( undefined ); const [ userSetGapValue ] = useStyle( 'spacing.blockGap', name, 'user' ); const hasGapValue = () => !! userSetGapValue; return { gapValue, + gapValues, + gapSides, + isAxialGap, setGapValue, + setGapValues, resetGapValue, hasGapValue, }; @@ -283,8 +319,16 @@ export default function DimensionsPanel( { name } ) { } = useMarginProps( name ); // Props for managing `spacing.blockGap`. - const { gapValue, setGapValue, resetGapValue, hasGapValue } = - useBlockGapProps( name ); + const { + gapValue, + gapValues, + gapSides, + isAxialGap, + setGapValue, + setGapValues, + resetGapValue, + hasGapValue, + } = useBlockGapProps( name ); const resetAll = () => { resetPaddingValue(); @@ -410,14 +454,27 @@ export default function DimensionsPanel( { name } ) { onDeselect={ resetGapValue } isShownByDefault={ true } > - + { isAxialGap ? ( + + ) : ( + + ) } ) }