UNPKG

ng-zorro-antd-yj

Version:

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

184 lines 13.4 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, ViewEncapsulation } from '@angular/core'; import { moveUpMotion } from '../core/animation/move'; import { NzMessageContainerComponent } from './nz-message-container.component'; export class NzMessageComponent { // Time to live. /** * @param {?} _messageContainer * @param {?} cdr */ constructor(_messageContainer, cdr) { this._messageContainer = _messageContainer; this.cdr = cdr; // Whether to set a timeout to destroy itself. this._eraseTimer = null; } /** * @return {?} */ ngOnInit() { // `NzMessageContainer` does its job so all properties cannot be undefined. this._options = (/** @type {?} */ (this.nzMessage.options)); if (this._options.nzAnimate) { this.nzMessage.state = 'enter'; } this._autoErase = this._options.nzDuration > 0; if (this._autoErase) { this._initErase(); this._startEraseTimeout(); } } /** * @return {?} */ ngOnDestroy() { if (this._autoErase) { this._clearEraseTimeout(); } } /** * @return {?} */ onEnter() { if (this._autoErase && this._options.nzPauseOnHover) { this._clearEraseTimeout(); this._updateTTL(); } } /** * @return {?} */ onLeave() { if (this._autoErase && this._options.nzPauseOnHover) { this._startEraseTimeout(); } } // Remove self /** * @protected * @param {?=} userAction * @return {?} */ _destroy(userAction = false) { if (this._options.nzAnimate) { this.nzMessage.state = 'leave'; this.cdr.detectChanges(); setTimeout((/** * @return {?} */ () => this._messageContainer.removeMessage(this.nzMessage.messageId, userAction)), 200); } else { this._messageContainer.removeMessage(this.nzMessage.messageId, userAction); } } /** * @private * @return {?} */ _initErase() { this._eraseTTL = this._options.nzDuration; this._eraseTimingStart = Date.now(); } /** * @private * @return {?} */ _updateTTL() { if (this._autoErase) { this._eraseTTL -= Date.now() - this._eraseTimingStart; } } /** * @private * @return {?} */ _startEraseTimeout() { if (this._eraseTTL > 0) { this._clearEraseTimeout(); this._eraseTimer = setTimeout((/** * @return {?} */ () => this._destroy()), this._eraseTTL); this._eraseTimingStart = Date.now(); } else { this._destroy(); } } /** * @private * @return {?} */ _clearEraseTimeout() { if (this._eraseTimer !== null) { clearTimeout(this._eraseTimer); this._eraseTimer = null; } } } NzMessageComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-message', preserveWhitespaces: false, animations: [moveUpMotion], template: "<div class=\"ant-message-notice\"\n [@moveUpMotion]=\"nzMessage.state\"\n (mouseenter)=\"onEnter()\"\n (mouseleave)=\"onLeave()\">\n <div class=\"ant-message-notice-content\">\n <div class=\"ant-message-custom-content\" [ngClass]=\"'ant-message-' + nzMessage.type\">\n <ng-container [ngSwitch]=\"nzMessage.type\">\n <i *ngSwitchCase=\"'success'\" nz-icon type=\"check-circle\"></i>\n <i *ngSwitchCase=\"'info'\" nz-icon type=\"info-circle\"></i>\n <i *ngSwitchCase=\"'warning'\" nz-icon type=\"exclamation-circle\"></i>\n <i *ngSwitchCase=\"'error'\" nz-icon type=\"close-circle\"></i>\n <i *ngSwitchCase=\"'loading'\" nz-icon type=\"loading\"></i>\n </ng-container>\n <ng-container *nzStringTemplateOutlet=\"nzMessage.content\">\n <span [innerHTML]=\"nzMessage.content\"></span>\n </ng-container>\n </div>\n </div>\n</div>\n" }] } ]; /** @nocollapse */ NzMessageComponent.ctorParameters = () => [ { type: NzMessageContainerComponent }, { type: ChangeDetectorRef } ]; NzMessageComponent.propDecorators = { nzMessage: [{ type: Input }], nzIndex: [{ type: Input }] }; if (false) { /** @type {?} */ NzMessageComponent.prototype.nzMessage; /** @type {?} */ NzMessageComponent.prototype.nzIndex; /** * @type {?} * @protected */ NzMessageComponent.prototype._options; /** * @type {?} * @private */ NzMessageComponent.prototype._autoErase; /** * @type {?} * @private */ NzMessageComponent.prototype._eraseTimer; /** * @type {?} * @private */ NzMessageComponent.prototype._eraseTimingStart; /** * @type {?} * @private */ NzMessageComponent.prototype._eraseTTL; /** * @type {?} * @private */ NzMessageComponent.prototype._messageContainer; /** * @type {?} * @protected */ NzMessageComponent.prototype.cdr; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnotbWVzc2FnZS5jb21wb25lbnQuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9uZy16b3Jyby1hbnRkLXlqLyIsInNvdXJjZXMiOlsibWVzc2FnZS9uei1tZXNzYWdlLmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsT0FBTyxFQUNMLHVCQUF1QixFQUN2QixpQkFBaUIsRUFDakIsU0FBUyxFQUNULEtBQUssRUFHTCxpQkFBaUIsRUFDbEIsTUFBTSxlQUFlLENBQUM7QUFDdkIsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ3RELE9BQU8sRUFBRSwyQkFBMkIsRUFBRSxNQUFNLGtDQUFrQyxDQUFDO0FBVy9FLE1BQU0sT0FBTyxrQkFBa0I7Ozs7OztJQVc3QixZQUFvQixpQkFBOEMsRUFBWSxHQUFzQjtRQUFoRixzQkFBaUIsR0FBakIsaUJBQWlCLENBQTZCO1FBQVksUUFBRyxHQUFILEdBQUcsQ0FBbUI7O1FBSjVGLGdCQUFXLEdBQWtCLElBQUksQ0FBQztJQUk2RCxDQUFDOzs7O0lBRXhHLFFBQVE7UUFDTiwyRUFBMkU7UUFDM0UsSUFBSSxDQUFDLFFBQVEsR0FBRyxtQkFBQSxJQUFJLENBQUMsU0FBUyxDQUFDLE9BQU8sRUFBa0MsQ0FBQztRQUV6RSxJQUFJLElBQUksQ0FBQyxRQUFRLENBQUMsU0FBUyxFQUFFO1lBQzNCLElBQUksQ0FBQyxTQUFTLENBQUMsS0FBSyxHQUFHLE9BQU8sQ0FBQztTQUNoQztRQUVELElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQyxVQUFVLEdBQUcsQ0FBQyxDQUF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