/
statistic.component.ts
75 lines (66 loc) · 2.35 KB
/
statistic.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
import { Direction, Directionality } from '@angular/cdk/bidi';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Input,
OnDestroy,
OnInit,
Optional,
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NgStyleInterface } from 'ng-zorro-antd/core/types';
import { NzStatisticValueType } from './typings';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-statistic',
exportAs: 'nzStatistic',
template: `
<div class="ant-statistic-title">
<ng-container *nzStringTemplateOutlet="nzTitle">{{ nzTitle }}</ng-container>
</div>
<div class="ant-statistic-content" [ngStyle]="nzValueStyle">
<span *ngIf="nzPrefix" class="ant-statistic-content-prefix">
<ng-container *nzStringTemplateOutlet="nzPrefix">{{ nzPrefix }}</ng-container>
</span>
<nz-statistic-number [nzValue]="nzValue" [nzValueTemplate]="nzValueTemplate"></nz-statistic-number>
<span *ngIf="nzSuffix" class="ant-statistic-content-suffix">
<ng-container *nzStringTemplateOutlet="nzSuffix">{{ nzSuffix }}</ng-container>
</span>
</div>
`,
host: {
class: 'ant-statistic',
'[class.ant-statistic-rtl]': `dir === 'rtl'`
}
})
export class NzStatisticComponent implements OnDestroy, OnInit {
@Input() nzPrefix?: string | TemplateRef<void>;
@Input() nzSuffix?: string | TemplateRef<void>;
@Input() nzTitle?: string | TemplateRef<void>;
@Input() nzValue?: NzStatisticValueType;
@Input() nzValueStyle: NgStyleInterface = {};
@Input() nzValueTemplate?: TemplateRef<{ $implicit: NzStatisticValueType }>;
dir: Direction = 'ltr';
private destroy$ = new Subject<void>();
constructor(protected cdr: ChangeDetectorRef, @Optional() private directionality: Directionality) {}
ngOnInit(): void {
this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction: Direction) => {
this.dir = direction;
this.cdr.detectChanges();
});
this.dir = this.directionality.value;
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}