Skip to content

Commit

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

Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
  • Loading branch information
3 people authored and yogeshbhutkar committed Dec 18, 2024
1 parent 167dc57 commit 10da749
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import { useEffect, useState, useRef, useMemo } from '@wordpress/element';
import {
Button,
ButtonGroup,
PanelBody,
TextControl,
ToolbarButton,
Popover,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import {
AlignmentControl,
Expand Down Expand Up @@ -123,26 +124,39 @@ function WidthPanel( { selectedWidth, setAttributes } ) {
}

return (
<PanelBody title={ __( 'Settings' ) }>
<ButtonGroup aria-label={ __( 'Button width' ) }>
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {
return (
<Button
key={ widthValue }
size="small"
variant={
widthValue === selectedWidth
? 'primary'
: undefined
}
onClick={ () => handleChange( widthValue ) }
>
{ widthValue }%
</Button>
);
} ) }
</ButtonGroup>
</PanelBody>
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
handleChange( undefined );
} }
>
<ToolsPanelItem
label={ __( 'Button width' ) }
__nextHasNoMarginBottom
isShownByDefault
hasValue={ () => !! selectedWidth }
onDeselect={ () => handleChange( undefined ) }
>
<ButtonGroup aria-label={ __( 'Button width' ) }>
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {
return (
<Button
key={ widthValue }
size="small"
variant={
widthValue === selectedWidth
? 'primary'
: undefined
}
onClick={ () => handleChange( widthValue ) }
>
{ widthValue }%
</Button>
);
} ) }
</ButtonGroup>
</ToolsPanelItem>
</ToolsPanel>
);
}

Expand Down

0 comments on commit 10da749

Please sign in to comment.