-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add a custom 'curve-data-table' component #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
loofpc
wants to merge
16
commits into
main
Choose a base branch
from
feat/custom-data-table-wrapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3a5931e
feat: add a custom 'curve-data-table' component that wraps the comple…
c1219dd
Merge branch 'main' into feat/custom-data-table-wrapper
d6ea25b
fix: contract for curve-data-table to conform with updates from main …
71ebfd8
fix: typo in display texts.
6bc524e
fix: imports, change detection and a let/const.
68cda5f
feat: add link token to Button link variant (React + Angular)
sjoerdbeentjes 2ab07b5
fix(angular): make build:css cross-platform
sjoerdbeentjes f86be66
chore(angular): simplify copy-font-files comment
sjoerdbeentjes 1a8d570
chore(angular): drop changeset for build script fix
sjoerdbeentjes f66cbf5
chore: version packages
github-actions[bot] 10590ec
docs: add package READMEs for curve-react and curve-angular
sjoerdbeentjes 3343bc8
docs: add changeset for package READMEs
sjoerdbeentjes 27ffd80
docs: correct published/private status of packages
sjoerdbeentjes 107ab49
chore: version packages
github-actions[bot] dfef470
fix: explanation of curve-data-table story.
53accba
Merge remote-tracking branch 'origin/main' into feat/custom-data-tabl…
sjoerdbeentjes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
apps/angular-app/src/app/custom-data-table/custom-data-table.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <p> | ||
| Dit is bijna dezelfde tabel, maar deze gebruikt een wrapper component die tabelconfiguratie | ||
| grotendeels standaardiseert, waardoor het gebruik er van een stuk eenvoudiger is. Het wordt | ||
| daarmee ook opinionated, maar dat wil je tot op zekere hoogte ook om consistentie af te dwingen. | ||
| </p> | ||
|
|
||
| <curve-data-table | ||
| [data]="data" | ||
| [columns]="columns" | ||
| searchColumn="app" | ||
| (rowActionTriggered)="rowActionTriggered($event)" | ||
| ></curve-data-table> | ||
|
|
||
| <br /><br /> | ||
| <p>Laatst uitgevoerde actie: {{ lastActionDisplay }}</p> | ||
106 changes: 106 additions & 0 deletions
106
apps/angular-app/src/app/custom-data-table/custom-data-table.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { provideIcons } from '@ng-icons/core'; | ||
| import { phosphorPlus } from '@ng-icons/phosphor-icons/regular'; | ||
| import { | ||
| ICurveDataTableColumn, | ||
| CurveDataTableImports, | ||
| CurveDataTableActionColumn, | ||
| CurveDataTableImageColumn, | ||
| CurveDataTableSelectionColumn, | ||
| CurveDataTableStringColumn, | ||
| CurveDataTableRowEvent, | ||
| } from '@surfnet/curve-angular'; | ||
|
|
||
| type App = { | ||
| id: string; | ||
| imageUrl?: string; | ||
| app: string; | ||
| vendor: string; | ||
| revenue: number; | ||
| }; | ||
|
|
||
| const data: App[] = [ | ||
| { | ||
| id: '1', | ||
| imageUrl: 'https://picsum.photos/seed/123/40', | ||
| app: '10voordeleraar-loa1', | ||
| vendor: '10voordeleraar-loa1', | ||
| revenue: 199, | ||
| }, | ||
| { | ||
| id: '2', | ||
| imageUrl: 'https://picsum.photos/seed/321/40', | ||
| app: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| vendor: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| revenue: 199, | ||
| }, | ||
| { | ||
| id: '3', | ||
| app: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| vendor: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| revenue: 199, | ||
| }, | ||
| { | ||
| id: '4', | ||
| app: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| vendor: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| revenue: 199, | ||
| }, | ||
| { | ||
| id: '5', | ||
| imageUrl: 'https://picsum.photos/seed/123/40', | ||
| app: '10voordeleraar-loa1', | ||
| vendor: '10voordeleraar-loa1', | ||
| revenue: 199, | ||
| }, | ||
| { | ||
| id: '6', | ||
| app: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| vendor: '10voordeleraar-loa2-without-interaction-with-mail', | ||
| revenue: 199, | ||
| }, | ||
| { | ||
| id: '7', | ||
| imageUrl: 'https://picsum.photos/seed/123/40', | ||
| app: '10voordeleraar-loa1', | ||
| vendor: '10voordeleraar-loa1', | ||
| revenue: 199, | ||
| }, | ||
| { | ||
| id: '8', | ||
| imageUrl: 'https://picsum.photos/seed/123/40', | ||
| app: '10voordeleraar-loa1', | ||
| vendor: '10voordeleraar-loa1', | ||
| revenue: 199, | ||
| }, | ||
| ]; | ||
|
|
||
| @Component({ | ||
| selector: 'app-custom-data-table', | ||
| templateUrl: './custom-data-table.component.html', | ||
| imports: [CurveDataTableImports], | ||
| providers: [provideIcons({ phosphorPlus })], | ||
| }) | ||
| export class CustomDataTableComponent { | ||
| public lastActionDisplay: string = ''; | ||
| public data = data; | ||
| public columns: ICurveDataTableColumn[] = [ | ||
| new CurveDataTableSelectionColumn(), | ||
| new CurveDataTableImageColumn('imageUrl'), | ||
| new CurveDataTableStringColumn('app', 'App'), | ||
| new CurveDataTableStringColumn('vendor', 'Vendor'), | ||
| new CurveDataTableStringColumn('revenue', 'Revenue', (value: number) => | ||
| this.currencyFormatter.format(value), | ||
| ), | ||
| new CurveDataTableActionColumn(['Go to details', 'Set inactive']), | ||
| ]; | ||
|
|
||
| private currencyFormatter = new Intl.NumberFormat('en-US', { | ||
| style: 'currency', | ||
| currency: 'USD', | ||
| }); | ||
|
|
||
| protected rowActionTriggered(event: CurveDataTableRowEvent<App>) { | ||
| this.lastActionDisplay = `'${event.action}' op rij ${event.record.id}`; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { CurveDataTableComponent } from './lib/curve-data-table'; | ||
|
|
||
| export * from './lib/curve-data-table'; | ||
| export * from './lib/model/curve-data-table-column'; | ||
| export * from './lib/model/curve-data-table-action-column'; | ||
| export * from './lib/model/curve-data-table-image-column'; | ||
| export * from './lib/model/curve-data-table-selection-column'; | ||
| export * from './lib/model/curve-data-table-string-column'; | ||
| export * from './lib/model/curve-data-table-row-event'; | ||
|
|
||
| export const CurveDataTableImports = [CurveDataTableComponent] as const; |
36 changes: 36 additions & 0 deletions
36
packages/angular/src/lib/ui/curve-data-table/src/lib/curve-data-table-action-cell.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { Component, ChangeDetectionStrategy, input, output } from '@angular/core'; | ||
| import { NgIcon, provideIcons } from '@ng-icons/core'; | ||
| import { phosphorDotsThree } from '@ng-icons/phosphor-icons/regular'; | ||
| import { HlmDropdownMenuImports } from '../../../dropdown-menu/src'; | ||
| import { CurveDataTableRowEvent } from './model/curve-data-table-row-event'; | ||
|
|
||
| @Component({ | ||
| selector: 'data-table-action-cell', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| imports: [HlmDropdownMenuImports, NgIcon], | ||
| providers: [provideIcons({ phosphorDotsThree })], | ||
| template: ` | ||
| <button hlmBtn variant="ghost" size="sm" [hlmDropdownMenuTrigger]="menu"> | ||
| <ng-icon name="phosphorDotsThree" /> | ||
| </button> | ||
| <ng-template #menu> | ||
| <hlm-dropdown-menu align="start" class="w-48"> | ||
| @for (action of actions(); track action) { | ||
| <button hlmDropdownMenuItem (click)="onActionClick(action)"> | ||
| {{ action }} | ||
| </button> | ||
| } | ||
| </hlm-dropdown-menu> | ||
| </ng-template> | ||
| `, | ||
| }) | ||
| export class DataTableActionCell<TData> { | ||
| public readonly record = input.required<TData>(); | ||
| public readonly actions = input.required<string[]>(); | ||
| public actionTriggered = output<CurveDataTableRowEvent<TData>>(); | ||
|
|
||
| onActionClick(action: string) { | ||
| const event: CurveDataTableRowEvent<TData> = { action: action, record: this.record() }; | ||
| this.actionTriggered.emit(event); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
packages/angular/src/lib/ui/curve-data-table/src/lib/curve-data-table-header-sortable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { ChangeDetectionStrategy, Component, input } from '@angular/core'; | ||
| import { NgIcon, provideIcons } from '@ng-icons/core'; | ||
| import { phosphorArrowsDownUp } from '@ng-icons/phosphor-icons/regular'; | ||
| import { Column } from '@tanstack/angular-table'; | ||
| import { HlmButton } from '../../../button/src'; | ||
|
|
||
| @Component({ | ||
| selector: 'data-table-header-sortable', | ||
| imports: [HlmButton, NgIcon], | ||
| providers: [provideIcons({ phosphorArrowsDownUp })], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: ` | ||
| <button | ||
| hlmBtn | ||
| variant="ghost" | ||
| size="sm" | ||
| (click)="column().toggleSorting(column().getIsSorted() === 'asc')" | ||
| > | ||
| {{ label() }} | ||
| <ng-icon name="phosphorArrowsDownUp" data-icon="inline-end" /> | ||
| </button> | ||
| `, | ||
| }) | ||
| export class DataTableHeaderSortable<TData> { | ||
| public readonly label = input.required<string>(); | ||
| public readonly column = input.required<Column<TData>>(); | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/angular/src/lib/ui/curve-data-table/src/lib/curve-data-table-image-cell.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Component, ChangeDetectionStrategy, input } from '@angular/core'; | ||
| import { NgIcon, provideIcons } from '@ng-icons/core'; | ||
| import { phosphorImage } from '@ng-icons/phosphor-icons/regular'; | ||
|
|
||
| @Component({ | ||
| selector: 'data-table-image-cell', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| imports: [NgIcon], | ||
| providers: [provideIcons({ phosphorImage })], | ||
| template: ` | ||
| @if (imageUrl()) { | ||
| <img [src]="imageUrl()" width="40" height="40" /> | ||
| } @else { | ||
| <ng-icon name="phosphorImage" size="40" /> | ||
| } | ||
| `, | ||
| }) | ||
| export class DataTableImageCell { | ||
| public readonly imageUrl = input<string>(); | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/angular/src/lib/ui/curve-data-table/src/lib/curve-data-table-select-all.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Component, ChangeDetectionStrategy, input } from '@angular/core'; | ||
| import { Table } from '@tanstack/angular-table'; | ||
| import { HlmCheckbox } from '../../../checkbox/src'; | ||
|
|
||
| @Component({ | ||
| selector: 'data-table-select-all', | ||
| imports: [HlmCheckbox], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: ` | ||
| <hlm-checkbox | ||
| aria-label="Select all" | ||
| [checked]="table().getIsAllPageRowsSelected()" | ||
| [indeterminate]="table().getIsSomePageRowsSelected()" | ||
| (checkedChange)="table().toggleAllPageRowsSelected($event)" | ||
| /> | ||
| `, | ||
| }) | ||
| export class DataTableSelectAll<TRecord> { | ||
| public readonly table = input.required<Table<TRecord>>(); | ||
| } |
19 changes: 19 additions & 0 deletions
19
packages/angular/src/lib/ui/curve-data-table/src/lib/curve-data-table-select-row-cell.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { Component, ChangeDetectionStrategy, input } from '@angular/core'; | ||
| import { Row } from '@tanstack/angular-table'; | ||
| import { HlmCheckbox } from '../../../checkbox/src'; | ||
|
|
||
| @Component({ | ||
| selector: 'data-table-select-row', | ||
| imports: [HlmCheckbox], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: ` | ||
| <hlm-checkbox | ||
| aria-label="Select row" | ||
| [checked]="row().getIsSelected()" | ||
| (checkedChange)="row().toggleSelected($event)" | ||
| /> | ||
| `, | ||
| }) | ||
| export class DataTableSelectRowCell<TRecord> { | ||
| public readonly row = input.required<Row<TRecord>>(); | ||
| } |
11 changes: 11 additions & 0 deletions
11
packages/angular/src/lib/ui/curve-data-table/src/lib/curve-data-table-string-cell.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Component, ChangeDetectionStrategy, input } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'data-table-string-cell', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: `<div [attr.class]="alignRight() ? 'text-right' : ''">{{ value() }}</div>`, | ||
| }) | ||
| export class DataTableStringCell { | ||
| public readonly value = input.required<string>(); | ||
| public readonly alignRight = input.required<boolean>(); | ||
| } |
38 changes: 38 additions & 0 deletions
38
packages/angular/src/lib/ui/curve-data-table/src/lib/curve-data-table.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| @if (searchColumn() || hasColumnFilter()) { | ||
| <div hlmDataTableToolbar> | ||
| @if (searchColumn()) { | ||
| <div hlmInputGroup class="max-w-xs"> | ||
| <div hlmInputGroupAddon> | ||
| <ng-icon name="phosphorMagnifyingGlass" /> | ||
| <input | ||
| hlmInputGroupInput | ||
| [placeholder]="`Search ${searchColumn()}...`" | ||
| [value]="appFilter()" | ||
| (input)="setAppFilter($event)" | ||
| /> | ||
| </div> | ||
| </div> | ||
| } @if (hasColumnFilter()) { | ||
| <button hlmBtn variant="outline" class="ml-auto" [hlmDropdownMenuTrigger]="columnsMenu"> | ||
| Columns | ||
| </button> | ||
| <ng-template #columnsMenu> | ||
| <hlm-dropdown-menu class="w-40"> | ||
| @for (column of hideableColumns(); track column.id) { | ||
| <button | ||
| hlmDropdownMenuCheckbox | ||
| class="capitalize" | ||
| [checked]="column.getIsVisible()" | ||
| (triggered)="column.toggleVisibility(!column.getIsVisible())" | ||
| > | ||
| {{ column.id }} | ||
| <hlm-dropdown-menu-checkbox-indicator /> | ||
| </button> | ||
| } | ||
| </hlm-dropdown-menu> | ||
| </ng-template> | ||
| } | ||
| </div> | ||
| } | ||
| <hlm-data-table-content [table]="table" [columns]="tanstackColumns" /> | ||
| <hlm-data-table-pagination [table]="table" /> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.