Skip to content

Commit

Permalink
feat: support navigation by multiple items WIP
Browse files Browse the repository at this point in the history
This commit goes in the direction of more generic slider rather than
just a gallery. The purpose of this commit is to make making something
like a product carousel, where multiple elements are visible, possible.
  • Loading branch information
daelmaak committed Sep 4, 2023
1 parent 988d94d commit 9ff0fae
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ <h2 id="demos">Demos</h2>
[loop]="true"
loading="lazy"
[visibleItems]="mobile ? 1.5 : 3"
[moveByItems]="mobile ? 1.5 : 3"
></gallery>
</app-showcase>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
[counter]="counter"
[counterOrientation]="counterOrientation"
[visibleItems]="visibleItems"
[moveByItems]="moveByItems"
[objectFit]="objectFit"
[loading]="loading"
[itemTemplate]="itemTemplate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class GalleryComponent {
@Input() counter = true;
@Input() counterOrientation: VerticalOrientation = 'bottom';
@Input() visibleItems = 1;
@Input() moveByItems = 1;
@Input() loading: Loading = 'lazy';
@Input() loop = false;
@Input() objectFit: ObjectFit = 'cover';
Expand Down
6 changes: 3 additions & 3 deletions libs/gallery/src/lib/components/viewer/viewer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
aria-label="Previous image"
class="viewer-arrow viewer-arrow-prev"
(mousedown)="$event.stopPropagation()"
(click)="selectByDelta(-1)"
(click)="selectByDelta(-moveByItems)"
>
<chevron-icon *ngIf="!arrowTemplate; else arrowTemplate"></chevron-icon>
</button>
Expand Down Expand Up @@ -107,15 +107,15 @@
aria-label="Next image"
class="viewer-arrow viewer-arrow-next"
(mousedown)="$event.stopPropagation()"
(click)="selectByDelta(1)"
(click)="selectByDelta(moveByItems)"
>
<chevron-icon *ngIf="!arrowTemplate; else arrowTemplate"></chevron-icon>
</button>

<counter
*ngIf="counter && items?.length"
[itemQuantity]="items?.length"
[selectedIndex]="selectedIndex"
[selectedIndex]="counterIndex"
[orientation]="counterOrientation"
></counter>

Expand Down
5 changes: 5 additions & 0 deletions libs/gallery/src/lib/components/viewer/viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class ViewerComponent implements OnChanges, OnInit, AfterViewInit {
@Input() aria: Aria;
@Input() loop: boolean;
@Input() visibleItems: number;
@Input() moveByItems: number;

@HostBinding('class.rtl')
@Input()
Expand All @@ -111,6 +112,10 @@ export class ViewerComponent implements OnChanges, OnInit, AfterViewInit {
: '400ms';
}

get counterIndex() {
return Math.floor(this.selectedIndex / this.moveByItems);
}

get showArrow() {
return this.arrows && this.items && this.items.length > 1;
}
Expand Down

0 comments on commit 9ff0fae

Please sign in to comment.