@@ -16,13 +16,13 @@ import removeAnchorTag from '../utils/remove-anchor-tag';
16
16
import { __ } from '@wordpress/i18n' ;
17
17
import { useEffect , useState , useRef , useMemo } from '@wordpress/element' ;
18
18
import {
19
- Button ,
20
- ButtonGroup ,
21
19
TextControl ,
22
20
ToolbarButton ,
23
21
Popover ,
24
22
__experimentalToolsPanel as ToolsPanel ,
25
23
__experimentalToolsPanelItem as ToolsPanelItem ,
24
+ __experimentalToggleGroupControl as ToggleGroupControl ,
25
+ __experimentalToggleGroupControlOption as ToggleGroupControlOption ,
26
26
} from '@wordpress/components' ;
27
27
import {
28
28
AlignmentControl ,
@@ -115,46 +115,38 @@ function useEnter( props ) {
115
115
}
116
116
117
117
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
-
126
118
return (
127
119
< ToolsPanel
128
120
label = { __ ( 'Settings' ) }
129
- resetAll = { ( ) => {
130
- handleChange ( undefined ) ;
131
- } }
121
+ resetAll = { ( ) => setAttributes ( { width : undefined } ) }
132
122
>
133
123
< ToolsPanelItem
134
124
label = { __ ( 'Button width' ) }
135
- __nextHasNoMarginBottom
136
125
isShownByDefault
137
126
hasValue = { ( ) => ! ! selectedWidth }
138
- onDeselect = { ( ) => handleChange ( undefined ) }
127
+ onDeselect = { ( ) => setAttributes ( { width : undefined } ) }
128
+ __nextHasNoMarginBottom
139
129
>
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
+ >
141
140
{ [ 25 , 50 , 75 , 100 ] . map ( ( widthValue ) => {
142
141
return (
143
- < Button
142
+ < ToggleGroupControlOption
144
143
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
+ />
155
147
) ;
156
148
} ) }
157
- </ ButtonGroup >
149
+ </ ToggleGroupControl >
158
150
</ ToolsPanelItem >
159
151
</ ToolsPanel >
160
152
) ;
0 commit comments