File

feature-libs/product-configurator/rulebased/components/show-more/configurator-show-more.component.ts

Implements

AfterViewInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-show-more
templateUrl ./configurator-show-more.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(cdRef: ChangeDetectorRef)
Parameters :
Name Type Optional
cdRef ChangeDetectorRef No

Inputs

text
Type : string
textSize
Type : number
Default value : 60

Methods

ngAfterViewInit
ngAfterViewInit()
Returns : void
Protected normalize
normalize(text: string)
Parameters :
Name Type Optional Default value
text string No ''
Returns : string
toggleShowMore
toggleShowMore()
Returns : void

Properties

showHiddenText
Default value : false
showMore
Default value : false
text
Type : string
Decorators :
@Input()
textNormalized
Type : string
textSize
Type : number
Default value : 60
Decorators :
@Input()
textToShow
Type : string
import {
  AfterViewInit,
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  Input,
} from '@angular/core';

@Component({
  selector: 'cx-configurator-show-more',
  templateUrl: './configurator-show-more.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorShowMoreComponent implements AfterViewInit {
  showMore = false;
  showHiddenText = false;
  textToShow: string;
  textNormalized: string;

  @Input() text: string;
  @Input() textSize = 60;

  constructor(protected cdRef: ChangeDetectorRef) {}

  ngAfterViewInit(): void {
    this.textNormalized = this.normalize(this.text);

    if (this.textNormalized.length > this.textSize) {
      this.showMore = true;
      this.textToShow = this.textNormalized.substring(0, this.textSize);
    } else {
      this.textToShow = this.textNormalized;
    }
    this.cdRef.detectChanges();
  }

  toggleShowMore(): void {
    this.showHiddenText = !this.showHiddenText;

    this.showHiddenText
      ? (this.textToShow = this.textNormalized)
      : (this.textToShow = this.textNormalized.substring(0, this.textSize));

    this.cdRef.detectChanges();
  }

  protected normalize(text: string = ''): string {
    return text.replace(/<[^>]*>/g, '');
  }
}
<ng-container *ngIf="text">
  <span>{{ textToShow }}</span>

  <button (click)="toggleShowMore()" *ngIf="showMore">
    <ng-container *ngIf="showHiddenText; else less"
      >&nbsp;... {{ 'configurator.button.less' | cxTranslate }}</ng-container
    >

    <ng-template #less>
      &nbsp;... {{ 'configurator.button.more' | cxTranslate }}</ng-template
    >
  </button>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""