feat: add list with actions component
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
import { SimpleListItemAction } from "./SimpleListItemAction";
|
||||||
|
|
||||||
|
export class SimpleListItem {
|
||||||
|
constructor(public id: string, public text: string = '', public actions: SimpleListItemAction[] = []) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export class SimpleListItemAction {
|
||||||
|
constructor(public icon: string, public action: string) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<mat-list>
|
||||||
|
@for (item of items(); track item.id) {
|
||||||
|
<mat-list-item>
|
||||||
|
{{ item.text }}
|
||||||
|
@if (item.actions; as actions) {
|
||||||
|
<div matListItemMeta>
|
||||||
|
@for (action of actions; track action.action) {
|
||||||
|
<button matIconButton (click)="this.action.emit({action: action.action, subject: item.id})">
|
||||||
|
<mat-icon>{{ action.icon }}</mat-icon>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</mat-list-item>
|
||||||
|
<mat-divider></mat-divider>
|
||||||
|
}
|
||||||
|
</mat-list>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { SimpleListWActions } from './simple-list-w-actions';
|
||||||
|
|
||||||
|
describe('SimpleListWActions', () => {
|
||||||
|
let component: SimpleListWActions;
|
||||||
|
let fixture: ComponentFixture<SimpleListWActions>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [SimpleListWActions]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(SimpleListWActions);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { Component, input, output } from '@angular/core';
|
||||||
|
import { MatIconButton } from '@angular/material/button';
|
||||||
|
import { MatIcon } from '@angular/material/icon';
|
||||||
|
import { MatDivider, MatListModule } from '@angular/material/list';
|
||||||
|
import { SimpleListItem } from './SimpleListItem';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-simple-list-w-actions',
|
||||||
|
imports: [MatListModule, MatIcon, MatDivider, MatIconButton],
|
||||||
|
templateUrl: './simple-list-w-actions.html',
|
||||||
|
styleUrl: './simple-list-w-actions.scss',
|
||||||
|
})
|
||||||
|
export class SimpleListWActions {
|
||||||
|
readonly action = output<{action: string, subject: string}>()
|
||||||
|
readonly items = input<SimpleListItem[]>([])
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user