Skip to content

Commit

Permalink
Button: Replace ButtonGroup usage with ToggleGroupControl
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Sep 24, 2024
1 parent 228ab3a commit 4fa6920
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { unlock } from '../lock-unlock';
import { __ } from '@wordpress/i18n';
import { useEffect, useState, useRef, useMemo } from '@wordpress/element';
import {
Button,
ButtonGroup,
PanelBody,
TextControl,
ToolbarButton,
Popover,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from '@wordpress/components';
import {
AlignmentControl,
Expand Down Expand Up @@ -115,34 +115,29 @@ function useEnter( props ) {
}

function WidthPanel( { selectedWidth, setAttributes } ) {
function handleChange( newWidth ) {
// Check if we are toggling the width off
const width = selectedWidth === newWidth ? undefined : newWidth;

// Update attributes.
setAttributes( { width } );
}

return (
<PanelBody title={ __( 'Settings' ) }>
<ButtonGroup aria-label={ __( 'Button width' ) }>
<ToggleGroupControl
label={ __( 'Button width' ) }
value={ selectedWidth }
hideLabelFromVision
onChange={ ( newWidth ) =>
setAttributes( { width: newWidth } )
}
isDeselectable
__next40pxDefaultSize
__nextHasNoMarginBottom
>
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {
return (
<Button
<ToggleGroupControlOption
key={ widthValue }
size="small"
variant={
widthValue === selectedWidth
? 'primary'
: undefined
}
onClick={ () => handleChange( widthValue ) }
>
{ widthValue }%
</Button>
value={ widthValue }
label={ `${ widthValue }%` }
/>
);
} ) }
</ButtonGroup>
</ToggleGroupControl>
</PanelBody>
);
}
Expand Down

0 comments on commit 4fa6920

Please sign in to comment.