Skip to content

Commit df9c37f

Browse files
committed
Button: Replace ButtonGroup usage with ToggleGroupControl
1 parent 750c8e4 commit df9c37f

File tree

1 file changed

+20
-28
lines changed
  • packages/block-library/src/button

1 file changed

+20
-28
lines changed

packages/block-library/src/button/edit.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import removeAnchorTag from '../utils/remove-anchor-tag';
1616
import { __ } from '@wordpress/i18n';
1717
import { useEffect, useState, useRef, useMemo } from '@wordpress/element';
1818
import {
19-
Button,
20-
ButtonGroup,
2119
TextControl,
2220
ToolbarButton,
2321
Popover,
2422
__experimentalToolsPanel as ToolsPanel,
2523
__experimentalToolsPanelItem as ToolsPanelItem,
24+
__experimentalToggleGroupControl as ToggleGroupControl,
25+
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
2626
} from '@wordpress/components';
2727
import {
2828
AlignmentControl,
@@ -115,46 +115,38 @@ function useEnter( props ) {
115115
}
116116

117117
function WidthPanel( { selectedWidth, setAttributes } ) {
118-
function handleChange( newWidth ) {
119-
// Check if we are toggling the width off
120-
const width = selectedWidth === newWidth ? undefined : newWidth;
121-
122-
// Update attributes.
123-
setAttributes( { width } );
124-
}
125-
126118
return (
127119
<ToolsPanel
128120
label={ __( 'Settings' ) }
129-
resetAll={ () => {
130-
handleChange( undefined );
131-
} }
121+
resetAll={ () => setAttributes( { width: undefined } ) }
132122
>
133123
<ToolsPanelItem
134124
label={ __( 'Button width' ) }
135-
__nextHasNoMarginBottom
136125
isShownByDefault
137126
hasValue={ () => !! selectedWidth }
138-
onDeselect={ () => handleChange( undefined ) }
127+
onDeselect={ () => setAttributes( { width: undefined } ) }
128+
__nextHasNoMarginBottom
139129
>
140-
<ButtonGroup aria-label={ __( 'Button width' ) }>
130+
<ToggleGroupControl
131+
label={ __( 'Button width' ) }
132+
value={ selectedWidth }
133+
onChange={ ( newWidth ) =>
134+
setAttributes( { width: newWidth } )
135+
}
136+
isBlock
137+
__next40pxDefaultSize
138+
__nextHasNoMarginBottom
139+
>
141140
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {
142141
return (
143-
<Button
142+
<ToggleGroupControlOption
144143
key={ widthValue }
145-
size="small"
146-
variant={
147-
widthValue === selectedWidth
148-
? 'primary'
149-
: undefined
150-
}
151-
onClick={ () => handleChange( widthValue ) }
152-
>
153-
{ widthValue }%
154-
</Button>
144+
value={ widthValue }
145+
label={ `${ widthValue }%` }
146+
/>
155147
);
156148
} ) }
157-
</ButtonGroup>
149+
</ToggleGroupControl>
158150
</ToolsPanelItem>
159151
</ToolsPanel>
160152
);

0 commit comments

Comments
 (0)