Skip to content

Commit

Permalink
Update global styles panel
Browse files Browse the repository at this point in the history
  • Loading branch information
stacimc committed Aug 6, 2021
1 parent d5ec9a5 commit 4add752
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/edit-site/src/components/sidebar/spacing-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { __experimentalUseCustomSides as useCustomSides } from '@wordpress/block
*/
import { useSetting } from '../editor/utils';

const AXIAL_SIDES = [ 'horizontal', 'vertical' ];

export function useHasSpacingPanel( context ) {
const hasPadding = useHasPadding( context );
const hasMargin = useHasMargin( context );
Expand Down Expand Up @@ -41,7 +43,17 @@ function filterValuesBySides( values, sides ) {

// Only include sides opted into within filtered values.
const filteredValues = {};
sides.forEach( ( side ) => ( filteredValues[ side ] = values[ side ] ) );
sides.forEach( ( side ) => {
if ( side === 'vertical' ) {
filteredValues.top = values.top;
filteredValues.bottom = values.bottom;
}
if ( side === 'horizontal' ) {
filteredValues.left = values.left;
filteredValues.right = values.right;
}
filteredValues[ side ] = values[ side ];
} );

return filteredValues;
}
Expand Down Expand Up @@ -77,6 +89,9 @@ export default function SpacingPanel( { context, getStyle, setStyle } ) {

const paddingValues = splitStyleValue( getStyle( name, 'padding' ) );
const paddingSides = useCustomSides( name, 'padding' );
const isAxialPadding =
paddingSides &&
paddingSides.some( ( side ) => AXIAL_SIDES.includes( side ) );

const setPaddingValues = ( newPaddingValues ) => {
const padding = filterValuesBySides( newPaddingValues, paddingSides );
Expand All @@ -85,6 +100,9 @@ export default function SpacingPanel( { context, getStyle, setStyle } ) {

const marginValues = splitStyleValue( getStyle( name, 'margin' ) );
const marginSides = useCustomSides( name, 'margin' );
const isAxialMargin =
marginSides &&
marginSides.some( ( side ) => AXIAL_SIDES.includes( side ) );

const setMarginValues = ( newMarginValues ) => {
const margin = filterValuesBySides( newMarginValues, marginSides );
Expand All @@ -100,6 +118,7 @@ export default function SpacingPanel( { context, getStyle, setStyle } ) {
label={ __( 'Padding' ) }
sides={ paddingSides }
units={ units }
splitOnAxis={ isAxialPadding }
/>
) }
{ showMarginControl && (
Expand All @@ -109,6 +128,7 @@ export default function SpacingPanel( { context, getStyle, setStyle } ) {
label={ __( 'Margin' ) }
sides={ marginSides }
units={ units }
splitOnAxis={ isAxialMargin }
/>
) }
</PanelBody>
Expand Down

0 comments on commit 4add752

Please sign in to comment.