Add table.component.ts
Create the following file in your project.
import { ChangeDetectionStrategy, Component, computed, input, ViewEncapsulation } from '@angular/core';
import type { ClassValue } from 'clsx';
import {
type ZardTableSizeVariants,
type ZardTableTypeVariants,
tableBodyVariants,
tableCaptionVariants,
tableCellVariants,
tableHeaderVariants,
tableHeadVariants,
tableRowVariants,
tableVariants,
} from '@/shared/components/table/table.variants';
import { mergeClasses } from '@/shared/utils/merge-classes';
@Component({
selector: 'table[z-table]',
template: `
<ng-content />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': 'classes()',
},
exportAs: 'zTable',
})
export class ZardTableComponent {
readonly zType = input<ZardTableTypeVariants>('default');
readonly zSize = input<ZardTableSizeVariants>('default');
readonly class = input<ClassValue>('');
protected readonly classes = computed(() =>
mergeClasses(
tableVariants({
zType: this.zType(),
zSize: this.zSize(),
}),
this.class(),
),
);
}
@Component({
selector: 'thead[z-table-header]',
template: `
<ng-content />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': 'classes()',
},
exportAs: 'zTableHeader',
})
export class ZardTableHeaderComponent {
readonly class = input<ClassValue>('');
protected readonly classes = computed(() => mergeClasses(tableHeaderVariants(), this.class()));
}
@Component({
selector: 'tbody[z-table-body]',
template: `
<ng-content />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': 'classes()',
},
exportAs: 'zTableBody',
})
export class ZardTableBodyComponent {
readonly class = input<ClassValue>('');
protected readonly classes = computed(() => mergeClasses(tableBodyVariants(), this.class()));
}
@Component({
selector: 'tr[z-table-row]',
template: `
<ng-content />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': 'classes()',
},
exportAs: 'zTableRow',
})
export class ZardTableRowComponent {
readonly class = input<ClassValue>('');
protected readonly classes = computed(() => mergeClasses(tableRowVariants(), this.class()));
}
@Component({
selector: 'th[z-table-head]',
template: `
<ng-content />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': 'classes()',
},
exportAs: 'zTableHead',
})
export class ZardTableHeadComponent {
readonly class = input<ClassValue>('');
protected readonly classes = computed(() => mergeClasses(tableHeadVariants(), this.class()));
}
@Component({
selector: 'td[z-table-cell]',
template: `
<ng-content />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': 'classes()',
},
exportAs: 'zTableCell',
})
export class ZardTableCellComponent {
readonly class = input<ClassValue>('');
protected readonly classes = computed(() => mergeClasses(tableCellVariants(), this.class()));
}
@Component({
selector: 'caption[z-table-caption]',
template: `
<ng-content />
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': 'classes()',
},
exportAs: 'zTableCaption',
})
export class ZardTableCaptionComponent {
readonly class = input<ClassValue>('');
protected readonly classes = computed(() => mergeClasses(tableCaptionVariants(), this.class()));
}