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 (WordPress#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>
);
}

0 comments on commit 9b3e07f

Please sign in to comment.