ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
334 lines (325 loc) • 10.2 kB
JavaScript
import { Platform, PlatformModule } from '@angular/cdk/platform';
import { Component, ChangeDetectionStrategy, ViewEncapsulation, Input, EventEmitter, ChangeDetectorRef, NgZone, Output, Inject, LOCALE_ID, NgModule } from '@angular/core';
import { interval } from 'rxjs';
import { getLocaleNumberSymbol, NumberSymbol, CommonModule } from '@angular/common';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzPipesModule } from 'ng-zorro-antd/core/pipe';
/**
* @fileoverview added by tsickle
* Generated from: statistic.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzStatisticComponent {
constructor() {
this.nzValueStyle = {};
}
}
NzStatisticComponent.decorators = [
{ type: Component, args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-statistic',
exportAs: 'nzStatistic',
template: `
<div class="ant-statistic">
<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>
</div>
`
}] }
];
NzStatisticComponent.propDecorators = {
nzPrefix: [{ type: Input }],
nzSuffix: [{ type: Input }],
nzTitle: [{ type: Input }],
nzValue: [{ type: Input }],
nzValueStyle: [{ type: Input }],
nzValueTemplate: [{ type: Input }]
};
if (false) {
/** @type {?} */
NzStatisticComponent.prototype.nzPrefix;
/** @type {?} */
NzStatisticComponent.prototype.nzSuffix;
/** @type {?} */
NzStatisticComponent.prototype.nzTitle;
/** @type {?} */
NzStatisticComponent.prototype.nzValue;
/** @type {?} */
NzStatisticComponent.prototype.nzValueStyle;
/** @type {?} */
NzStatisticComponent.prototype.nzValueTemplate;
}
/**
* @fileoverview added by tsickle
* Generated from: countdown.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const REFRESH_INTERVAL = 1000 / 30;
class NzCountdownComponent extends NzStatisticComponent {
/**
* @param {?} cdr
* @param {?} ngZone
* @param {?} platform
*/
constructor(cdr, ngZone, platform) {
super();
this.cdr = cdr;
this.ngZone = ngZone;
this.platform = platform;
this.nzFormat = 'HH:mm:ss';
this.nzCountdownFinish = new EventEmitter();
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.nzValue) {
this.target = Number(changes.nzValue.currentValue);
if (!changes.nzValue.isFirstChange()) {
this.syncTimer();
}
}
}
/**
* @return {?}
*/
ngOnInit() {
this.syncTimer();
}
/**
* @return {?}
*/
ngOnDestroy() {
this.stopTimer();
}
/**
* @return {?}
*/
syncTimer() {
if (this.target >= Date.now()) {
this.startTimer();
}
else {
this.stopTimer();
}
}
/**
* @return {?}
*/
startTimer() {
if (this.platform.isBrowser) {
this.ngZone.runOutsideAngular((/**
* @return {?}
*/
() => {
this.stopTimer();
this.updater_ = interval(REFRESH_INTERVAL).subscribe((/**
* @return {?}
*/
() => {
this.updateValue();
this.cdr.detectChanges();
}));
}));
}
}
/**
* @return {?}
*/
stopTimer() {
if (this.updater_) {
this.updater_.unsubscribe();
this.updater_ = null;
}
}
/**
* Update time that should be displayed on the screen.
* @protected
* @return {?}
*/
updateValue() {
this.diff = Math.max(this.target - Date.now(), 0);
if (this.diff === 0) {
this.stopTimer();
this.nzCountdownFinish.emit();
}
}
}
NzCountdownComponent.decorators = [
{ type: Component, args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-countdown',
exportAs: 'nzCountdown',
template: `
<nz-statistic
[nzValue]="diff"
[nzValueStyle]="nzValueStyle"
[nzValueTemplate]="nzValueTemplate || countDownTpl"
[nzTitle]="nzTitle"
[nzPrefix]="nzPrefix"
[nzSuffix]="nzSuffix"
>
</nz-statistic>
<ng-template #countDownTpl>{{ diff | nzTimeRange: nzFormat }}</ng-template>
`
}] }
];
/** @nocollapse */
NzCountdownComponent.ctorParameters = () => [
{ type: ChangeDetectorRef },
{ type: NgZone },
{ type: Platform }
];
NzCountdownComponent.propDecorators = {
nzFormat: [{ type: Input }],
nzCountdownFinish: [{ type: Output }]
};
if (false) {
/** @type {?} */
NzCountdownComponent.prototype.nzFormat;
/** @type {?} */
NzCountdownComponent.prototype.nzCountdownFinish;
/** @type {?} */
NzCountdownComponent.prototype.diff;
/**
* @type {?}
* @private
*/
NzCountdownComponent.prototype.target;
/**
* @type {?}
* @private
*/
NzCountdownComponent.prototype.updater_;
/**
* @type {?}
* @private
*/
NzCountdownComponent.prototype.cdr;
/**
* @type {?}
* @private
*/
NzCountdownComponent.prototype.ngZone;
/**
* @type {?}
* @private
*/
NzCountdownComponent.prototype.platform;
}
/**
* @fileoverview added by tsickle
* Generated from: statistic-number.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzStatisticNumberComponent {
/**
* @param {?} locale_id
*/
constructor(locale_id) {
this.locale_id = locale_id;
this.displayInt = '';
this.displayDecimal = '';
}
/**
* @return {?}
*/
ngOnChanges() {
this.formatNumber();
}
/**
* @private
* @return {?}
*/
formatNumber() {
/** @type {?} */
const decimalSeparator = typeof this.nzValue === 'number' ? '.' : getLocaleNumberSymbol(this.locale_id, NumberSymbol.Decimal);
/** @type {?} */
const value = String(this.nzValue);
const [int, decimal] = value.split(decimalSeparator);
this.displayInt = int;
this.displayDecimal = decimal ? `${decimalSeparator}${decimal}` : '';
}
}
NzStatisticNumberComponent.decorators = [
{ type: Component, args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
preserveWhitespaces: false,
selector: 'nz-statistic-number',
exportAs: 'nzStatisticNumber',
template: `
<span class="ant-statistic-content-value">
<ng-container *ngIf="nzValueTemplate" [ngTemplateOutlet]="nzValueTemplate" [ngTemplateOutletContext]="{ $implicit: nzValue }">
</ng-container>
<ng-container *ngIf="!nzValueTemplate">
<span *ngIf="displayInt" class="ant-statistic-content-value-int">{{ displayInt }}</span>
<span *ngIf="displayDecimal" class="ant-statistic-content-value-decimal">{{ displayDecimal }}</span>
</ng-container>
</span>
`
}] }
];
/** @nocollapse */
NzStatisticNumberComponent.ctorParameters = () => [
{ type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] }
];
NzStatisticNumberComponent.propDecorators = {
nzValue: [{ type: Input }],
nzValueTemplate: [{ type: Input }]
};
if (false) {
/** @type {?} */
NzStatisticNumberComponent.prototype.nzValue;
/** @type {?} */
NzStatisticNumberComponent.prototype.nzValueTemplate;
/** @type {?} */
NzStatisticNumberComponent.prototype.displayInt;
/** @type {?} */
NzStatisticNumberComponent.prototype.displayDecimal;
/**
* @type {?}
* @private
*/
NzStatisticNumberComponent.prototype.locale_id;
}
/**
* @fileoverview added by tsickle
* Generated from: statistic.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzStatisticModule {
}
NzStatisticModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule, PlatformModule, NzOutletModule, NzPipesModule],
declarations: [NzStatisticComponent, NzCountdownComponent, NzStatisticNumberComponent],
exports: [NzStatisticComponent, NzCountdownComponent, NzStatisticNumberComponent]
},] }
];
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ng-zorro-antd-statistic.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NzCountdownComponent, NzStatisticComponent, NzStatisticModule, NzStatisticNumberComponent };
//# sourceMappingURL=ng-zorro-antd-statistic.js.map