Skip to content

Commit

Permalink
Add consistency to control display defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Mar 31, 2023
1 parent 9772f53 commit 11df198
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ function DimensionsToolsPanel( {
}

const DEFAULT_CONTROLS = {
contentSize: true,
wideSize: true,
padding: true,
margin: true,
blockGap: true,
minHeight: true,
contentSize: false,
wideSize: false,
padding: false,
margin: false,
blockGap: false,
minHeight: false,
childLayout: true,
};

Expand Down Expand Up @@ -421,7 +421,10 @@ export default function DimensionsPanel( {
label={ __( 'Content size' ) }
hasValue={ hasUserSetContentSizeValue }
onDeselect={ resetContentSizeValue }
isShownByDefault={ defaultControls.contentSize }
isShownByDefault={
defaultControls.contentSize ??
DEFAULT_CONTROLS.contentSize
}
panelId={ panelId }
>
<HStack alignment="flex-end" justify="flex-start">
Expand All @@ -447,7 +450,9 @@ export default function DimensionsPanel( {
label={ __( 'Wide size' ) }
hasValue={ hasUserSetWideSizeValue }
onDeselect={ resetWideSizeValue }
isShownByDefault={ defaultControls.wideSize }
isShownByDefault={
defaultControls.wideSize ?? DEFAULT_CONTROLS.wideSize
}
panelId={ panelId }
>
<HStack alignment="flex-end" justify="flex-start">
Expand All @@ -472,7 +477,9 @@ export default function DimensionsPanel( {
hasValue={ hasPaddingValue }
label={ __( 'Padding' ) }
onDeselect={ resetPaddingValue }
isShownByDefault={ defaultControls.padding }
isShownByDefault={
defaultControls.padding ?? DEFAULT_CONTROLS.padding
}
className={ classnames( {
'tools-panel-item-spacing': showSpacingPresetsControl,
} ) }
Expand Down Expand Up @@ -511,7 +518,9 @@ export default function DimensionsPanel( {
hasValue={ hasMarginValue }
label={ __( 'Margin' ) }
onDeselect={ resetMarginValue }
isShownByDefault={ defaultControls.margin }
isShownByDefault={
defaultControls.margin ?? DEFAULT_CONTROLS.margin
}
className={ classnames( {
'tools-panel-item-spacing': showSpacingPresetsControl,
} ) }
Expand Down Expand Up @@ -550,7 +559,9 @@ export default function DimensionsPanel( {
hasValue={ hasGapValue }
label={ __( 'Block spacing' ) }
onDeselect={ resetGapValue }
isShownByDefault={ defaultControls.blockGap }
isShownByDefault={
defaultControls.blockGap ?? DEFAULT_CONTROLS.blockGap
}
className={ classnames( {
'tools-panel-item-spacing': showSpacingPresetsControl,
} ) }
Expand Down Expand Up @@ -596,7 +607,9 @@ export default function DimensionsPanel( {
hasValue={ hasMinHeightValue }
label={ __( 'Min. height' ) }
onDeselect={ resetMinHeightValue }
isShownByDefault={ defaultControls.minHeight }
isShownByDefault={
defaultControls.minHeight ?? DEFAULT_CONTROLS.minHeight
}
panelId={ panelId }
>
<HeightControl
Expand All @@ -614,9 +627,8 @@ export default function DimensionsPanel( {
label={ childLayoutOrientationLabel }
onDeselect={ resetChildLayoutValue }
isShownByDefault={
typeof defaultControls.childLayout === 'boolean'
? defaultControls.childLayout
: DEFAULT_CONTROLS.childLayout
defaultControls.childLayout ??
DEFAULT_CONTROLS.childLayout
}
panelId={ panelId }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ const {
DimensionsPanel: StylesDimensionsPanel,
} = unlock( blockEditorPrivateApis );

const DEFAULT_CONTROLS = {
contentSize: true,
wideSize: true,
padding: true,
margin: true,
blockGap: true,
minHeight: true,
childLayout: false,
};

export default function DimensionsPanel( { name, variation = '' } ) {
let prefixParts = [];
if ( variation ) {
Expand Down Expand Up @@ -66,6 +76,7 @@ export default function DimensionsPanel( { name, variation = '' } ) {
onChange={ onChange }
settings={ settings }
includeLayoutControls
defaultControls={ DEFAULT_CONTROLS }
/>
);
}

0 comments on commit 11df198

Please sign in to comment.