refactor(keyword-highlighting): remove duplication after rebase

This commit is contained in:
2026-08-24 21:49:05 +02:00
parent 2f509fbbfe
commit 56ada07d97
16 changed files with 222 additions and 149 deletions
@@ -8,6 +8,31 @@
matSort
(matSortChange)="_handleSortChange($event)"
multiTemplateDataRows>
@if (detailTemplate()) {
<ng-container [matColumnDef]="expandColumnId">
<th mat-header-cell *matHeaderCellDef class="expand-cell"></th>
<td mat-cell *matCellDef="let row" class="expand-cell">
@if (isExpandable(row)) {
@let expanded = row === expandedElement();
<button
mat-icon-button
type="button"
[attr.aria-expanded]="expanded"
[matTooltip]="
expanded ? 'Details ausblenden' : 'Details anzeigen'
"
[attr.aria-label]="
expanded ? 'Details ausblenden' : 'Details anzeigen'
">
<mat-icon class="expand-icon" [class.is-expanded]="expanded">
expand_more
</mat-icon>
</button>
}
</td>
</ng-container>
}
@for (col of columns(); track col.id) {
<ng-container [matColumnDef]="col.id">
@if (col.headerTemplate) {
@@ -27,3 +27,18 @@ tr.detail-row {
background: var(--sg-surface-soft);
cursor: pointer;
}
.expand-cell {
width: 1%;
white-space: nowrap;
padding-right: 0;
}
.expand-icon {
color: var(--sg-text-muted);
transition: transform 150ms ease-in-out;
&.is-expanded {
transform: rotate(180deg);
}
}
@@ -19,6 +19,9 @@ import {
SortDirection,
} from '@angular/material/sort';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';
import { ActivatedRoute, Router } from '@angular/router';
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
export interface BaseColumn<T> {
@@ -43,7 +46,15 @@ export type GenericColumn<T> = AccessorColumn<T> | DisplayColumn<T>;
@Component({
selector: 'app-data-table',
standalone: true,
imports: [MatTableModule, NgTemplateOutlet, MatSortModule, SkTextDirective],
imports: [
MatTableModule,
NgTemplateOutlet,
MatSortModule,
MatButtonModule,
MatIconModule,
MatTooltipModule,
SkTextDirective,
],
templateUrl: './data-table.component.html',
styleUrl: './data-table.component.scss',
})
@@ -54,6 +65,7 @@ export class DataTableComponent<T> implements AfterViewInit {
detailTemplate = input<TemplateRef<any> | null>(null);
expandedElement = signal<T | null>(null);
canExpand = input<((row: T) => boolean) | null>(null);
maxHeight = input<string | null>(null);
containerOverflow = computed(() => (this.maxHeight() ? 'auto' : 'visible'));
@@ -78,7 +90,12 @@ export class DataTableComponent<T> implements AfterViewInit {
handleSortChange = output<Sort>();
displayedColumns = computed(() => this.columns().map((col) => col.id));
readonly expandColumnId = 'expand';
displayedColumns = computed(() => {
const ids = this.columns().map((col) => col.id);
return this.detailTemplate() ? [this.expandColumnId, ...ids] : ids;
});
dataSource = new MatTableDataSource<T>([]);
sort = viewChild.required(MatSort);
@@ -160,8 +177,13 @@ export class DataTableComponent<T> implements AfterViewInit {
}
}
isExpandable(row: T): boolean {
if (!this.detailTemplate()) return false;
return this.canExpand()?.(row) ?? true;
}
toggleRow(row: T): void {
if (!this.detailTemplate()) return;
if (!this.isExpandable(row)) return;
this.expandedElement.update((current) => (current === row ? null : row));
}
}