forked from NationalBankBelgium/stark
-
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(stark-ui): implement Pagination component. Integrate pagination …
- Loading branch information
1 parent
8a787f7
commit 74566f1
Showing
43 changed files
with
2,918 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./pagination/pagination.module"; | ||
export * from "./pagination/components"; |
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,3 @@ | ||
export * from "./components/pagination.component"; | ||
export * from "./components/paginate-event.intf"; | ||
export * from "./components/pagination-config.intf"; |
23 changes: 23 additions & 0 deletions
23
packages/stark-ui/src/modules/pagination/components/_pagination-theme.scss
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,23 @@ | ||
/********** PAGINATION THEME **********/ | ||
/* stark: src/modules/pagination/components/_pagination-theme.scss */ | ||
|
||
@media #{$tablet-query} { | ||
.stark-pagination > div { | ||
.pagination-enter-page { | ||
& input { | ||
border: solid 1px $divider-color; | ||
} | ||
} | ||
|
||
.page-numbers { | ||
&.active { | ||
a { | ||
color: mat-color(map-get($base-theme, primary-palette)); | ||
opacity: 1; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* END stark: src/modules/pagination/components/_pagination-theme.scss */ |
68 changes: 68 additions & 0 deletions
68
packages/stark-ui/src/modules/pagination/components/_pagination.component.scss
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,68 @@ | ||
/********** PAGINATION **********/ | ||
/* stark: src/modules/pagination/components/_pagination.component.scss */ | ||
.stark-pagination > div { | ||
align-items: center; | ||
display: flex; | ||
justify-content: flex-start; | ||
ul { | ||
align-items: center; | ||
display: flex; | ||
list-style: none; | ||
margin: 0; | ||
margin-right: 18px; | ||
padding: 0; | ||
} | ||
.pagination-enter-page { | ||
display: none; | ||
} | ||
|
||
.pagination-items-per-page { | ||
.stark-dropdown .mat-form-field { | ||
width: 50px; | ||
} | ||
} | ||
|
||
.page-numbers { | ||
display: none; | ||
} | ||
} | ||
|
||
@media #{$tablet-query} { | ||
.stark-pagination > div { | ||
font-size: mat-font-size($typography-config, caption); | ||
font-weight: mat-font-weight($typography-config, caption); | ||
line-height: mat-line-height($typography-config, caption); | ||
|
||
.pagination-enter-page { | ||
align-items: center; | ||
display: flex; | ||
margin-right: 40px; | ||
& input { | ||
margin-right: 4px; | ||
width: 26px; | ||
height: 24px; | ||
padding: 4px; | ||
border-radius: 2px; | ||
text-align: center; | ||
} | ||
} | ||
|
||
.page-numbers { | ||
cursor: pointer; | ||
display: flex; | ||
a { | ||
color: inherit; | ||
padding: 15px; | ||
opacity: 0.5; | ||
} | ||
} | ||
|
||
&.compact { | ||
.pagination-enter-page { | ||
margin-right: 5px; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* END stark: src/modules/pagination/components/_pagination.component.scss */ |
14 changes: 14 additions & 0 deletions
14
packages/stark-ui/src/modules/pagination/components/paginate-event.intf.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,14 @@ | ||
/** | ||
* Event to be emitted by the Stark Pagination component when the pagination changes | ||
*/ | ||
export interface StarkPaginateEvent { | ||
/** | ||
* Current page after pagination | ||
*/ | ||
page: number; | ||
|
||
/** | ||
* Current number of items displayed per page | ||
*/ | ||
itemsPerPage: number; | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/stark-ui/src/modules/pagination/components/pagination-config.intf.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,52 @@ | ||
/** | ||
* Defines the config object to be used with the Pagination component. | ||
*/ | ||
export interface StarkPaginationConfig { | ||
/** | ||
* If true, the component will be displayed in "extended" mode (an "extended-pagination" class is added to the element). | ||
* Default: false | ||
*/ | ||
isExtended?: boolean; | ||
|
||
/** | ||
* Number of items displayed on each page. The number of available pages for pagination is calculated based on this number. | ||
* Default: itemsPerPageOptions[0] | ||
*/ | ||
itemsPerPage?: number; | ||
|
||
/** | ||
* Available options for items per page dropdown. | ||
* Default : [5,10,15] | ||
*/ | ||
itemsPerPageOptions?: number[]; | ||
|
||
/** | ||
* If false, then itemsPerPage dropdown will not be present. | ||
* Default: true | ||
*/ | ||
itemsPerPageIsPresent?: boolean; | ||
|
||
/** | ||
* Current page index. | ||
* Default: 0 | ||
*/ | ||
page?: number; | ||
|
||
/** | ||
* If false, then page nav bar will not be present. | ||
* Default: true | ||
*/ | ||
pageNavIsPresent?: boolean; | ||
|
||
/** | ||
* f false, then input box for page selection will not be present. | ||
* Default: true | ||
*/ | ||
pageInputIsPresent?: boolean; | ||
|
||
/** | ||
* Number of items being paged in order to calculate number of pages for pagination. | ||
* Default: 0 | ||
*/ | ||
totalItems?: number; | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/stark-ui/src/modules/pagination/components/pagination.component.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,79 @@ | ||
<div *ngIf="mode !== 'compact'"> | ||
<ul *ngIf="paginationConfig.pageNavIsPresent !== false"> | ||
<li class="first-page" aria-label="First page" *ngIf="!paginationConfig.isExtended"> | ||
|
||
<button mat-icon-button (click)="goToFirst()" [disabled]="!hasPrevious()" aria-label="First page"> | ||
<mat-icon starkSvgViewBox svgIcon="page-first"></mat-icon> | ||
</button> | ||
</li> | ||
<li class="previous" aria-label="Previous"> | ||
<button mat-icon-button (click)="goToPrevious()" [disabled]="!hasPrevious()" aria-label="Previous"> | ||
<mat-icon starkSvgViewBox svgIcon="chevron-left"></mat-icon> | ||
</button> | ||
</li> | ||
<ng-container *ngIf="paginationConfig.isExtended"> | ||
<!-- workaround to use ngIf together with ngFor --> | ||
<li class="page-numbers" *ngFor="let pageNumber of pageNumbers; trackBy: trackPageNumberFn" | ||
value="{{ pageNumber }}" | ||
[ngClass]="paginationConfig.page === pageNumber ? 'active' : ''"> | ||
<a *ngIf="pageNumber !== '...'" (click)="goToPage(pageNumber)">{{ pageNumber }}</a> | ||
<span *ngIf="pageNumber === '...'">{{ pageNumber }}</span> | ||
</li> | ||
</ng-container> | ||
<li class="next" aria-label="Next"> | ||
<button mat-icon-button type="button" (click)="goToNext()" [disabled]="!hasNext()"> | ||
<mat-icon starkSvgViewBox svgIcon="chevron-right"></mat-icon> | ||
</button> | ||
</li> | ||
<li class="last-page" aria-label="Last page" *ngIf="!paginationConfig.isExtended"> | ||
|
||
<button mat-icon-button type="button" (click)="goToLast()" [disabled]="!hasNext()" aria-label="Last page"> | ||
<mat-icon starkSvgViewBox svgIcon="page-last"></mat-icon> | ||
</button> | ||
</li> | ||
</ul> | ||
<div class="pagination-enter-page" *ngIf="paginationConfig.pageInputIsPresent !== false"> | ||
<input [starkOnEnterKey]="changePageOnEnter.bind(this)" starkRestrictInput="\d" | ||
maxlength="{{ getPageInputMaxDigits() }}" | ||
id="current-page-{{ htmlSuffixId }}" [(ngModel)]="paginationInput"> | ||
<span> / </span><span class="total-pages">{{ getTotalPages() }}</span> | ||
</div> | ||
<div class="pagination-items-per-page" *ngIf="paginationConfig.itemsPerPageIsPresent !== false"> | ||
<stark-dropdown [options]="paginationConfig.itemsPerPageOptions" [value]="paginationConfig.itemsPerPage" | ||
placeholder="" | ||
(dropdownSelectionChanged)="onChangeItemsPerPage($event)" | ||
dropdownId="items-per-page-{{ htmlSuffixId }}" | ||
dropdownName="items-per-page-{{ htmlSuffixId }}"></stark-dropdown> | ||
</div> | ||
</div> | ||
|
||
<div *ngIf="mode === 'compact'" class="compact"> | ||
<ul *ngIf="paginationConfig.pageNavIsPresent !== false"> | ||
<li class="first-page" aria-label="First page"> | ||
<button mat-icon-button (click)="goToFirst()" [disabled]="!hasPrevious()" aria-label="First page"> | ||
<mat-icon starkSvgViewBox svgIcon="page-first"></mat-icon> | ||
</button> | ||
</li> | ||
<li class="previous" aria-label="Previous"> | ||
<button mat-icon-button (click)="goToPrevious()" [disabled]="!hasPrevious()" aria-label="Previous"> | ||
<mat-icon starkSvgViewBox svgIcon="chevron-left"></mat-icon> | ||
</button> | ||
</li> | ||
<div class="pagination-enter-page" *ngIf="paginationConfig.pageInputIsPresent !== false"> | ||
<input [starkOnEnterKey]="changePageOnEnter.bind(this)" starkRestrictInput="\d" | ||
maxlength="{{ getPageInputMaxDigits() }}" | ||
id="current-page-{{ htmlSuffixId }}" [(ngModel)]="paginationInput"> | ||
<span> / </span><span class="total-pages">{{ getTotalPages() }}</span> | ||
</div> | ||
<li class="next" aria-label="Next"> | ||
<button mat-icon-button (click)="goToNext()" [disabled]="!hasNext()"> | ||
<mat-icon starkSvgViewBox svgIcon="chevron-right"></mat-icon> | ||
</button> | ||
</li> | ||
<li class="last-page" aria-label="Last page"> | ||
<button mat-icon-button (click)="goToLast()" [disabled]="!hasNext()" aria-label="Last page"> | ||
<mat-icon starkSvgViewBox svgIcon="page-last"></mat-icon> | ||
</button> | ||
</li> | ||
</ul> | ||
</div> |
Oops, something went wrong.