import { ChangeDetectionStrategy, Component, ViewEncapsulation, HostBinding, Input, OnChanges, } from "@angular/core"; import { CdkTable, CDK_TABLE } from "@angular/cdk/table"; /** Workaround for https://github.com/angular/angular/issues/17849 */ export const _SamTable = CdkTable; /** * Wrapper for the CdkTable with Material design styles. * * `CDK_TABLE_TEMPLATE` is no longer exported from `@angular/cdk/table` as of * CDK 20 (the template is now inlined directly in `CdkTable`'s own * `@Component` decorator), so this is a local copy of that same template * kept in sync with `@angular/cdk/table`'s `CdkTable` component template. */ @Component({ selector: "sam-datatable, table[sam-datatable]", template: ` @if (_isServer) { } @if (_isNativeHtmlTable) { } @else { } `, providers: [ { provide: CdkTable, useExisting: SamDataTableComponent }, { provide: CDK_TABLE, useExisting: SamDataTableComponent }, ], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, }) export class SamDataTableComponent extends _SamTable implements OnChanges { @Input() allowHorizontalScroll = false; @HostBinding("class.sam-datatable-horizontal") samTableHorizontalClass = this.allowHorizontalScroll; ngOnChanges(c) { if (c.allowHorizontalScroll) { this.samTableHorizontalClass = this.allowHorizontalScroll; } } }