Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/angular-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@angular/forms": "^20.1.6",
"@angular/platform-browser": "^20.1.6",
"@angular/platform-browser-dynamic": "^20.1.6",
"@webcomponents/scoped-custom-element-registry": "^0.0.10",
"rxjs": "^7.8.2",
"zone.js": "^0.15.1"
},
Expand Down
9 changes: 9 additions & 0 deletions apps/angular-demo/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
<h1>Hello Angular Demo!</h1>
<sl-button variant="info" size="lg">Button</sl-button>

<ul>
<ng-template ngFor let-item [ngForOf]="quotes">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the new @for syntax?

<li>{{item.quote}} - {{item.author}}
</ng-template>
</ul>

<sl-paginator [dataSource]="dataSource"
(sl-page-change)="onPageChange()"></sl-paginator>
47 changes: 45 additions & 2 deletions apps/angular-demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
import { NgFor } from '@angular/common';
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ButtonComponent } from '@sl-design-system/angular/button';
import { PaginatorComponent } from '@sl-design-system/angular/paginator';
import { FetchListDataSource, FetchListDataSourceError, ListDataSourceItem } from '@sl-design-system/data-source';

interface Quote {
id: string;
quote: string;
author: string;
}

interface QuotesResponse {
quotes: Quote[];
total: number;
skip: number;
limit: number;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
imports: [ButtonComponent],
imports: [NgFor, ButtonComponent, PaginatorComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
styleUrls: ['./app.component.css'],
})
export class AppComponent {}
export class AppComponent {

dataSource!: FetchListDataSource<Quote>;
quotes?:Quote[];

ngOnInit(): void {
this.dataSource = new FetchListDataSource<Quote>({
pageSize: 10,
pagination: true,
fetchPage: async ({ page, pageSize }) => {
const response = await fetch(`https://dummyjson.com/quotes?skip=${page * pageSize}&limit=${pageSize}`);

if (response.ok) {
const { quotes, total } = (await response.json()) as QuotesResponse;
this.quotes = quotes;
return { items: quotes, totalItems: total };
} else {
throw new FetchListDataSourceError('Failed to fetch data', response);
}
}
});

}
onPageChange() {
setTimeout(() => {
this.quotes = [...this.dataSource.items.map((item: ListDataSourceItem) => item.id as Quote)];
}, 10);
}
}
4 changes: 3 additions & 1 deletion apps/angular-demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { ButtonComponent } from '@sl-design-system/angular/button';
import { PaginatorComponent } from '@sl-design-system/angular/paginator';


@NgModule({
declarations: [],
imports: [AppComponent, BrowserModule, ButtonComponent],
imports: [AppComponent, BrowserModule, ButtonComponent, PaginatorComponent],
})
export class AppModule {}
1 change: 1 addition & 0 deletions apps/angular-demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { setup } from '@sl-design-system/sanoma-learning';
import '@sl-design-system/button/register.js';
import '@sl-design-system/paginator/register.js';

bootstrapApplication(AppComponent);

Expand Down
1 change: 1 addition & 0 deletions apps/angular-demo/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import 'zone.js';
import '@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min.js';
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@
"@sl-design-system/angular": "^3.2.0",
"@sl-design-system/button": "^1.2.4",
"@sl-design-system/checkbox": "^2.1.4",
"@sl-design-system/data-source": "^0.2.0",
"@sl-design-system/dialog": "^2.0.1",
"@sl-design-system/form": "^1.2.4",
"@sl-design-system/icon": "^1.2.1",
"@sl-design-system/paginator": "^0.2.0",
"@sl-design-system/radio-group": "^1.1.4",
"@sl-design-system/sanoma-learning": "^0.4.6",
"@sl-design-system/select": "^2.0.4",
Expand Down