|
| 1 | +import { SortHeaderComponent } from '@/ui/table/sort-header.component'; |
| 2 | +import { SortDirective } from '@/ui/table/sort.directive'; |
| 3 | +import { TableLayoutComponent } from '@/ui/table/table-layout.component'; |
| 4 | +import { TablePaginationComponent } from '@/ui/table/table-pagination.component'; |
| 5 | +import { TableDirective } from '@/ui/table/table.directive'; |
| 6 | +import { SortChangeType } from '@/ui/table/table.types'; |
| 7 | +import { TdDirective } from '@/ui/table/td.directive'; |
| 8 | +import { ThDirective } from '@/ui/table/th.directive'; |
| 9 | +import { HeadTrDirective } from '@/ui/table/tr-head.directive'; |
| 10 | +import { TrDirective } from '@/ui/table/tr.directive'; |
| 11 | +import { |
| 12 | + ChangeDetectionStrategy, |
| 13 | + Component, |
| 14 | + computed, |
| 15 | + signal, |
| 16 | +} from '@angular/core'; |
| 17 | + |
| 18 | +export interface PeriodicElement { |
| 19 | + name: string; |
| 20 | + position: number; |
| 21 | + weight: number; |
| 22 | + symbol: string; |
| 23 | +} |
| 24 | + |
| 25 | +const LIMIT = 30; |
| 26 | + |
| 27 | +const elementNames = [ |
| 28 | + 'Hydrogen', |
| 29 | + 'Helium', |
| 30 | + 'Lithium', |
| 31 | + 'Beryllium', |
| 32 | + 'Boron', |
| 33 | + 'Carbon', |
| 34 | + 'Nitrogen', |
| 35 | + 'Oxygen', |
| 36 | + 'Fluorine', |
| 37 | + 'Neon', |
| 38 | +]; |
| 39 | +const elementSymbols = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne']; |
| 40 | + |
| 41 | +export function generatePeriodicElements(count = 500): PeriodicElement[] { |
| 42 | + const elements: PeriodicElement[] = []; |
| 43 | + |
| 44 | + for (let i = 0; i < count; i++) { |
| 45 | + const randomIndex = Math.floor(Math.random() * elementNames.length); |
| 46 | + elements.push({ |
| 47 | + name: elementNames[randomIndex], |
| 48 | + position: i + 1, |
| 49 | + weight: parseFloat((Math.random() * 200).toFixed(2)), |
| 50 | + symbol: elementSymbols[randomIndex], |
| 51 | + }); |
| 52 | + } |
| 53 | + |
| 54 | + return elements; |
| 55 | +} |
| 56 | + |
| 57 | +// Example usage |
| 58 | +const ELEMENT_DATA = generatePeriodicElements(); |
| 59 | + |
| 60 | +@Component({ |
| 61 | + selector: 'doc-show-case-table', |
| 62 | + imports: [ |
| 63 | + SortDirective, |
| 64 | + TableDirective, |
| 65 | + TrDirective, |
| 66 | + TdDirective, |
| 67 | + ThDirective, |
| 68 | + HeadTrDirective, |
| 69 | + TableLayoutComponent, |
| 70 | + SortHeaderComponent, |
| 71 | + SortDirective, |
| 72 | + TablePaginationComponent, |
| 73 | + ], |
| 74 | + templateUrl: './show-case-table.component.html', |
| 75 | + styleUrl: './show-case-table.component.css', |
| 76 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 77 | +}) |
| 78 | +export class ShowCaseTableComponent { |
| 79 | + data = signal(ELEMENT_DATA); |
| 80 | + currentPage = signal(0); |
| 81 | + totalPages = computed(() => Math.ceil(this.data().length / LIMIT)); |
| 82 | + |
| 83 | + selectedRow = signal<PeriodicElement | undefined>(undefined); |
| 84 | + |
| 85 | + sortChange($event: SortChangeType) { |
| 86 | + console.log($event); |
| 87 | + } |
| 88 | + |
| 89 | + setPage(page: number) { |
| 90 | + this.currentPage.set(page); |
| 91 | + } |
| 92 | + |
| 93 | + selectRow($event: PeriodicElement) { |
| 94 | + this.selectedRow.set($event); |
| 95 | + } |
| 96 | +} |
0 commit comments