@@ -7,7 +7,6 @@ import clsx from 'clsx';
7
7
* WordPress dependencies
8
8
*/
9
9
import {
10
- PanelBody ,
11
10
Placeholder ,
12
11
QueryControls ,
13
12
RadioControl ,
@@ -328,131 +327,240 @@ function Controls( { attributes, setAttributes, postCount } ) {
328
327
/>
329
328
</ ToolsPanelItem >
330
329
</ ToolsPanel >
331
- < PanelBody title = { __ ( 'Featured image' ) } >
332
- < ToggleControl
333
- __nextHasNoMarginBottom
330
+ < ToolsPanel
331
+ label = { __ ( 'Featured image' ) }
332
+ resetAll = { ( ) =>
333
+ setAttributes ( {
334
+ displayFeaturedImage : false ,
335
+ featuredImageAlign : undefined ,
336
+ featuredImageSizeSlug : 'thumbnail' ,
337
+ featuredImageSizeWidth : null ,
338
+ featuredImageSizeHeight : null ,
339
+ addLinkToFeaturedImage : false ,
340
+ } )
341
+ }
342
+ dropdownMenuProps = { dropdownMenuProps }
343
+ >
344
+ < ToolsPanelItem
345
+ hasValue = { ( ) => ! ! displayFeaturedImage }
334
346
label = { __ ( 'Display featured image' ) }
335
- checked = { displayFeaturedImage }
336
- onChange = { ( value ) =>
337
- setAttributes ( { displayFeaturedImage : value } )
347
+ onDeselect = { ( ) =>
348
+ setAttributes ( { displayFeaturedImage : false } )
338
349
}
339
- />
350
+ isShownByDefault
351
+ >
352
+ < ToggleControl
353
+ __nextHasNoMarginBottom
354
+ label = { __ ( 'Display featured image' ) }
355
+ checked = { displayFeaturedImage }
356
+ onChange = { ( value ) =>
357
+ setAttributes ( { displayFeaturedImage : value } )
358
+ }
359
+ />
360
+ </ ToolsPanelItem >
340
361
{ displayFeaturedImage && (
341
362
< >
342
- < ImageSizeControl
343
- onChange = { ( value ) => {
344
- const newAttrs = { } ;
345
- if ( value . hasOwnProperty ( 'width' ) ) {
346
- newAttrs . featuredImageSizeWidth =
347
- value . width ;
348
- }
349
- if ( value . hasOwnProperty ( 'height' ) ) {
350
- newAttrs . featuredImageSizeHeight =
351
- value . height ;
352
- }
353
- setAttributes ( newAttrs ) ;
354
- } }
355
- slug = { featuredImageSizeSlug }
356
- width = { featuredImageSizeWidth }
357
- height = { featuredImageSizeHeight }
358
- imageWidth = { defaultImageWidth }
359
- imageHeight = { defaultImageHeight }
360
- imageSizeOptions = { imageSizeOptions }
361
- imageSizeHelp = { __ (
362
- 'Select the size of the source image.'
363
- ) }
364
- onChangeImage = { ( value ) =>
363
+ < ToolsPanelItem
364
+ hasValue = { ( ) =>
365
+ featuredImageSizeSlug !== 'thumbnail' ||
366
+ featuredImageSizeWidth !== null ||
367
+ featuredImageSizeHeight !== null
368
+ }
369
+ label = { __ ( 'Image size' ) }
370
+ onDeselect = { ( ) =>
365
371
setAttributes ( {
366
- featuredImageSizeSlug : value ,
367
- featuredImageSizeWidth : undefined ,
368
- featuredImageSizeHeight : undefined ,
372
+ featuredImageSizeSlug : 'thumbnail' ,
373
+ featuredImageSizeWidth : null ,
374
+ featuredImageSizeHeight : null ,
369
375
} )
370
376
}
371
- />
372
- < ToggleGroupControl
373
- className = "editor-latest-posts-image-alignment-control"
374
- __nextHasNoMarginBottom
375
- __next40pxDefaultSize
377
+ isShownByDefault
378
+ >
379
+ < ImageSizeControl
380
+ onChange = { ( value ) => {
381
+ const newAttrs = { } ;
382
+ if ( value . hasOwnProperty ( 'width' ) ) {
383
+ newAttrs . featuredImageSizeWidth =
384
+ value . width ;
385
+ }
386
+ if ( value . hasOwnProperty ( 'height' ) ) {
387
+ newAttrs . featuredImageSizeHeight =
388
+ value . height ;
389
+ }
390
+ setAttributes ( newAttrs ) ;
391
+ } }
392
+ slug = { featuredImageSizeSlug }
393
+ width = { featuredImageSizeWidth }
394
+ height = { featuredImageSizeHeight }
395
+ imageWidth = { defaultImageWidth }
396
+ imageHeight = { defaultImageHeight }
397
+ imageSizeOptions = { imageSizeOptions }
398
+ imageSizeHelp = { __ (
399
+ 'Select the size of the source image.'
400
+ ) }
401
+ onChangeImage = { ( value ) =>
402
+ setAttributes ( {
403
+ featuredImageSizeSlug : value ,
404
+ featuredImageSizeWidth : undefined ,
405
+ featuredImageSizeHeight : undefined ,
406
+ } )
407
+ }
408
+ />
409
+ </ ToolsPanelItem >
410
+ < ToolsPanelItem
411
+ hasValue = { ( ) => ! ! featuredImageAlign }
376
412
label = { __ ( 'Image alignment' ) }
377
- value = { featuredImageAlign || 'none' }
378
- onChange = { ( value ) =>
413
+ onDeselect = { ( ) =>
379
414
setAttributes ( {
380
- featuredImageAlign :
381
- value !== 'none' ? value : undefined ,
415
+ featuredImageAlign : undefined ,
382
416
} )
383
417
}
418
+ isShownByDefault
384
419
>
385
- { imageAlignmentOptions . map (
386
- ( { value, icon, label } ) => {
387
- return (
388
- < ToggleGroupControlOptionIcon
389
- key = { value }
390
- value = { value }
391
- icon = { icon }
392
- label = { label }
393
- />
394
- ) ;
420
+ < ToggleGroupControl
421
+ className = "editor-latest-posts-image-alignment-control"
422
+ __nextHasNoMarginBottom
423
+ __next40pxDefaultSize
424
+ label = { __ ( 'Image alignment' ) }
425
+ value = { featuredImageAlign || 'none' }
426
+ onChange = { ( value ) =>
427
+ setAttributes ( {
428
+ featuredImageAlign :
429
+ value !== 'none'
430
+ ? value
431
+ : undefined ,
432
+ } )
395
433
}
396
- ) }
397
- </ ToggleGroupControl >
398
- < ToggleControl
399
- __nextHasNoMarginBottom
434
+ >
435
+ { imageAlignmentOptions . map (
436
+ ( { value, icon, label } ) => {
437
+ return (
438
+ < ToggleGroupControlOptionIcon
439
+ key = { value }
440
+ value = { value }
441
+ icon = { icon }
442
+ label = { label }
443
+ />
444
+ ) ;
445
+ }
446
+ ) }
447
+ </ ToggleGroupControl >
448
+ </ ToolsPanelItem >
449
+ < ToolsPanelItem
450
+ hasValue = { ( ) => ! ! addLinkToFeaturedImage }
400
451
label = { __ ( 'Add link to featured image' ) }
401
- checked = { addLinkToFeaturedImage }
402
- onChange = { ( value ) =>
452
+ onDeselect = { ( ) =>
403
453
setAttributes ( {
404
- addLinkToFeaturedImage : value ,
454
+ addLinkToFeaturedImage : false ,
405
455
} )
406
456
}
407
- />
457
+ isShownByDefault
458
+ >
459
+ < ToggleControl
460
+ __nextHasNoMarginBottom
461
+ label = { __ ( 'Add link to featured image' ) }
462
+ checked = { addLinkToFeaturedImage }
463
+ onChange = { ( value ) =>
464
+ setAttributes ( {
465
+ addLinkToFeaturedImage : value ,
466
+ } )
467
+ }
468
+ />
469
+ </ ToolsPanelItem >
408
470
</ >
409
471
) }
410
- </ PanelBody >
411
- < PanelBody title = { __ ( 'Sorting and filtering' ) } >
412
- < QueryControls
413
- { ...{ order, orderBy } }
414
- numberOfItems = { postsToShow }
415
- onOrderChange = { ( value ) =>
416
- setAttributes ( { order : value } )
417
- }
418
- onOrderByChange = { ( value ) =>
419
- setAttributes ( { orderBy : value } )
420
- }
421
- onNumberOfItemsChange = { ( value ) =>
422
- setAttributes ( { postsToShow : value } )
472
+ </ ToolsPanel >
473
+
474
+ < ToolsPanel
475
+ label = { __ ( 'Sorting and filtering' ) }
476
+ resetAll = { ( ) =>
477
+ setAttributes ( {
478
+ order : 'desc' ,
479
+ orderBy : 'date' ,
480
+ postsToShow : 5 ,
481
+ categories : undefined ,
482
+ selectedAuthor : undefined ,
483
+ columns : 3 ,
484
+ } )
485
+ }
486
+ dropdownMenuProps = { dropdownMenuProps }
487
+ >
488
+ < ToolsPanelItem
489
+ hasValue = { ( ) =>
490
+ order !== 'desc' ||
491
+ orderBy !== 'date' ||
492
+ postsToShow !== 5 ||
493
+ categories ?. length > 0 ||
494
+ ! ! selectedAuthor
423
495
}
424
- categorySuggestions = { categorySuggestions }
425
- onCategoryChange = { selectCategories }
426
- selectedCategories = { categories }
427
- onAuthorChange = { ( value ) =>
496
+ label = { __ ( 'Sort and filter' ) }
497
+ onDeselect = { ( ) =>
428
498
setAttributes ( {
429
- selectedAuthor :
430
- '' !== value ? Number ( value ) : undefined ,
499
+ order : 'desc' ,
500
+ orderBy : 'date' ,
501
+ postsToShow : 5 ,
502
+ categories : undefined ,
503
+ selectedAuthor : undefined ,
431
504
} )
432
505
}
433
- authorList = { authorList ?? [ ] }
434
- selectedAuthorId = { selectedAuthor }
435
- />
506
+ isShownByDefault
507
+ >
508
+ < QueryControls
509
+ { ...{ order, orderBy } }
510
+ numberOfItems = { postsToShow }
511
+ onOrderChange = { ( value ) =>
512
+ setAttributes ( { order : value } )
513
+ }
514
+ onOrderByChange = { ( value ) =>
515
+ setAttributes ( { orderBy : value } )
516
+ }
517
+ onNumberOfItemsChange = { ( value ) =>
518
+ setAttributes ( { postsToShow : value } )
519
+ }
520
+ categorySuggestions = { categorySuggestions }
521
+ onCategoryChange = { selectCategories }
522
+ selectedCategories = { categories }
523
+ onAuthorChange = { ( value ) =>
524
+ setAttributes ( {
525
+ selectedAuthor :
526
+ '' !== value ? Number ( value ) : undefined ,
527
+ } )
528
+ }
529
+ authorList = { authorList ?? [ ] }
530
+ selectedAuthorId = { selectedAuthor }
531
+ />
532
+ </ ToolsPanelItem >
436
533
437
534
{ postLayout === 'grid' && (
438
- < RangeControl
439
- __nextHasNoMarginBottom
440
- __next40pxDefaultSize
535
+ < ToolsPanelItem
536
+ hasValue = { ( ) => columns !== 3 }
441
537
label = { __ ( 'Columns' ) }
442
- value = { columns }
443
- onChange = { ( value ) =>
444
- setAttributes ( { columns : value } )
445
- }
446
- min = { 2 }
447
- max = {
448
- ! postCount
449
- ? MAX_POSTS_COLUMNS
450
- : Math . min ( MAX_POSTS_COLUMNS , postCount )
538
+ onDeselect = { ( ) =>
539
+ setAttributes ( {
540
+ columns : 3 ,
541
+ } )
451
542
}
452
- required
453
- />
543
+ isShownByDefault
544
+ >
545
+ < RangeControl
546
+ __nextHasNoMarginBottom
547
+ __next40pxDefaultSize
548
+ label = { __ ( 'Columns' ) }
549
+ value = { columns }
550
+ onChange = { ( value ) =>
551
+ setAttributes ( { columns : value } )
552
+ }
553
+ min = { 2 }
554
+ max = {
555
+ ! postCount
556
+ ? MAX_POSTS_COLUMNS
557
+ : Math . min ( MAX_POSTS_COLUMNS , postCount )
558
+ }
559
+ required
560
+ />
561
+ </ ToolsPanelItem >
454
562
) }
455
- </ PanelBody >
563
+ </ ToolsPanel >
456
564
</ >
457
565
) ;
458
566
}
0 commit comments