Add buttons to list field

This commit is contained in:
2024-06-29 14:40:25 +09:30
parent ddc20daaa5
commit 0f60377e91
2 changed files with 27 additions and 6 deletions

View File

@@ -1,3 +1,7 @@
:host {
display: block;
}
.row-wrapper {
display: flex;
}

View File

@@ -18,17 +18,34 @@ import {
selector: 'app-list-field',
standalone: true,
imports: [CommonModule, MatButton, MatIconModule, ProtoFieldComponent],
template: ` @for(value of values(); track values()) {
template: ` @for(value of values(); track $index) {
<div class="row-wrapper">
<app-proto-field
[configuration]="configuration().subConfiguration"
[value]="value"
></app-proto-field>
<button mat-icon-button (click)="remove($index)">
<mat-icon>remove</mat-icon>
</button>
</div>
}
<button mat-icon-button><mat-icon>add</mat-icon></button>`,
<button mat-icon-button (click)="add()"><mat-icon>add</mat-icon></button>`,
styleUrl: './list-field.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ListFieldComponent {
configuration = input.required<ListMessage>();
values = model<any[]>();
add() {
const newValues = this.values();
newValues?.push(null);
this.values.set(newValues);
}
remove(index: number) {
const newValues = this.values();
newValues?.splice(index, 1);
this.values.set(newValues);
}
}