File

projects/storefrontlib/cms-components/product/product-list/product-facet-navigation/facet-list/facet-list.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-facet-list
templateUrl ./facet-list.component.html

Index

Properties
Methods
Inputs
Outputs
HostListeners
Accessors

Constructor

constructor(facetService: FacetService, elementRef: ElementRef, renderer: Renderer2)
Parameters :
Name Type Optional
facetService FacetService No
elementRef ElementRef No
renderer Renderer2 No

Inputs

isDialog
Type : boolean

Indicates that the facet navigation is rendered in dialog.

Outputs

closeList
Type : EventEmitter

Emits when the list must close

HostListeners

click
click()

Methods

block
block(event?: MouseEvent)
Parameters :
Name Type Optional
event MouseEvent Yes
Returns : void
close
close(event?: boolean)
Parameters :
Name Type Optional
event boolean Yes
Returns : void
expandFacetGroup
expandFacetGroup(facet: Facet, ref: FacetComponent)

Toggles the facet group in case it is not expanded.

Parameters :
Name Type Optional
facet Facet No
ref FacetComponent No
Returns : void
handleClick
handleClick()
Decorators :
@HostListener('click')
Returns : void
isCollapsed
isCollapsed(facet: Facet)

Indicates that the facet group has been collapsed.

Parameters :
Name Type Optional
facet Facet No
Returns : Observable<boolean>
isExpanded
isExpanded(facet: Facet)

Indicates that the facet group has been expanded.

Parameters :
Name Type Optional
facet Facet No
Returns : Observable<boolean>

Properties

Private _isDialog
Type : boolean
closeList
Default value : new EventEmitter()
Decorators :
@Output()

Emits when the list must close

dialogFocusConfig
Type : FocusConfig
Default value : { trap: true, block: true, focusOnEscape: true, autofocus: 'cx-facet', }
facetList$
Type : Observable<FacetList>
Default value : this.facetService.facetList$

The list of all facet and values related to the products in the list

iconTypes
Default value : ICON_TYPE

Accessors

isDialog
getisDialog()
setisDialog(value: boolean)

Indicates that the facet navigation is rendered in dialog.

Parameters :
Name Type Optional
value boolean No
Returns : void
import {
  ChangeDetectionStrategy,
  Component,
  ElementRef,
  EventEmitter,
  HostListener,
  Input,
  Output,
  Renderer2,
} from '@angular/core';
import { Facet } from '@spartacus/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { FocusConfig } from '../../../../../layout/a11y/keyboard-focus/index';
import { ICON_TYPE } from '../../../../misc/icon/icon.model';
import { FacetGroupCollapsedState, FacetList } from '../facet.model';
import { FacetComponent } from '../facet/facet.component';
import { FacetService } from '../services/facet.service';

@Component({
  selector: 'cx-facet-list',
  templateUrl: './facet-list.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FacetListComponent {
  private _isDialog: boolean;
  /**
   * Indicates that the facet navigation is rendered in dialog.
   */
  @Input()
  set isDialog(value: boolean) {
    this._isDialog = value;
    if (value) {
      this.renderer.addClass(document.body, 'modal-open');
    }
  }

  get isDialog(): boolean {
    return this._isDialog;
  }

  /** Emits when the list must close */
  @Output() closeList = new EventEmitter();

  /** The list of all facet and values related to the products in the list */
  facetList$: Observable<FacetList> = this.facetService.facetList$;

  iconTypes = ICON_TYPE;

  dialogFocusConfig: FocusConfig = {
    trap: true,
    block: true,
    focusOnEscape: true,
    autofocus: 'cx-facet',
  };

  @HostListener('click') handleClick() {
    this.close();
  }

  constructor(
    protected facetService: FacetService,
    protected elementRef: ElementRef,
    protected renderer: Renderer2
  ) {}

  /**
   * Toggles the facet group in case it is not expanded.
   */
  expandFacetGroup(facet: Facet, ref: FacetComponent) {
    if (!ref.isExpanded) {
      this.facetService.toggle(facet, ref.isExpanded);
    }
  }

  /**
   * Indicates that the facet group has been expanded.
   */
  isExpanded(facet: Facet): Observable<boolean> {
    return this.facetService
      .getState(facet)
      .pipe(
        map((value) => value.toggled === FacetGroupCollapsedState.EXPANDED)
      );
  }

  /**
   * Indicates that the facet group has been collapsed.
   */
  isCollapsed(facet: Facet): Observable<boolean> {
    return this.facetService
      .getState(facet)
      .pipe(
        map((value) => value.toggled === FacetGroupCollapsedState.COLLAPSED)
      );
  }

  close(event?: boolean): void {
    this.renderer.removeClass(document.body, 'modal-open');
    this.closeList.emit(event);
  }

  block(event?: MouseEvent) {
    event.stopPropagation();
  }
}
<div
  class="inner"
  *ngIf="(facetList$ | async)?.facets as facets"
  [cxFocus]="isDialog ? dialogFocusConfig : {}"
  (esc)="close($event)"
  (click)="block($event)"
>
  <h4>
    {{ 'productList.filterBy.label' | cxTranslate }}
    <button
      type="button"
      class="close"
      [attr.aria-label]="'common.close' | cxTranslate"
      (click)="close()"
    >
      <cx-icon aria-hidden="true" [type]="iconTypes.CLOSE"></cx-icon>
    </button>
  </h4>

  <!-- 
      Here we'd like to introduce configurable facet components, 
      either by using specific configuration or generic sproutlets 
  -->
  <cx-facet
    *ngFor="let facet of facets"
    #facetRef
    [facet]="facet"
    [cxFocus]="{ lock: true, trap: true, autofocus: 'a' }"
    (unlock)="expandFacetGroup(facet, facetRef)"
    [class.expanded]="isExpanded(facet) | async"
    [class.collapsed]="isCollapsed(facet) | async"
  ></cx-facet>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""