feature-libs/product-configurator/rulebased/components/show-more/configurator-show-more.component.ts
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | cx-configurator-show-more |
| templateUrl | ./configurator-show-more.component.html |
Properties |
Methods |
|
Inputs |
constructor(cdRef: ChangeDetectorRef)
|
||||||
|
Parameters :
|
| text | |
Type : string
|
|
| textSize | |
Type : number
|
|
Default value : 60
|
|
| ngAfterViewInit |
ngAfterViewInit()
|
|
Returns :
void
|
| Protected normalize | ||||||||
normalize(text: string)
|
||||||||
|
Parameters :
Returns :
string
|
| toggleShowMore |
toggleShowMore()
|
|
Returns :
void
|
| 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"
> ... {{ 'configurator.button.less' | cxTranslate }}</ng-container
>
<ng-template #less>
... {{ 'configurator.button.more' | cxTranslate }}</ng-template
>
</button>
</ng-container>