Skip to content

Commit

Permalink
Refactor "Settings" panel of Spacer block to use ToolsPanel instead o…
Browse files Browse the repository at this point in the history
…f PanelBody (#67981)

Co-authored-by: prasadkarmalkar <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent afca7b5 commit 9b3e07f
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions packages/block-library/src/spacer/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import {
PanelBody,
__experimentalUseCustomUnits as useCustomUnits,
__experimentalUnitControl as UnitControl,
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { View } from '@wordpress/primitives';
Expand Down Expand Up @@ -94,28 +95,54 @@ export default function SpacerControls( {
} ) {
return (
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
width: undefined,
height: '100px',
} );
} }
>
{ orientation === 'horizontal' && (
<DimensionInput
<ToolsPanelItem
label={ __( 'Width' ) }
value={ width }
onChange={ ( nextWidth ) =>
setAttributes( { width: nextWidth } )
isShownByDefault
hasValue={ () => width !== undefined }
onDeselect={ () =>
setAttributes( { width: undefined } )
}
isResizing={ isResizing }
/>
>
<DimensionInput
label={ __( 'Width' ) }
value={ width }
onChange={ ( nextWidth ) =>
setAttributes( { width: nextWidth } )
}
isResizing={ isResizing }
/>
</ToolsPanelItem>
) }
{ orientation !== 'horizontal' && (
<DimensionInput
<ToolsPanelItem
label={ __( 'Height' ) }
value={ height }
onChange={ ( nextHeight ) =>
setAttributes( { height: nextHeight } )
isShownByDefault
hasValue={ () => height !== '100px' }
onDeselect={ () =>
setAttributes( { height: '100px' } )
}
isResizing={ isResizing }
/>
>
<DimensionInput
label={ __( 'Height' ) }
value={ height }
onChange={ ( nextHeight ) =>
setAttributes( { height: nextHeight } )
}
isResizing={ isResizing }
/>
</ToolsPanelItem>
) }
</PanelBody>
</ToolsPanel>
</InspectorControls>
);
}

1 comment on commit 9b3e07f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 9b3e07f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12416616768
📝 Reported issues:

Please sign in to comment.