-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design,design-land): add link support to paginator
- Loading branch information
Showing
10 changed files
with
311 additions
and
59 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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { BasicPaginatorComponent } from './basic-paginator/basic-paginator.component'; | ||
import { LinkPaginatorComponent } from './link-paginator/link-paginator.component'; | ||
|
||
export const PAGINATOR_EXAMPLES = [ | ||
BasicPaginatorComponent, | ||
LinkPaginatorComponent, | ||
]; |
1 change: 1 addition & 0 deletions
1
libs/design/paginator/examples/src/link-paginator/link-paginator.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 @@ | ||
<daff-paginator aria-label="Search results page" [numberOfPages]="numberOfPages" [currentPage]="currentPage$ | async" [linkMode]="true" [url]="url" [queryParam]="queryParam"></daff-paginator> |
32 changes: 32 additions & 0 deletions
32
libs/design/paginator/examples/src/link-paginator/link-paginator.component.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,32 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
} from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { | ||
Observable, | ||
map, | ||
} from 'rxjs'; | ||
|
||
@Component({ | ||
// eslint-disable-next-line @angular-eslint/component-selector | ||
selector: 'link-paginator', | ||
templateUrl: './link-paginator.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class LinkPaginatorComponent { | ||
numberOfPages = 15; | ||
// TODO: don't hardcode this, pass it in design land | ||
url = '/paginator'; | ||
queryParam = 'currentPage'; | ||
|
||
get currentPage$(): Observable<number> { | ||
return this.route.queryParamMap.pipe( | ||
map((qps) => Number(qps.get(this.queryParam))), | ||
); | ||
} | ||
|
||
constructor( | ||
private route: ActivatedRoute, | ||
) {} | ||
} |
19 changes: 19 additions & 0 deletions
19
libs/design/paginator/examples/src/link-paginator/link-paginator.module.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,19 @@ | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { DaffPaginatorModule } from '@daffodil/design'; | ||
|
||
import { LinkPaginatorComponent } from './link-paginator.component'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
LinkPaginatorComponent, | ||
], | ||
exports: [ | ||
LinkPaginatorComponent, | ||
], | ||
imports: [ | ||
DaffPaginatorModule, | ||
], | ||
providers: [], | ||
}) | ||
export class LinkPaginatorModule { } |
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,4 +1,5 @@ | ||
export { BasicPaginatorComponent } from './basic-paginator/basic-paginator.component'; | ||
export { LinkPaginatorComponent } from './link-paginator/link-paginator.component'; | ||
|
||
export { PaginatorExamplesModule } from './paginator-examples.module'; | ||
export { PAGINATOR_EXAMPLES } from './examples'; |
106 changes: 82 additions & 24 deletions
106
libs/design/src/molecules/paginator/paginator.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 |
---|---|---|
@@ -1,48 +1,106 @@ | ||
<button type="button" class="daff-paginator__previous" | ||
[disabled]="_disablePrev()" | ||
<button *ngIf="!linkMode" type="button" class="daff-paginator__previous" | ||
[disabled]="_disablePrev" | ||
tabindex="0" | ||
attr.aria-label="Go to Previous Page of {{_paginatorId}} Paginator" | ||
(click)="_onNotifyPrevPageChange()"> | ||
<fa-icon [icon]="faChevronLeft" size="sm"></fa-icon> Previous | ||
</button> | ||
<ng-container *ngIf="linkMode"> | ||
<a class="daff-paginator__previous" | ||
*ngIf="!_disablePrev" | ||
attr.aria-label="Go to Previous Page of {{_paginatorId}} Paginator" | ||
[routerLink]="url" | ||
queryParamsHandling="merge" | ||
[queryParams]="_buildPageQueryParams(currentPage - 1)"> | ||
<fa-icon [icon]="faChevronLeft" size="sm"></fa-icon><span>Previous</span> | ||
</a> | ||
<span class="daff-paginator__previous disabled" | ||
*ngIf="_disablePrev" | ||
attr.aria-label="Go to Previous Page of {{_paginatorId}} Paginator" | ||
[attr.disabled]="true"> | ||
<fa-icon [icon]="faChevronLeft" size="sm"></fa-icon><span>Previous</span> | ||
</span> | ||
</ng-container> | ||
|
||
<button type="button" class="daff-paginator__page-link" | ||
<button *ngIf="!linkMode" type="button" class="daff-paginator__page-link" | ||
[class.selected]="_isSelected(1)" | ||
tabindex="0" | ||
attr.aria-label="Go to Page 1 of {{_paginatorId}} Paginator" | ||
(click)="_onNotifyPageChange(1)"> | ||
<span>1</span> | ||
</button> | ||
<a *ngIf="linkMode" class="daff-paginator__page-link" | ||
[routerLink]="url" | ||
[queryParams]="_buildPageQueryParams(1)" | ||
queryParamsHandling="merge" | ||
[class.selected]="_isSelected(1)" | ||
attr.aria-label="Go to Page 1 of {{_paginatorId}} Paginator" | ||
><span>1</span></a> | ||
|
||
<span class="daff-paginator__ellipsis" *ngIf="_showFirstEllipsis()">...</span> | ||
<span class="daff-paginator__ellipsis" *ngIf="_showFirstEllipsis">...</span> | ||
|
||
<ng-container *ngFor="let pageNumber of _numberOfPagesArray"> | ||
<button type="button" class="daff-paginator__page-link" | ||
[class.selected]="_isSelected(pageNumber)" | ||
tabindex="0" | ||
attr.aria-label="Go to Page {{pageNumber}} of {{_paginatorId}} Paginator" | ||
aria-current="_isSelected(pageNumber)" | ||
*ngIf="_showNumber(pageNumber)" | ||
(click)="_onNotifyPageChange(pageNumber)"> | ||
<span>{{ pageNumber }}</span> | ||
</button> | ||
<ng-container *ngIf="_showNumber(pageNumber)"> | ||
<button *ngIf="!linkMode" type="button" class="daff-paginator__page-link" | ||
[class.selected]="_isSelected(pageNumber)" | ||
[attr.data-page-number]="pageNumber" | ||
tabindex="0" | ||
attr.aria-label="Go to Page {{pageNumber}} of {{_paginatorId}} Paginator" | ||
aria-current="_isSelected(pageNumber)" | ||
(click)="_onNotifyPageChange(pageNumber)"> | ||
<span>{{ pageNumber }}</span> | ||
</button> | ||
<a *ngIf="linkMode" class="daff-paginator__page-link" | ||
[attr.data-page-number]="pageNumber" | ||
[routerLink]="url" | ||
[queryParams]="_buildPageQueryParams(pageNumber)" | ||
queryParamsHandling="merge" | ||
[class.selected]="_isSelected(pageNumber)" | ||
attr.aria-label="Go to Page {{pageNumber}} of {{_paginatorId}} Paginator" | ||
><span>{{ pageNumber }}</span></a> | ||
</ng-container> | ||
</ng-container> | ||
|
||
<span class="daff-paginator__ellipsis" *ngIf="_showLastEllipsis()">...</span> | ||
<span class="daff-paginator__ellipsis" *ngIf="_showLastEllipsis">...</span> | ||
|
||
<button type="button" class="daff-paginator__page-link" | ||
[class.selected]="_isSelected(numberOfPages)" | ||
tabindex="0" | ||
attr.aria-label="Go To Page {{numberOfPages}} of {{_paginatorId}} Paginator" | ||
(click)="_onNotifyPageChange(numberOfPages)" | ||
*ngIf="!(numberOfPages < 2)"> | ||
<span>{{ numberOfPages }}</span> | ||
</button> | ||
<ng-container *ngIf="!(numberOfPages < 2)"> | ||
<button *ngIf="!linkMode" type="button" class="daff-paginator__page-link" | ||
[class.selected]="_isSelected(numberOfPages)" | ||
tabindex="0" | ||
attr.aria-label="Go To Page {{numberOfPages}} of {{_paginatorId}} Paginator" | ||
(click)="_onNotifyPageChange(numberOfPages)" | ||
> | ||
<span>{{ numberOfPages }}</span> | ||
</button> | ||
<a *ngIf="linkMode" class="daff-paginator__page-link" | ||
[routerLink]="url" | ||
[queryParams]="_buildPageQueryParams(numberOfPages)" | ||
queryParamsHandling="merge" | ||
[class.selected]="_isSelected(numberOfPages)" | ||
attr.aria-label="Go to Page {{numberOfPages}} of {{_paginatorId}} Paginator" | ||
><span>{{ numberOfPages }}</span></a> | ||
</ng-container> | ||
|
||
<button class="daff-paginator__next" | ||
[disabled]="_disableNext()" | ||
<button *ngIf="!linkMode" class="daff-paginator__next" | ||
[disabled]="_disableNext" | ||
tabindex="0" | ||
attr.aria-label="Go to Next Page of {{_paginatorId}} Paginator" | ||
(click)="_onNotifyNextPageChange()"> | ||
Next <fa-icon [icon]="faChevronRight" size="sm"></fa-icon> | ||
</button> | ||
<ng-container *ngIf="linkMode"> | ||
<a class="daff-paginator__next" | ||
*ngIf="!_disableNext" | ||
[routerLink]="url" | ||
attr.aria-label="Go to Next Page of {{_paginatorId}} Paginator" | ||
queryParamsHandling="merge" | ||
[queryParams]="_buildPageQueryParams(currentPage + 1)"> | ||
<span>Next</span><fa-icon [icon]="faChevronRight" size="sm"></fa-icon> | ||
</a> | ||
<span class="daff-paginator__next disabled" | ||
*ngIf="_disableNext" | ||
attr.aria-label="Go to Next Page of {{_paginatorId}} Paginator" | ||
[attr.disabled]="true"> | ||
<span>Next</span><fa-icon [icon]="faChevronRight" size="sm"></fa-icon> | ||
</span> | ||
</ng-container> |
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
Oops, something went wrong.