Skip to content

Commit

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

Co-authored-by: prasadkarmalkar <prasadkarmalkar@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent d988d28 commit d90fbad
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions packages/block-library/src/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import {
} from '@wordpress/block-editor';
import {
__experimentalUseCustomUnits as useCustomUnits,
PanelBody,
__experimentalUnitControl as UnitControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { sprintf, __ } from '@wordpress/i18n';
Expand All @@ -30,19 +31,32 @@ function ColumnInspectorControls( { width, setAttributes } ) {
availableUnits: availableUnits || [ '%', 'px', 'em', 'rem', 'vw' ],
} );
return (
<PanelBody title={ __( 'Settings' ) }>
<UnitControl
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( { width: undefined } );
} }
>
<ToolsPanelItem
hasValue={ () => width !== undefined }
label={ __( 'Width' ) }
__unstableInputWidth="calc(50% - 8px)"
__next40pxDefaultSize
value={ width || '' }
onChange={ ( nextWidth ) => {
nextWidth = 0 > parseFloat( nextWidth ) ? '0' : nextWidth;
setAttributes( { width: nextWidth } );
} }
units={ units }
/>
</PanelBody>
onDeselect={ () => setAttributes( { width: undefined } ) }
isShownByDefault
>
<UnitControl
label={ __( 'Width' ) }
__unstableInputWidth="calc(50% - 8px)"
__next40pxDefaultSize
value={ width || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth ) ? '0' : nextWidth;
setAttributes( { width: nextWidth } );
} }
units={ units }
/>
</ToolsPanelItem>
</ToolsPanel>
);
}

Expand Down

0 comments on commit d90fbad

Please sign in to comment.