File

projects/storefrontlib/cms-components/content/banner-carousel/banner-carousel.component.ts

Description

Generic carousel that renders CMS Components.

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-banner-carousel
templateUrl banner-carousel.component.html

Index

Properties
Methods
HostBindings

Constructor

constructor(componentData: CmsComponentData<model>, cmsService: CmsService)
Parameters :
Name Type Optional
componentData CmsComponentData<model> No
cmsService CmsService No

HostBindings

class
Type : string
Default value : ''

Adds a specific theme for the carousel. The effect can be used in CSS customisations.

Methods

getItems
getItems()

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.

Returns : Observable<Observable[]>

Properties

Private componentData$
Type : Observable<model>
Default value : this.componentData.data$.pipe( filter(Boolean), tap((d: model) => (this.theme = `${d.effect}-theme`)) )
Private items$
Type : Observable<Observable[]>
Default value : this.componentData$.pipe( map((data) => data.banners.trim().split(' ')), map((codes) => codes.map((code) => this.cmsService.getComponentData(code)) ) )
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>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""