Skip to content

Commit f30973c

Browse files
[UXP-34] add pagination change on slide
1 parent 467ec0b commit f30973c

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/app/shared/carousel/carousel.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div *ngIf="!(isLoading$ | async) && itemList?.length > 0">
22
<ngb-carousel #carousel [interval]="2000" (slide)="onSlide($event)" class="ds-carousel">
3-
<ng-template ngbSlide *ngFor="let item of currentPageItems(); let i = index; let last = last">
3+
<ng-template ngbSlide [id]="'slide_' + i" *ngFor="let item of currentPageItems(); let i = index; let last = last">
44
<ng-container *ngIf="getItemLink(item.indexableObject); let currentLink; else carouselContent">
55
<a *ngIf="isLinkInternal(currentLink)" [routerLink]="currentLink">
66
<ng-container *ngTemplateOutlet="carouselContent"></ng-container>
@@ -41,7 +41,7 @@
4141
</button>
4242
</div>
4343
<div class="mt-4 w-100 d-flex justify-content-center align-items-center" *ngIf="totalPages > 1">
44-
<button (click)="previousPage()" [disabled]="currentPage === 1" class="prev">
44+
<button (click)="previousPage()" [disabled]="currentPage === 1" class="prev border-0 bg-transparent">
4545
<i class="fa fa-arrow-left"></i>
4646
</button>
4747
<button
@@ -52,7 +52,7 @@
5252
[style.color]="page === currentPage ? '#000000' : '#7c7c7c'">
5353
{{ page < 10 ? '0' + page : page }}
5454
</button>
55-
<button (click)="nextPage()" [disabled]="currentPage === pages().length" class="next">
55+
<button (click)="nextPage()" [disabled]="currentPage === pages().length" class="next border-0 bg-transparent">
5656
<i class="fa fa-arrow-right"></i>
5757
</button>
5858
</div>

src/app/shared/carousel/carousel.component.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class CarouselComponent implements OnInit {
7878
/**
7979
* reference to the carousel
8080
*/
81-
@ViewChild('carousel', {static: true}) carousel: NgbCarousel;
81+
@ViewChild('carousel', {static: false}) carousel: NgbCarousel;
8282

8383
isLoading$ = new BehaviorSubject(true);
8484

@@ -159,13 +159,26 @@ export class CarouselComponent implements OnInit {
159159
* function to call on slide
160160
*/
161161
onSlide(slideEvent: NgbSlideEvent) {
162+
const previousSlideIndex = parseInt(slideEvent.prev.split(('_'))[1], 10);
163+
const direction = slideEvent.direction;
164+
162165
if (this.unpauseOnArrow && slideEvent.paused &&
163166
(slideEvent.source === NgbSlideEventSource.ARROW_LEFT || slideEvent.source === NgbSlideEventSource.ARROW_RIGHT)) {
164167
this.togglePaused();
165168
}
166169
if (this.pauseOnIndicator && !slideEvent.paused && slideEvent.source === NgbSlideEventSource.INDICATOR) {
167170
this.togglePaused();
168171
}
172+
173+
if (previousSlideIndex === (this.carouselOptions.numberOfItems - 1) && direction === 'left' && (this.hasMoreToLoad || this.currentPage < this.totalPages)) {
174+
this.changePage(this.currentPage + 1);
175+
} else if (previousSlideIndex === 0 && direction === 'right' && this.currentPage !== 1) {
176+
this.changePage(this.currentPage - 1);
177+
} else if (previousSlideIndex === 0 && direction === 'right' && this.currentPage === 1) {
178+
this.changePage(this.totalPages);
179+
} else if (previousSlideIndex === (this.currentPageItems().length - 1) && direction === 'left' && (!this.hasMoreToLoad || this.currentPage === this.totalPages)) {
180+
this.changePage(1);
181+
}
169182
}
170183

171184
/**

0 commit comments

Comments
 (0)