projects/storefrontlib/cms-components/content/banner-carousel/banner-carousel.component.ts
Generic carousel that renders CMS Components.
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | cx-banner-carousel |
| templateUrl | banner-carousel.component.html |
Properties |
|
Methods |
HostBindings |
constructor(componentData: CmsComponentData<model>, cmsService: CmsService)
|
|||||||||
|
Parameters :
|
| class |
Type : string
|
Default value : ''
|
|
Adds a specific theme for the carousel. The effect can be used in CSS customisations. |
| Private componentData$ |
Type : Observable<model>
|
Default value : this.componentData.data$.pipe(
filter(Boolean),
tap((d: model) => (this.theme = `${d.effect}-theme`))
)
|
| theme |
Type : string
|
Default value : ''
|
Decorators :
@HostBinding('class')
|
|
Adds a specific theme for the carousel. The effect can be used in CSS customisations. |
import { ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';
import {
CmsBannerCarouselComponent as model,
CmsService,
ContentSlotComponentData,
} from '@spartacus/core';
import { Observable } from 'rxjs';
import { filter, map, tap } from 'rxjs/operators';
import { CmsComponentData } from '../../../cms-structure/index';
/**
* Generic carousel that renders CMS Components.
*/
@Component({
selector: 'cx-banner-carousel',
templateUrl: 'banner-carousel.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BannerCarouselComponent {
private componentData$: Observable<model> = this.componentData.data$.pipe(
filter(Boolean),
tap((d: model) => (this.theme = `${d.effect}-theme`))
);
private items$: Observable<Observable<ContentSlotComponentData>[]> =
this.componentData$.pipe(
map((data) => data.banners.trim().split(' ')),
map((codes) =>
codes.map((code) => this.cmsService.getComponentData(code))
)
);
/**
* Adds a specific theme for the carousel. The effect can be
* used in CSS customisations.
*/
@HostBinding('class') theme = '';
constructor(
private componentData: CmsComponentData<model>,
private cmsService: CmsService
) {}
/**
* Returns an Obervable with an Array of Observables. This is done, so that
* the component UI could consider to lazy load the UI components when they're
* in the viewpoint.
*/
getItems(): Observable<Observable<ContentSlotComponentData>[]> {
return this.items$;
}
}
<cx-carousel
[items]="getItems() | async"
[template]="template"
itemWidth="100%"
class="inline-navigation"
></cx-carousel>
<ng-template #template let-item="item">
<ng-container
[cxComponentWrapper]="{
flexType: item.typeCode,
typeCode: item.typeCode,
uid: item?.uid
}"
>
</ng-container>
</ng-template>