Skip to content

Commit

Permalink
Replace PanelBody with ToolsPanel and ToolsPanelItem in spacer block
Browse files Browse the repository at this point in the history
  • Loading branch information
prasadkarmalkar committed Dec 13, 2024
1 parent 8d6b8c5 commit 669e1e5
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 669e1e5

Please sign in to comment.