File
Description
Generic in-memory paged list component that can be used to render arbitrary items in
a vertical orientation.
Previous/next buttons as well as indicator-buttons can used to navigate the slides (pages).
To allow for flexible rendering of items, the rendering is delegated to the
given template and headerTemplate.
Implements
Metadata
| changeDetection |
ChangeDetectionStrategy.OnPush |
| selector |
cx-epd-visualization-paged-list |
| templateUrl |
./paged-list.component.html |
Index
Properties
|
|
|
Methods
|
|
|
Inputs
|
|
|
Outputs
|
|
|
|
activeSlideStartIndex
|
Type : number
|
Default value : 0
|
|
|
|
headerTemplate
|
Type : TemplateRef<any>
|
|
|
The headerTemplate is rendered above the item rows.
|
|
hideIndicators
|
Type : boolean
|
Default value : false
|
|
|
Indicates whether the visual indicators are used.
|
|
indicatorIcon
|
Type : any
|
Default value : ICON_TYPE.CIRCLE
|
|
|
|
items
|
Type : Observable<any>[]
|
|
|
The items$ represent the carousel items.
|
|
itemsPerSlide
|
Type : number
|
Default value : 10
|
|
|
The maximum number of items per slide
|
|
nextIcon
|
Type : any
|
Default value : ICON_TYPE.CARET_RIGHT
|
|
|
|
previousIcon
|
Type : any
|
Default value : ICON_TYPE.CARET_LEFT
|
|
|
|
template
|
Type : TemplateRef<any>
|
|
|
The template is rendered for each item, so that the actual
view can be given by the component that uses the PagedListComponent.
|
|
title
|
Type : string
|
|
|
The title is rendered as the carousel heading.
|
Methods
|
setActiveSlideStartIndex
|
setActiveSlideStartIndex(activeSlideStartIndex: number)
|
|
|
Parameters :
| Name |
Type |
Optional |
| activeSlideStartIndex |
number
|
No
|
|
|
activeSlideStartIndex
|
Type : number
|
Default value : 0
|
Decorators :
@Input()
|
|
|
|
activeSlideStartIndexChange
|
Default value : new EventEmitter<number>()
|
Decorators :
@Output()
|
|
|
|
headerTemplate
|
Type : TemplateRef<any>
|
Decorators :
@Input()
|
|
|
The headerTemplate is rendered above the item rows.
|
|
hideIndicators
|
Default value : false
|
Decorators :
@Input()
|
|
|
Indicates whether the visual indicators are used.
|
|
indicatorIcon
|
Default value : ICON_TYPE.CIRCLE
|
Decorators :
@Input()
|
|
|
|
items
|
Type : Observable<any>[]
|
Decorators :
@Input()
|
|
|
The items$ represent the carousel items.
|
|
itemsPerSlide
|
Type : number
|
Default value : 10
|
Decorators :
@Input()
|
|
|
The maximum number of items per slide
|
|
nextIcon
|
Default value : ICON_TYPE.CARET_RIGHT
|
Decorators :
@Input()
|
|
|
|
previousIcon
|
Default value : ICON_TYPE.CARET_LEFT
|
Decorators :
@Input()
|
|
|
|
template
|
Type : TemplateRef<any>
|
Decorators :
@Input()
|
|
|
The template is rendered for each item, so that the actual
view can be given by the component that uses the PagedListComponent.
|
|
title
|
Type : string
|
Decorators :
@Input()
|
|
|
The title is rendered as the carousel heading.
|
import {
ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
Input,
OnInit,
Output,
TemplateRef,
} from '@angular/core';
import { ICON_TYPE } from '@spartacus/storefront';
import { Observable } from 'rxjs';
/**
* Generic in-memory paged list component that can be used to render arbitrary items in
* a vertical orientation.
* Previous/next buttons as well as indicator-buttons can used to navigate the slides (pages).
*
* To allow for flexible rendering of items, the rendering is delegated to the
* given `template` and `headerTemplate`.
*/
@Component({
selector: 'cx-epd-visualization-paged-list',
templateUrl: './paged-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PagedListComponent implements OnInit {
/**
* The title is rendered as the carousel heading.
*/
@Input() title: string;
/**
* The items$ represent the carousel items.
*/
@Input() items: Observable<any>[];
/**
* The headerTemplate is rendered above the item rows.
*/
@Input() headerTemplate: TemplateRef<any>;
/**
* The template is rendered for each item, so that the actual
* view can be given by the component that uses the `PagedListComponent`.
*/
@Input() template: TemplateRef<any>;
/**
* The maximum number of items per slide
*/
@Input() itemsPerSlide = 10;
/**
* Indicates whether the visual indicators are used.
*/
@Input() hideIndicators = false;
@Input() indicatorIcon = ICON_TYPE.CIRCLE;
@Input() previousIcon = ICON_TYPE.CARET_LEFT;
@Input() nextIcon = ICON_TYPE.CARET_RIGHT;
@Input() activeSlideStartIndex = 0;
@Output() activeSlideStartIndexChange = new EventEmitter<number>();
setActiveSlideStartIndex(activeSlideStartIndex: number) {
this.activeSlideStartIndex = activeSlideStartIndex;
this.activeSlideStartIndexChange.emit(activeSlideStartIndex);
}
constructor(protected el: ElementRef) {}
ngOnInit() {
if (!this.headerTemplate) {
console.error(
'No template reference provided to render the header for the `cx-epd-visualization-paged-list`'
);
return;
}
if (!this.template) {
console.error(
'No template reference provided to render the items for the `cx-epd-visualization-paged-list`'
);
return;
}
}
}
<ng-container *ngIf="items?.length > 0 && itemsPerSlide">
<h3 *ngIf="title">{{ title }}</h3>
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
<div class="list-panel">
<div class="slides">
<ng-container *ngFor="let _ of items; let i = index">
<div
class="slide"
*ngIf="i % itemsPerSlide === 0"
[class.active]="i === activeSlideStartIndex"
>
<ng-container
*ngFor="
let item of items | slice: i:i + itemsPerSlide;
let j = index
"
>
<div
*ngIf="item as data"
class="item"
[class.active]="i === activeSlideStartIndex"
>
<ng-container
*ngTemplateOutlet="
template;
context: {
item: data,
active: i === activeSlideStartIndex
}
"
></ng-container>
</div>
</ng-container>
</div>
</ng-container>
</div>
</div>
<div
*ngIf="!hideIndicators && itemsPerSlide < items.length"
class="indicators"
>
<button
*ngIf="itemsPerSlide < items.length"
class="previous"
(click)="setActiveSlideStartIndex(activeSlideStartIndex - itemsPerSlide)"
[disabled]="activeSlideStartIndex === 0"
>
<cx-icon [type]="previousIcon"></cx-icon>
</button>
<ng-container *ngFor="let _ of items; let i = index">
<button
*ngIf="i % itemsPerSlide === 0"
(click)="setActiveSlideStartIndex(i)"
[disabled]="i === activeSlideStartIndex"
class="slide-indicator"
>
<cx-icon [type]="indicatorIcon"></cx-icon>
</button>
</ng-container>
<button
*ngIf="itemsPerSlide < items.length"
class="next"
(click)="setActiveSlideStartIndex(activeSlideStartIndex + itemsPerSlide)"
[disabled]="activeSlideStartIndex > items.length - itemsPerSlide - 1"
>
<cx-icon [type]="nextIcon"></cx-icon>
</button>
</div>
</ng-container>
Legend
Html element with directive