1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-11 14:04:03 +00:00
Files
browser/libs/components/src/table/table.component.ts
Will Martin 827c4c0301 [PM-15847] libs/components strict migration (#15738)
This PR migrates `libs/components` to use strict TypeScript.

- Remove `@ts-strict-ignore` from each file in `libs/components` and resolved any new compilation errors
- Converted ViewChild and ContentChild decorators to use the new signal-based queries using the [Angular signal queries migration](https://angular.dev/reference/migrations/signal-queries)
  - Made view/content children `required` where appropriate, eliminating the need for additional null checking. This helped simplify the strict migration.

---

Co-authored-by: Vicki League <vleague@bitwarden.com>
2025-08-18 15:36:45 -04:00

67 lines
1.6 KiB
TypeScript

import { isDataSource } from "@angular/cdk/collections";
import { CommonModule } from "@angular/common";
import {
AfterContentChecked,
Component,
Directive,
OnDestroy,
TemplateRef,
input,
contentChild,
} from "@angular/core";
import { Observable } from "rxjs";
import { TableDataSource } from "./table-data-source";
@Directive({
selector: "ng-template[body]",
})
export class TableBodyDirective {
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
constructor(public readonly template: TemplateRef<any>) {}
}
@Component({
selector: "bit-table",
templateUrl: "./table.component.html",
imports: [CommonModule],
})
export class TableComponent implements OnDestroy, AfterContentChecked {
readonly dataSource = input<TableDataSource<any>>();
readonly layout = input<"auto" | "fixed">("auto");
readonly templateVariable = contentChild(TableBodyDirective);
protected rows$?: Observable<any[]>;
private _initialized = false;
get tableClass() {
return [
"tw-w-full",
"tw-leading-normal",
"tw-text-main",
"tw-border-collapse",
"tw-text-start",
this.layout() === "auto" ? "tw-table-auto" : "tw-table-fixed",
];
}
ngAfterContentChecked(): void {
const dataSource = this.dataSource();
if (!this._initialized && isDataSource(dataSource)) {
this._initialized = true;
const dataStream = dataSource.connect();
this.rows$ = dataStream;
}
}
ngOnDestroy(): void {
const dataSource = this.dataSource();
if (isDataSource(dataSource)) {
dataSource.disconnect();
}
}
}