forked from valor-software/ngx-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pagination): add custom template functionality
Add custom template functionality Fix tooltip and popover unit tests Close valor-software#2044
- Loading branch information
1 parent
2b2f5de
commit fd73917
Showing
14 changed files
with
340 additions
and
53 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
demo/src/app/components/+pagination/demos/custom-template/custom-template.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,39 @@ | ||
<pagination [totalItems]="66" | ||
[boundaryLinks]="true" | ||
[customFirstTemplate]="firstTemplate" | ||
[customLastTemplate]="lastTemplate" | ||
[customPreviousTemplate]="prevTemplate" | ||
[customNextTemplate]="nextTemplate" | ||
[customPageTemplate]="pageTemplate"> | ||
</pagination> | ||
|
||
<ng-template #pageTemplate let-page let-disabled="disabled" let-currentPage="currentPage"> | ||
{{ convertToRoman(page)}} | ||
<em *ngIf="page === currentPage">(page {{ page }})</em> | ||
</ng-template> | ||
|
||
<ng-template #nextTemplate let-disabled="disabled" let-currentPage="currentPage"> | ||
<ng-container *ngIf="!disabled"> | ||
➡️ | ||
</ng-container> | ||
<ng-container *ngIf="disabled"> | ||
⛔ | ||
</ng-container> | ||
</ng-template> | ||
|
||
<ng-template #prevTemplate let-disabled="disabled" let-currentPage="currentPage"> | ||
<ng-container *ngIf="!disabled"> | ||
⬅️ | ||
</ng-container> | ||
<ng-container *ngIf="disabled"> | ||
⛔ | ||
</ng-container> | ||
</ng-template> | ||
|
||
<ng-template #lastTemplate let-disabled="disabled" let-currentPage="currentPage"> | ||
Finish 🏁 | ||
</ng-template> | ||
|
||
<ng-template #firstTemplate let-disabled="disabled" let-currentPage="currentPage"> | ||
Start 🏁 | ||
</ng-template> |
34 changes: 34 additions & 0 deletions
34
demo/src/app/components/+pagination/demos/custom-template/custom-template.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,34 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'demo-pagination-custom-template', | ||
templateUrl: './custom-template.html' | ||
}) | ||
export class DemoPaginationCustomTemplateComponent { | ||
|
||
convertToRoman(page: number): string { | ||
const roman = { | ||
M: 1000, | ||
CM: 900, | ||
D: 500, | ||
CD: 400, | ||
C: 100, | ||
XC: 90, | ||
L: 50, | ||
XL: 40, | ||
X: 10, | ||
IX: 9, | ||
V: 5, | ||
IV: 4, | ||
I: 1 | ||
}; | ||
|
||
return Object.keys(roman).reduce((acc, symbol) => { | ||
const numeralSystem = Math.floor(page / roman[symbol]); | ||
// tslint:disable-next-line:no-parameter-reassignment | ||
page -= numeralSystem * roman[symbol]; | ||
|
||
return acc + symbol.repeat(numeralSystem); | ||
}, ''); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,35 +1,62 @@ | ||
<ul class="pagination" [ngClass]="classMap"> | ||
<li class="pagination-first page-item" | ||
*ngIf="boundaryLinks" | ||
[class.disabled]="noPrevious()||disabled"> | ||
<a class="page-link" href (click)="selectPage(1, $event)" | ||
[innerHTML]="getText('first')"></a> | ||
[class.disabled]="noPrevious() || disabled"> | ||
<a class="page-link" href (click)="selectPage(1, $event)"> | ||
<ng-container [ngTemplateOutlet]="customFirstTemplate || defaultFirstTemplate" | ||
[ngTemplateOutletContext]="{disabled: noPrevious() || disabled, currentPage: page}"> | ||
</ng-container> | ||
</a> | ||
</li> | ||
|
||
<li class="pagination-prev page-item" | ||
*ngIf="directionLinks" | ||
[class.disabled]="noPrevious()||disabled"> | ||
<a class="page-link" href (click)="selectPage(page - 1, $event)" | ||
[innerHTML]="getText('previous')"></a> | ||
[class.disabled]="noPrevious() || disabled"> | ||
<a class="page-link" href (click)="selectPage(page - 1, $event)"> | ||
<ng-container [ngTemplateOutlet]="customPreviousTemplate || defaultPreviousTemplate" | ||
[ngTemplateOutletContext]="{disabled: noPrevious() || disabled, currentPage: page}"> | ||
</ng-container> | ||
</a> | ||
</li> | ||
|
||
<li *ngFor="let pg of pages" | ||
[class.active]="pg.active" | ||
[class.disabled]="disabled&&!pg.active" | ||
[class.disabled]="disabled && !pg.active" | ||
class="pagination-page page-item"> | ||
<a class="page-link" href (click)="selectPage(pg.number, $event)" | ||
[innerHTML]="pg.text"></a> | ||
<a class="page-link" href (click)="selectPage(pg.number, $event)"> | ||
<ng-container [ngTemplateOutlet]="customPageTemplate || defaultPageTemplate" | ||
[ngTemplateOutletContext]="{disabled: disabled, $implicit: pg.number, currentPage: page}"> | ||
</ng-container> | ||
</a> | ||
</li> | ||
|
||
<li class="pagination-next page-item" | ||
*ngIf="directionLinks" | ||
[class.disabled]="noNext()||disabled"> | ||
<a class="page-link" href (click)="selectPage(page + 1, $event)" | ||
[innerHTML]="getText('next')"></a></li> | ||
[class.disabled]="noNext() || disabled"> | ||
<a class="page-link" href (click)="selectPage(page + 1, $event)"> | ||
<ng-container [ngTemplateOutlet]="customNextTemplate || defaultNextTemplate" | ||
[ngTemplateOutletContext]="{disabled: noNext() || disabled, currentPage: page}"> | ||
</ng-container> | ||
</a> | ||
</li> | ||
|
||
<li class="pagination-last page-item" | ||
*ngIf="boundaryLinks" | ||
[class.disabled]="noNext()||disabled"> | ||
<a class="page-link" href (click)="selectPage(totalPages, $event)" | ||
[innerHTML]="getText('last')"></a></li> | ||
[class.disabled]="noNext() || disabled"> | ||
<a class="page-link" href (click)="selectPage(totalPages, $event)"> | ||
<ng-container [ngTemplateOutlet]="customLastTemplate || defaultLastTemplate" | ||
[ngTemplateOutletContext]="{disabled: noNext() || disabled, currentPage: page}"> | ||
</ng-container> | ||
</a> | ||
</li> | ||
</ul> | ||
|
||
<ng-template #defaultPageTemplate let-page>{{ page }}</ng-template> | ||
|
||
<ng-template #defaultNextTemplate>{{ getText('next') }}</ng-template> | ||
|
||
<ng-template #defaultPreviousTemplate>{{ getText('previous') }}</ng-template> | ||
|
||
<ng-template #defaultFirstTemplate>{{ getText('first') }}</ng-template> | ||
|
||
<ng-template #defaultLastTemplate>{{ getText('last') }}</ng-template> |
Oops, something went wrong.