@@ -28,6 +28,8 @@ export default class DaList extends LitElement {
28
28
newItem : { attribute : false } ,
29
29
_permissions : { state : true } ,
30
30
_listItems : { state : true } ,
31
+ _filter : { state : true } ,
32
+ _showFilter : { state : true } ,
31
33
_selectedItems : { state : true } ,
32
34
_dropFiles : { state : true } ,
33
35
_dropMessage : { state : true } ,
@@ -39,6 +41,7 @@ export default class DaList extends LitElement {
39
41
this . _dropFiles = [ ] ;
40
42
this . _dropMessage = 'Drop content here' ;
41
43
this . _lastCheckedIndex = null ;
44
+ this . _filter = '' ;
42
45
}
43
46
44
47
connectedCallback ( ) {
@@ -378,6 +381,28 @@ export default class DaList extends LitElement {
378
381
this . handleSort ( this . _sortDate , 'lastModified' ) ;
379
382
}
380
383
384
+ toggleFilterView ( ) {
385
+ this . _filter = '' ;
386
+ this . _showFilter = ! this . _showFilter ;
387
+ const filterInput = this . shadowRoot ?. querySelector ( 'input[name="filter"]' ) ;
388
+ filterInput . value = '' ;
389
+ if ( this . _showFilter ) {
390
+ this . wait ( 1 ) . then ( ( ) => { filterInput . focus ( ) ; } ) ;
391
+ }
392
+ }
393
+
394
+ handleFilterBlur ( e ) {
395
+ if ( e . target . value === '' ) {
396
+ this . _showFilter = false ;
397
+ }
398
+ }
399
+
400
+ handleNameFilter ( e ) {
401
+ this . _sortName = undefined ;
402
+ this . _sortDate = undefined ;
403
+ this . _filter = e . target . value ;
404
+ }
405
+
381
406
get isSelectAll ( ) {
382
407
const selectCount = this . _listItems . filter ( ( item ) => item . isChecked ) . length ;
383
408
return selectCount === this . _listItems . length && this . _listItems . length !== 0 ;
@@ -440,21 +465,33 @@ export default class DaList extends LitElement {
440
465
}
441
466
442
467
render ( ) {
468
+ const filteredItems = this . _listItems . filter ( ( item ) => item . name . includes ( this . _filter ) ) ;
469
+
443
470
return html `
444
471
< div class ="da-browse-panel-header ">
445
472
${ this . renderCheckBox ( ) }
446
473
< div class ="da-browse-sort ">
447
- < span > </ span >
474
+ <!-- Toggle button is split into 2 buttons (enable/disable) to prevent bug re-toggling on blur event -->
475
+ ${ ! this . _showFilter ? html `
476
+ < button class ="da-browse-filter " name ="toggle-filter " @click =${ ( ) => this . toggleFilterView ( ) } >
477
+ < img class ="toggle-icon-dark " width ="20 " src ="/blocks/browse/da-browse/img/Filter20.svg " />
478
+ </ button >
479
+ ` : html `
480
+ < button class ="da-browse-filter selected " name ="toggle-filter " @click =${ ( ) => this . toggleFilterView ( ) } >
481
+ < img class ="toggle-icon-dark " width ="20 " src ="/blocks/browse/da-browse/img/Filter20.svg " />
482
+ </ button >
483
+ ` }
448
484
< div class ="da-browse-header-container ">
449
- < button class ="da-browse-header-name ${ this . _sortName } " @click =${ this . handleNameSort } > Name</ button >
485
+ < input @blur =${ this . handleFilterBlur } name ="filter" class=${ this . _showFilter ? 'show' : nothing } @change=${ this . handleNameFilter } @keyup=${ this . handleNameFilter } type="text" placeholder="Filter">
486
+ < button class ="da-browse-header-name ${ this . _sortName } ${ this . _showFilter ? 'hide' : '' } " @click =${ this . handleNameSort } > Name</ button >
450
487
</ div >
451
488
< div class ="da-browse-header-container ">
452
489
< button class ="da-browse-header-name ${ this . _sortDate } " @click =${ this . handleDateSort } > Modified</ button >
453
490
</ div >
454
491
</ div >
455
492
</ div >
456
493
< div class ="da-browse-panel " @dragenter =${ this . drag ? this . dragenter : nothing } @dragleave =${ this . drag ? this . dragleave : nothing } >
457
- ${ this . _listItems ?. length > 0 ? this . renderList ( this . _listItems , true ) : this . renderEmpty ( ) }
494
+ ${ filteredItems ?. length > 0 ? this . renderList ( filteredItems , true ) : this . renderEmpty ( ) }
458
495
${ this . drag ? this . renderDropArea ( ) : nothing }
459
496
</ div >
460
497
< da-actionbar
0 commit comments