@@ -8,7 +8,6 @@ import clsx from 'clsx';
8
8
*/
9
9
import {
10
10
useBlockProps ,
11
- BlockControls ,
12
11
InspectorControls ,
13
12
RichText ,
14
13
__experimentalUseBorderProps as useBorderProps ,
@@ -21,9 +20,8 @@ import {
21
20
import { useDispatch , useSelect } from '@wordpress/data' ;
22
21
import { useEffect , useRef } from '@wordpress/element' ;
23
22
import {
24
- ToolbarDropdownMenu ,
25
- ToolbarGroup ,
26
- ToolbarButton ,
23
+ SelectControl ,
24
+ ToggleControl ,
27
25
ResizableBox ,
28
26
__experimentalUseCustomUnits as useCustomUnits ,
29
27
__experimentalUnitControl as UnitControl ,
@@ -41,14 +39,6 @@ import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
41
39
/**
42
40
* Internal dependencies
43
41
*/
44
- import {
45
- buttonOnly ,
46
- buttonOutside ,
47
- buttonInside ,
48
- noButton ,
49
- buttonWithIcon ,
50
- toggleLabel ,
51
- } from './icons' ;
52
42
import {
53
43
PC_WIDTH_DEFAULT ,
54
44
PX_WIDTH_DEFAULT ,
@@ -201,68 +191,23 @@ export default function SearchEdit( {
201
191
202
192
const buttonPositionControls = [
203
193
{
204
- role : 'menuitemradio' ,
205
- title : __ ( 'Button outside' ) ,
206
- isActive : buttonPosition === 'button-outside' ,
207
- icon : buttonOutside ,
208
- onClick : ( ) => {
209
- setAttributes ( {
210
- buttonPosition : 'button-outside' ,
211
- isSearchFieldHidden : false ,
212
- } ) ;
213
- } ,
194
+ label : __ ( 'Button outside' ) ,
195
+ value : 'button-outside' ,
214
196
} ,
215
197
{
216
- role : 'menuitemradio' ,
217
- title : __ ( 'Button inside' ) ,
218
- isActive : buttonPosition === 'button-inside' ,
219
- icon : buttonInside ,
220
- onClick : ( ) => {
221
- setAttributes ( {
222
- buttonPosition : 'button-inside' ,
223
- isSearchFieldHidden : false ,
224
- } ) ;
225
- } ,
198
+ label : __ ( 'Button inside' ) ,
199
+ value : 'button-inside' ,
226
200
} ,
227
201
{
228
- role : 'menuitemradio' ,
229
- title : __ ( 'No button' ) ,
230
- isActive : buttonPosition === 'no-button' ,
231
- icon : noButton ,
232
- onClick : ( ) => {
233
- setAttributes ( {
234
- buttonPosition : 'no-button' ,
235
- isSearchFieldHidden : false ,
236
- } ) ;
237
- } ,
202
+ label : __ ( 'No button' ) ,
203
+ value : 'no-button' ,
238
204
} ,
239
205
{
240
- role : 'menuitemradio' ,
241
- title : __ ( 'Button only' ) ,
242
- isActive : buttonPosition === 'button-only' ,
243
- icon : buttonOnly ,
244
- onClick : ( ) => {
245
- setAttributes ( {
246
- buttonPosition : 'button-only' ,
247
- isSearchFieldHidden : true ,
248
- } ) ;
249
- } ,
206
+ label : __ ( 'Button only' ) ,
207
+ value : 'button-only' ,
250
208
} ,
251
209
] ;
252
210
253
- const getButtonPositionIcon = ( ) => {
254
- switch ( buttonPosition ) {
255
- case 'button-inside' :
256
- return buttonInside ;
257
- case 'button-outside' :
258
- return buttonOutside ;
259
- case 'no-button' :
260
- return noButton ;
261
- case 'button-only' :
262
- return buttonOnly ;
263
- }
264
- } ;
265
-
266
211
const getResizableSides = ( ) => {
267
212
if ( hasOnlyButton ) {
268
213
return { } ;
@@ -376,51 +321,91 @@ export default function SearchEdit( {
376
321
377
322
const controls = (
378
323
< >
379
- < BlockControls >
380
- < ToolbarGroup >
381
- < ToolbarButton
382
- title = { __ ( 'Show search label' ) }
383
- icon = { toggleLabel }
384
- onClick = { ( ) => {
385
- setAttributes ( {
386
- showLabel : ! showLabel ,
387
- } ) ;
388
- } }
389
- className = { showLabel ? 'is-pressed' : undefined }
390
- />
391
- < ToolbarDropdownMenu
392
- icon = { getButtonPositionIcon ( ) }
393
- label = { __ ( 'Change button position' ) }
394
- controls = { buttonPositionControls }
395
- />
396
- { ! hasNoButton && (
397
- < ToolbarButton
398
- title = { __ ( 'Use button with icon' ) }
399
- icon = { buttonWithIcon }
400
- onClick = { ( ) => {
401
- setAttributes ( {
402
- buttonUseIcon : ! buttonUseIcon ,
403
- } ) ;
404
- } }
405
- className = {
406
- buttonUseIcon ? 'is-pressed' : undefined
407
- }
408
- />
409
- ) }
410
- </ ToolbarGroup >
411
- </ BlockControls >
412
-
413
324
< InspectorControls >
414
325
< ToolsPanel
415
326
label = { __ ( 'Settings' ) }
416
327
resetAll = { ( ) => {
417
328
setAttributes ( {
418
329
width : undefined ,
419
330
widthUnit : undefined ,
331
+ showLabel : true ,
332
+ buttonUseIcon : false ,
333
+ buttonPosition : 'button-outside' ,
334
+ isSearchFieldHidden : false ,
420
335
} ) ;
421
336
} }
422
337
dropdownMenuProps = { dropdownMenuProps }
423
338
>
339
+ < ToolsPanelItem
340
+ hasValue = { ( ) => ! showLabel }
341
+ label = { __ ( 'Show label' ) }
342
+ onDeselect = { ( ) => {
343
+ setAttributes ( {
344
+ showLabel : true ,
345
+ } ) ;
346
+ } }
347
+ isShownByDefault
348
+ >
349
+ < ToggleControl
350
+ __nextHasNoMarginBottom
351
+ checked = { showLabel }
352
+ label = { __ ( 'Show label' ) }
353
+ onChange = { ( value ) =>
354
+ setAttributes ( {
355
+ showLabel : value ,
356
+ } )
357
+ }
358
+ />
359
+ </ ToolsPanelItem >
360
+ < ToolsPanelItem
361
+ hasValue = { ( ) => buttonPosition !== 'button-outside' }
362
+ label = { __ ( 'Button position' ) }
363
+ onDeselect = { ( ) => {
364
+ setAttributes ( {
365
+ buttonPosition : 'button-outside' ,
366
+ isSearchFieldHidden : false ,
367
+ } ) ;
368
+ } }
369
+ isShownByDefault
370
+ >
371
+ < SelectControl
372
+ value = { buttonPosition }
373
+ __next40pxDefaultSize
374
+ __nextHasNoMarginBottom
375
+ label = { __ ( 'Button position' ) }
376
+ onChange = { ( value ) => {
377
+ setAttributes ( {
378
+ buttonPosition : value ,
379
+ isSearchFieldHidden :
380
+ value === 'button-only' ,
381
+ } ) ;
382
+ } }
383
+ options = { buttonPositionControls }
384
+ />
385
+ </ ToolsPanelItem >
386
+ { buttonPosition !== 'no-button' && (
387
+ < ToolsPanelItem
388
+ hasValue = { ( ) => ! ! buttonUseIcon }
389
+ label = { __ ( 'Use button with icon' ) }
390
+ onDeselect = { ( ) => {
391
+ setAttributes ( {
392
+ buttonUseIcon : false ,
393
+ } ) ;
394
+ } }
395
+ isShownByDefault
396
+ >
397
+ < ToggleControl
398
+ __nextHasNoMarginBottom
399
+ checked = { buttonUseIcon }
400
+ label = { __ ( 'Use button with icon' ) }
401
+ onChange = { ( value ) =>
402
+ setAttributes ( {
403
+ buttonUseIcon : value ,
404
+ } )
405
+ }
406
+ />
407
+ </ ToolsPanelItem >
408
+ ) }
424
409
< ToolsPanelItem
425
410
hasValue = { ( ) => ! ! width }
426
411
label = { __ ( 'Width' ) }
0 commit comments