projects/rebirth-ng/src/lib/ellipsis/ellipsis.component.ts
changeDetection | ChangeDetectionStrategy.OnPush |
exportAs | ellipsis |
selector | re-ellipsis |
styleUrls | ellipsis.component.scss |
templateUrl | ./ellipsis.component.html |
Properties |
Methods |
|
Inputs |
constructor(rebirthNGConfig: RebirthNGConfig, documentRef: DocumentRef)
|
|||||||||
Parameters :
|
html
|
Default value: |
max
|
Type: |
placement
|
Type: |
text
|
Type: |
Private ellipsis |
ellipsis()
|
Returns :
void
|
Private unCodeHtml | ||||||
unCodeHtml(text: string)
|
||||||
Parameters :
Returns :
string
|
ellipsisText |
ellipsisText:
|
Type : string
|
Default value : ''
|
fullText |
fullText:
|
Type : string
|
Default value : ''
|
length |
length:
|
Type : number
|
max | ||||||
setmax(length: number)
|
||||||
Parameters :
Returns :
void
|
text | ||||||
settext(text: string)
|
||||||
Parameters :
Returns :
void
|
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
import { RebirthNGConfig } from '../rebirth-ng.config';
import { DocumentRef } from '../window-ref/document-ref.service';
@Component({
selector: 're-ellipsis',
templateUrl: './ellipsis.component.html',
styleUrls: ['./ellipsis.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
exportAs: 'ellipsis'
})
export class EllipsisComponent {
length: number;
fullText = '';
ellipsisText = '';
@Input() placement: 'top' | 'bottom' | 'left' | 'right';
@Input() html = false;
constructor(rebirthNGConfig: RebirthNGConfig, private documentRef: DocumentRef) {
this.length = rebirthNGConfig.ellipsis.length;
this.placement = <any>rebirthNGConfig.ellipsis.placement;
}
@Input()
set max(length: number) {
this.length = length;
this.ellipsis();
}
@Input()
set text(text: string) {
this.fullText = text || '';
this.ellipsis();
}
private ellipsis() {
const text = this.html ? this.unCodeHtml(this.fullText) : this.fullText;
this.ellipsisText = text.length > this.length ? text.substr(0, this.length) : '';
}
private unCodeHtml(text: string) {
const $div = this.documentRef.createElement('div');
$div.innerHTML = text;
text = $div.innerText;
return text;
}
}
<span *ngIf="ellipsisText" [reTooltip]="fullText" [placement]="placement">{{ellipsisText}}...</span>
<span *ngIf="!html && !ellipsisText">{{fullText}}</span>
<span *ngIf="html && !ellipsisText" [innerHTML]="fullText"></span>