-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-table.ts
More file actions
54 lines (47 loc) · 1.74 KB
/
Copy pathdata-table.ts
File metadata and controls
54 lines (47 loc) · 1.74 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
import { Component, ChangeDetectionStrategy, input, output, computed } from '@angular/core';
import { AppIconComponent } from '../icon/app-icon';
import { SkeletonComponent } from '../skeleton/skeleton';
import { EmptyStateComponent } from '../empty-state/empty-state';
export interface ColumnDef<T> {
key: string;
header: string;
width?: string;
sortable?: boolean;
align?: 'left' | 'center' | 'right';
cell?: (row: T) => string | number | boolean;
}
@Component({
selector: 'app-data-table',
standalone: true,
imports: [AppIconComponent, SkeletonComponent, EmptyStateComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './data-table.html',
styleUrl: './data-table.css'
})
export class DataTableComponent<T extends Record<string, unknown>> {
readonly columns = input.required<ColumnDef<T>[]>();
readonly data = input.required<T[]>();
readonly loading = input<boolean>(false);
readonly hasActions = input<boolean>(true);
readonly roundedBottom = input<boolean>(true);
readonly emptyTitle = input<string>('Nenhum dado encontrado');
readonly emptyDescription = input<string>('Não existem registros cadastrados para exibição.');
readonly containerClasses = computed(() => {
const base = 'w-full bg-white dark:bg-slate-800 border border-gray-200/80 dark:border-slate-700/80 shadow-2xs overflow-hidden';
return this.roundedBottom()
? `${base} rounded-[12px]`
: `${base} rounded-t-[12px] border-b-0`;
});
readonly rowClick = output<T>();
readonly editRow = output<T>();
readonly deleteRow = output<T>();
onRowClick(row: T): void {
this.rowClick.emit(row);
}
onEdit(row: T): void {
this.editRow.emit(row);
}
onDelete(row: T): void {
this.deleteRow.emit(row);
}
}