This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 764
/
color-filter.ts
56 lines (50 loc) · 1.52 KB
/
color-filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (c) 2016-2020 VMware, Inc. All Rights Reserved.
* This software is released under MIT license.
* The full license information can be found in LICENSE in the root directory of this project.
*/
import { Component, EventEmitter } from '@angular/core';
import { ClrDatagridFilterInterface } from '@clr/angular';
import { User } from '../inventory/user';
import { COLORS } from '../inventory/values';
@Component({
selector: 'clr-datagrid-color-filter-demo',
template: ` <span
*ngFor="let color of allColors"
class="color-square color-selectable"
(click)="toggleColor(color)"
[style.backgroundColor]="color"
[class.color-selected]="selectedColors[color]"
></span>`,
styleUrls: ['../datagrid.demo.scss'],
})
export class ColorFilter implements ClrDatagridFilterInterface<User> {
allColors = COLORS;
selectedColors: { [color: string]: boolean } = {};
nbColors = 0;
changes: any = new EventEmitter<any>(false);
listSelected(): string[] {
const list: string[] = [];
for (const color in this.selectedColors) {
if (this.selectedColors[color]) {
list.push(color);
}
}
return list;
}
toggleColor(color: string) {
this.selectedColors[color] = !this.selectedColors[color];
if (this.selectedColors[color]) {
this.nbColors++;
} else {
this.nbColors--;
}
this.changes.emit(true);
}
accepts(user: User) {
return this.nbColors === 0 || this.selectedColors[user.color];
}
isActive(): boolean {
return this.nbColors > 0;
}
}