-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathperson-list.component.ts
More file actions
67 lines (61 loc) · 1.77 KB
/
person-list.component.ts
File metadata and controls
67 lines (61 loc) · 1.77 KB
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
57
58
59
60
61
62
63
64
65
66
67
import { Component, Input } from '@angular/core';
import { CDFlashingDirective } from '@angular-challenges/shared/directives';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MatChipsModule } from '@angular/material/chips';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
@Component({
selector: 'app-person-list',
imports: [
CommonModule,
FormsModule,
MatListModule,
MatFormFieldModule,
MatInputModule,
MatChipsModule,
CDFlashingDirective,
],
template: `
<h1 cd-flash class="text-center font-semibold" title="Title">
{{ title | titlecase }}
</h1>
<mat-form-field class="w-4/5" cd-flash>
<input
placeholder="Add one member to the list"
matInput
type="text"
[(ngModel)]="label"
(keydown)="handleKey($event)" />
</mat-form-field>
<mat-list class="flex w-full">
<div *ngIf="names?.length === 0" class="empty-list-label">Empty list</div>
<mat-list-item
*ngFor="let name of names"
cd-flash
class="text-orange-500">
<div MatListItemLine class="flex justify-between">
<h3 title="Name">
{{ name }}
</h3>
</div>
</mat-list-item>
<mat-divider *ngIf="names?.length !== 0"></mat-divider>
</mat-list>
`,
host: {
class: 'w-full flex flex-col items-center',
},
})
export class PersonListComponent {
@Input() names: string[] = [];
@Input() title = '';
label = '';
handleKey(event: KeyboardEvent) {
if (event.key === 'Enter') {
this.names?.unshift(this.label);
this.label = '';
}
}
}