From aec60be54dfeb45191bbf3bb4b284a486303da23 Mon Sep 17 00:00:00 2001 From: Benazeer Hassan <66269472+benazeer-ben@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:04:49 +0530 Subject: [PATCH] Search Block: Refactoring settings panel (#67907) * Refactoring settings panel * Feedback changes * Feedback changes * Update packages/block-library/src/search/edit.js Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> * Update packages/block-library/src/search/edit.js Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> * Update packages/block-library/src/search/edit.js Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> * Feedback changes * Final Suggestion change --------- Co-authored-by: benazeer-ben Co-authored-by: fabiankaegy Co-authored-by: t-hamano --- packages/block-library/src/search/edit.js | 173 +++++++++++++--------- 1 file changed, 99 insertions(+), 74 deletions(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index ed8edf4a5aca8c..16eb62daa6abbf 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -25,12 +25,13 @@ import { ToolbarGroup, ToolbarButton, ResizableBox, - PanelBody, - __experimentalVStack as VStack, __experimentalUseCustomUnits as useCustomUnits, __experimentalUnitControl as UnitControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, + __experimentalToolsPanel as ToolsPanel, + __experimentalToolsPanelItem as ToolsPanelItem, + __experimentalVStack as VStack, } from '@wordpress/components'; import { useInstanceId } from '@wordpress/compose'; import { Icon, search } from '@wordpress/icons'; @@ -54,6 +55,7 @@ import { MIN_WIDTH, isPercentageUnit, } from './utils.js'; +import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; // Used to calculate border radius adjustment to avoid "fat" corners when // button is placed inside wrapper. @@ -370,6 +372,7 @@ export default function SearchEdit( { ); }; + const dropdownMenuProps = useToolsPanelDropdownMenuProps(); const controls = ( <> @@ -408,79 +411,101 @@ export default function SearchEdit( { - - { + setAttributes( { + width: undefined, + widthUnit: undefined, + } ); + } } + dropdownMenuProps={ dropdownMenuProps } + > + !! width } + label={ __( 'Width' ) } + onDeselect={ () => { + setAttributes( { + width: undefined, + widthUnit: undefined, + } ); + } } + isShownByDefault > - { - const parsedNewWidth = - newWidth === '' - ? undefined - : parseInt( newWidth, 10 ); - setAttributes( { - width: parsedNewWidth, - } ); - } } - onUnitChange={ ( newUnit ) => { - setAttributes( { - width: - '%' === newUnit - ? PC_WIDTH_DEFAULT - : PX_WIDTH_DEFAULT, - widthUnit: newUnit, - } ); - } } - __unstableInputWidth="80px" - value={ `${ width }${ widthUnit }` } - units={ units } - /> - { - setAttributes( { - width: newWidth, - widthUnit: '%', - } ); - } } - isBlock - __next40pxDefaultSize - __nextHasNoMarginBottom - > - { PERCENTAGE_WIDTHS.map( ( widthValue ) => { - return ( - - ); - } ) } - - - + + { + const parsedNewWidth = + newWidth === '' + ? undefined + : parseInt( newWidth, 10 ); + setAttributes( { + width: parsedNewWidth, + } ); + } } + onUnitChange={ ( newUnit ) => { + setAttributes( { + width: + '%' === newUnit + ? PC_WIDTH_DEFAULT + : PX_WIDTH_DEFAULT, + widthUnit: newUnit, + } ); + } } + __unstableInputWidth="80px" + value={ `${ width }${ widthUnit }` } + units={ units } + /> + { + setAttributes( { + width: newWidth, + widthUnit: '%', + } ); + } } + isBlock + __next40pxDefaultSize + __nextHasNoMarginBottom + > + { PERCENTAGE_WIDTHS.map( ( widthValue ) => { + return ( + + ); + } ) } + + + + );