-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add example for providing custom
MatPaginatorIntl
(#22771)
Adds an example for providing a custom `MatPaginatorIntl`. The example also show-cases the use with `@angular/localize`. Fixes #8239.
- Loading branch information
1 parent
1305587
commit 972283c
Showing
13 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
2 changes: 2 additions & 0 deletions
2
src/components-examples/material/paginator/paginator-intl/paginator-intl-example.html
This file contains 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,2 @@ | ||
<mat-paginator [length]="0" [pageSizeOptions]="[10, 50, 100]"> | ||
</mat-paginator> |
45 changes: 45 additions & 0 deletions
45
src/components-examples/material/paginator/paginator-intl/paginator-intl-example.ts
This file contains 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,45 @@ | ||
import {Component, Injectable, NgModule} from '@angular/core'; | ||
import {MatPaginatorIntl, MatPaginatorModule} from '@angular/material/paginator'; | ||
import {Subject} from 'rxjs'; | ||
|
||
@Injectable() | ||
export class MyCustomPaginatorIntl implements MatPaginatorIntl { | ||
changes = new Subject<void>(); | ||
|
||
// For internationalization, the `$localize` function from | ||
// the `@angular/localize` package can be used. | ||
firstPageLabel = $localize`First page`; | ||
itemsPerPageLabel = $localize`Items per page:`; | ||
lastPageLabel = $localize`Last page`; | ||
|
||
// You can set labels to an arbitrary string too, or dynamically compute | ||
// it through other third-party internationalization libraries. | ||
nextPageLabel = 'Next page'; | ||
previousPageLabel = 'Previous page'; | ||
|
||
getRangeLabel(page: number, pageSize: number, length: number): string { | ||
if (length === 0) { | ||
return $localize`Page 1 of 1`; | ||
} | ||
const amountPages = Math.ceil(length / pageSize); | ||
return $localize`Page ${page + 1} of ${amountPages}`; | ||
} | ||
} | ||
|
||
/** | ||
* @title Paginator internationalization | ||
*/ | ||
@Component({ | ||
selector: 'paginator-intl-example', | ||
templateUrl: 'paginator-intl-example.html', | ||
}) | ||
export class PaginatorIntlExample {} | ||
|
||
@NgModule({ | ||
imports: [MatPaginatorModule], | ||
declarations: [PaginatorIntlExample], | ||
providers: [ | ||
{provide: MatPaginatorIntl, useClass: MyCustomPaginatorIntl} | ||
] | ||
}) | ||
export class PaginatorIntlExampleModule {} |
This file contains 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 |
---|---|---|
|
@@ -11,3 +11,8 @@ ts_library( | |
"@npm//@angular/core", | ||
], | ||
) | ||
|
||
ts_library( | ||
name = "localize_types", | ||
srcs = ["localize-types.d.ts"], | ||
) |
This file contains 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,5 @@ | ||
import {LocalizeFn} from '@angular/localize/src/localize'; | ||
|
||
declare global { | ||
const $localize: LocalizeFn; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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