UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

402 lines (387 loc) 16.5 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/platform'), require('rxjs'), require('@angular/common'), require('@angular/core'), require('ng-zorro-antd/core')) : typeof define === 'function' && define.amd ? define('ng-zorro-antd/statistic', ['exports', '@angular/cdk/platform', 'rxjs', '@angular/common', '@angular/core', 'ng-zorro-antd/core'], factory) : (factory((global['ng-zorro-antd'] = global['ng-zorro-antd'] || {}, global['ng-zorro-antd'].statistic = {}),global.ng.cdk.platform,global.rxjs,global.ng.common,global.ng.core,global['ng-zorro-antd'].core)); }(this, (function (exports,platform,rxjs,common,core,core$1) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Alibaba.com All Rights Reserved. * * 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 */ /** @type {?} */ var REFRESH_INTERVAL = 1000 / 30; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzStatisticComponent = /** @class */ (function () { function NzStatisticComponent() { this.nzValueStyle = {}; } NzStatisticComponent.decorators = [ { type: core.Component, args: [{ changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, selector: 'nz-statistic', exportAs: 'nzStatistic', template: "<div class=\"ant-statistic-title\">\n <ng-container *nzStringTemplateOutlet=\"nzTitle\">{{ nzTitle }}</ng-container>\n</div>\n<div class=\"ant-statistic-content\" [ngStyle]=\"nzValueStyle\">\n <span *ngIf=\"nzPrefix\" class=\"ant-statistic-content-prefix\">\n <ng-container *nzStringTemplateOutlet=\"nzPrefix\">{{ nzPrefix }}</ng-container>\n </span>\n <nz-statistic-number\n [nzValue]=\"nzValue\"\n [nzValueTemplate]=\"nzValueTemplate\">\n </nz-statistic-number>\n <span *ngIf=\"nzSuffix\" class=\"ant-statistic-content-suffix\">\n <ng-container *nzStringTemplateOutlet=\"nzSuffix\">{{ nzSuffix }}</ng-container>\n </span>\n</div>\n", host: { class: 'ant-statistic' }, styles: ['nz-statistic { display: block; }'] }] } ]; NzStatisticComponent.propDecorators = { nzPrefix: [{ type: core.Input }], nzSuffix: [{ type: core.Input }], nzTitle: [{ type: core.Input }], nzValue: [{ type: core.Input }], nzValueStyle: [{ type: core.Input }], nzValueTemplate: [{ type: core.Input }] }; return NzStatisticComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzCountdownComponent = /** @class */ (function (_super) { __extends(NzCountdownComponent, _super); function NzCountdownComponent(cdr, ngZone, platform$$1) { var _this = _super.call(this) || this; _this.cdr = cdr; _this.ngZone = ngZone; _this.platform = platform$$1; /** * @override */ _this.nzFormat = 'HH:mm:ss'; return _this; } /** @override */ /** * @override * @param {?} changes * @return {?} */ NzCountdownComponent.prototype.ngOnChanges = /** * @override * @param {?} changes * @return {?} */ function (changes) { if (changes.nzValue) { this.target = Number(changes.nzValue.currentValue); if (!changes.nzValue.isFirstChange()) { this.syncTimer(); } } }; /** * @return {?} */ NzCountdownComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.syncTimer(); }; /** * @return {?} */ NzCountdownComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.stopTimer(); }; /** * @return {?} */ NzCountdownComponent.prototype.syncTimer = /** * @return {?} */ function () { if (this.target >= Date.now()) { this.startTimer(); } else { this.stopTimer(); } }; /** * @return {?} */ NzCountdownComponent.prototype.startTimer = /** * @return {?} */ function () { var _this = this; if (this.platform.isBrowser) { this.ngZone.runOutsideAngular(( /** * @return {?} */function () { _this.stopTimer(); _this.updater_ = rxjs.interval(REFRESH_INTERVAL).subscribe(( /** * @return {?} */function () { _this.updateValue(); _this.cdr.detectChanges(); })); })); } }; /** * @return {?} */ NzCountdownComponent.prototype.stopTimer = /** * @return {?} */ function () { if (this.updater_) { this.updater_.unsubscribe(); this.updater_ = null; } }; /** * Update time that should be displayed on the screen. */ /** * Update time that should be displayed on the screen. * @protected * @return {?} */ NzCountdownComponent.prototype.updateValue = /** * Update time that should be displayed on the screen. * @protected * @return {?} */ function () { this.diff = Math.max(this.target - Date.now(), 0); if (this.diff === 0) { this.stopTimer(); } }; NzCountdownComponent.decorators = [ { type: core.Component, args: [{ changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, selector: 'nz-countdown', exportAs: 'nzCountdown', template: "<nz-statistic\n [nzValue]=\"diff\"\n [nzValueStyle]=\"nzValueStyle\"\n [nzValueTemplate]=\"nzValueTemplate || countDownTpl\"\n [nzTitle]=\"nzTitle\"\n [nzPrefix]=\"nzPrefix\"\n [nzSuffix]=\"nzSuffix\">\n</nz-statistic>\n\n<ng-template #countDownTpl>{{ diff | nzTimeRange: nzFormat }}</ng-template>" }] } ]; /** @nocollapse */ NzCountdownComponent.ctorParameters = function () { return [ { type: core.ChangeDetectorRef }, { type: core.NgZone }, { type: platform.Platform } ]; }; NzCountdownComponent.propDecorators = { nzFormat: [{ type: core.Input }] }; return NzCountdownComponent; }(NzStatisticComponent)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzStatisticNumberComponent = /** @class */ (function () { function NzStatisticNumberComponent(locale_id) { this.locale_id = locale_id; this.displayInt = ''; this.displayDecimal = ''; } /** * @return {?} */ NzStatisticNumberComponent.prototype.ngOnChanges = /** * @return {?} */ function () { this.formatNumber(); }; /** * @private * @return {?} */ NzStatisticNumberComponent.prototype.formatNumber = /** * @private * @return {?} */ function () { /** @type {?} */ var decimalSeparator = typeof this.nzValue === 'number' ? '.' : common.getLocaleNumberSymbol(this.locale_id, common.NumberSymbol.Decimal); /** @type {?} */ var value = String(this.nzValue); var _a = __read(value.split(decimalSeparator), 2), int = _a[0], decimal = _a[1]; this.displayInt = int; this.displayDecimal = decimal ? "" + decimalSeparator + decimal : ''; }; NzStatisticNumberComponent.decorators = [ { type: core.Component, args: [{ changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, preserveWhitespaces: false, selector: 'nz-statistic-number', exportAs: 'nzStatisticNumber', template: "<ng-container\n *ngIf=\"nzValueTemplate\"\n [ngTemplateOutlet]=\"nzValueTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: nzValue }\">\n</ng-container>\n<ng-container *ngIf=\"!nzValueTemplate\">\n <span *ngIf=\"displayInt\" class=\"ant-statistic-content-value-int\">{{ displayInt }}</span>\n <span *ngIf=\"displayDecimal\" class=\"ant-statistic-content-value-decimal\">{{ displayDecimal }}</span>\n</ng-container>\n", host: { class: 'ant-statistic-content-value' }, styles: ['nz-number { display: inline }'] }] } ]; /** @nocollapse */ NzStatisticNumberComponent.ctorParameters = function () { return [ { type: String, decorators: [{ type: core.Inject, args: [core.LOCALE_ID,] }] } ]; }; NzStatisticNumberComponent.propDecorators = { nzValue: [{ type: core.Input }], nzValueTemplate: [{ type: core.Input }] }; return NzStatisticNumberComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzTimeRangePipe = /** @class */ (function () { function NzTimeRangePipe() { } /** * @param {?} value * @param {?=} format * @return {?} */ NzTimeRangePipe.prototype.transform = /** * @param {?} value * @param {?=} format * @return {?} */ function (value, format) { if (format === void 0) { format = 'HH:mm:ss'; } /** @type {?} */ var duration = Number(value || 0); return core$1.timeUnits.reduce(( /** * @param {?} current * @param {?} __1 * @return {?} */function (current, _a) { var _b = __read(_a, 2), name = _b[0], unit = _b[1]; if (current.indexOf(name) !== -1) { /** @type {?} */ var v_1 = Math.floor(duration / unit); duration -= v_1 * unit; return current.replace(new RegExp(name + "+", 'g'), ( /** * @param {?} match * @return {?} */function (match) { return core$1.padStart(v_1.toString(), match.length, '0'); })); } return current; }), format); }; NzTimeRangePipe.decorators = [ { type: core.Pipe, args: [{ name: 'nzTimeRange', pure: true },] } ]; return NzTimeRangePipe; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzStatisticModule = /** @class */ (function () { function NzStatisticModule() { } NzStatisticModule.decorators = [ { type: core.NgModule, args: [{ imports: [common.CommonModule, core$1.NzAddOnModule], declarations: [NzStatisticComponent, NzCountdownComponent, NzStatisticNumberComponent, NzTimeRangePipe], exports: [NzStatisticComponent, NzCountdownComponent, NzStatisticNumberComponent, NzTimeRangePipe] },] } ]; return NzStatisticModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ exports.NzCountdownComponent = NzCountdownComponent; exports.NzStatisticComponent = NzStatisticComponent; exports.NzStatisticModule = NzStatisticModule; exports.NzStatisticNumberComponent = NzStatisticNumberComponent; exports.NzTimeRangePipe = NzTimeRangePipe; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ng-zorro-antd-statistic.umd.js.map