UNPKG

ng-zorro-antd

Version:

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

283 lines (277 loc) 12.3 kB
import { __decorate } from 'tslib'; import * as i0 from '@angular/core'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Optional, Input, Output, NgModule } from '@angular/core'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { slideAlertMotion } from 'ng-zorro-antd/core/animation'; import * as i1 from 'ng-zorro-antd/core/config'; import { WithConfig } from 'ng-zorro-antd/core/config'; import { InputBoolean } from 'ng-zorro-antd/core/util'; import * as i2 from '@angular/cdk/bidi'; import { BidiModule } from '@angular/cdk/bidi'; import * as i3 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i4 from 'ng-zorro-antd/icon'; import { NzIconModule } from 'ng-zorro-antd/icon'; import * as i5 from 'ng-zorro-antd/core/outlet'; import { NzOutletModule } from 'ng-zorro-antd/core/outlet'; const NZ_CONFIG_MODULE_NAME = 'alert'; class NzAlertComponent { constructor(nzConfigService, cdr, directionality) { this.nzConfigService = nzConfigService; this.cdr = cdr; this.directionality = directionality; this._nzModuleName = NZ_CONFIG_MODULE_NAME; this.nzAction = null; this.nzCloseText = null; this.nzIconType = null; this.nzMessage = null; this.nzDescription = null; this.nzType = 'info'; this.nzCloseable = false; this.nzShowIcon = false; this.nzBanner = false; this.nzNoAnimation = false; this.nzOnClose = new EventEmitter(); this.closed = false; this.iconTheme = 'fill'; this.inferredIconType = 'info-circle'; this.dir = 'ltr'; this.isTypeSet = false; this.isShowIconSet = false; this.destroy$ = new Subject(); this.nzConfigService .getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME) .pipe(takeUntil(this.destroy$)) .subscribe(() => { this.cdr.markForCheck(); }); } ngOnInit() { this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => { this.dir = direction; this.cdr.detectChanges(); }); this.dir = this.directionality.value; } closeAlert() { this.closed = true; } onFadeAnimationDone() { if (this.closed) { this.nzOnClose.emit(true); } } ngOnChanges(changes) { const { nzShowIcon, nzDescription, nzType, nzBanner } = changes; if (nzShowIcon) { this.isShowIconSet = true; } if (nzType) { this.isTypeSet = true; switch (this.nzType) { case 'error': this.inferredIconType = 'close-circle'; break; case 'success': this.inferredIconType = 'check-circle'; break; case 'info': this.inferredIconType = 'info-circle'; break; case 'warning': this.inferredIconType = 'exclamation-circle'; break; } } if (nzDescription) { this.iconTheme = this.nzDescription ? 'outline' : 'fill'; } if (nzBanner) { if (!this.isTypeSet) { this.nzType = 'warning'; } if (!this.isShowIconSet) { this.nzShowIcon = true; } } } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzAlertComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzAlertComponent, deps: [{ token: i1.NzConfigService }, { token: i0.ChangeDetectorRef }, { token: i2.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Component }); NzAlertComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzAlertComponent, selector: "nz-alert", inputs: { nzAction: "nzAction", nzCloseText: "nzCloseText", nzIconType: "nzIconType", nzMessage: "nzMessage", nzDescription: "nzDescription", nzType: "nzType", nzCloseable: "nzCloseable", nzShowIcon: "nzShowIcon", nzBanner: "nzBanner", nzNoAnimation: "nzNoAnimation" }, outputs: { nzOnClose: "nzOnClose" }, exportAs: ["nzAlert"], usesOnChanges: true, ngImport: i0, template: ` <div *ngIf="!closed" class="ant-alert" [class.ant-alert-rtl]="dir === 'rtl'" [class.ant-alert-success]="nzType === 'success'" [class.ant-alert-info]="nzType === 'info'" [class.ant-alert-warning]="nzType === 'warning'" [class.ant-alert-error]="nzType === 'error'" [class.ant-alert-no-icon]="!nzShowIcon" [class.ant-alert-banner]="nzBanner" [class.ant-alert-closable]="nzCloseable" [class.ant-alert-with-description]="!!nzDescription" [@.disabled]="nzNoAnimation" [@slideAlertMotion] (@slideAlertMotion.done)="onFadeAnimationDone()" > <ng-container *ngIf="nzShowIcon"> <i nz-icon class="ant-alert-icon" [nzType]="nzIconType || inferredIconType" [nzTheme]="iconTheme"></i> </ng-container> <div class="ant-alert-content" *ngIf="nzMessage || nzDescription"> <span class="ant-alert-message" *ngIf="nzMessage"> <ng-container *nzStringTemplateOutlet="nzMessage">{{ nzMessage }}</ng-container> </span> <span class="ant-alert-description" *ngIf="nzDescription"> <ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container> </span> </div> <div class="ant-alert-action" *ngIf="nzAction"> <ng-container *nzStringTemplateOutlet="nzAction">{{ nzAction }}</ng-container> </div> <button type="button" tabindex="0" *ngIf="nzCloseable || nzCloseText" class="ant-alert-close-icon" (click)="closeAlert()" > <ng-template #closeDefaultTemplate> <i nz-icon nzType="close"></i> </ng-template> <ng-container *ngIf="nzCloseText; else closeDefaultTemplate"> <ng-container *nzStringTemplateOutlet="nzCloseText"> <span class="ant-alert-close-text">{{ nzCloseText }}</span> </ng-container> </ng-container> </button> </div> `, isInline: true, directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4.NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { type: i5.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }], animations: [slideAlertMotion], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); __decorate([ WithConfig(), InputBoolean() ], NzAlertComponent.prototype, "nzCloseable", void 0); __decorate([ WithConfig(), InputBoolean() ], NzAlertComponent.prototype, "nzShowIcon", void 0); __decorate([ InputBoolean() ], NzAlertComponent.prototype, "nzBanner", void 0); __decorate([ InputBoolean() ], NzAlertComponent.prototype, "nzNoAnimation", void 0); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzAlertComponent, decorators: [{ type: Component, args: [{ selector: 'nz-alert', exportAs: 'nzAlert', animations: [slideAlertMotion], template: ` <div *ngIf="!closed" class="ant-alert" [class.ant-alert-rtl]="dir === 'rtl'" [class.ant-alert-success]="nzType === 'success'" [class.ant-alert-info]="nzType === 'info'" [class.ant-alert-warning]="nzType === 'warning'" [class.ant-alert-error]="nzType === 'error'" [class.ant-alert-no-icon]="!nzShowIcon" [class.ant-alert-banner]="nzBanner" [class.ant-alert-closable]="nzCloseable" [class.ant-alert-with-description]="!!nzDescription" [@.disabled]="nzNoAnimation" [@slideAlertMotion] (@slideAlertMotion.done)="onFadeAnimationDone()" > <ng-container *ngIf="nzShowIcon"> <i nz-icon class="ant-alert-icon" [nzType]="nzIconType || inferredIconType" [nzTheme]="iconTheme"></i> </ng-container> <div class="ant-alert-content" *ngIf="nzMessage || nzDescription"> <span class="ant-alert-message" *ngIf="nzMessage"> <ng-container *nzStringTemplateOutlet="nzMessage">{{ nzMessage }}</ng-container> </span> <span class="ant-alert-description" *ngIf="nzDescription"> <ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container> </span> </div> <div class="ant-alert-action" *ngIf="nzAction"> <ng-container *nzStringTemplateOutlet="nzAction">{{ nzAction }}</ng-container> </div> <button type="button" tabindex="0" *ngIf="nzCloseable || nzCloseText" class="ant-alert-close-icon" (click)="closeAlert()" > <ng-template #closeDefaultTemplate> <i nz-icon nzType="close"></i> </ng-template> <ng-container *ngIf="nzCloseText; else closeDefaultTemplate"> <ng-container *nzStringTemplateOutlet="nzCloseText"> <span class="ant-alert-close-text">{{ nzCloseText }}</span> </ng-container> </ng-container> </button> </div> `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, preserveWhitespaces: false }] }], ctorParameters: function () { return [{ type: i1.NzConfigService }, { type: i0.ChangeDetectorRef }, { type: i2.Directionality, decorators: [{ type: Optional }] }]; }, propDecorators: { nzAction: [{ type: Input }], nzCloseText: [{ type: Input }], nzIconType: [{ type: Input }], nzMessage: [{ type: Input }], nzDescription: [{ type: Input }], nzType: [{ type: Input }], nzCloseable: [{ type: Input }], nzShowIcon: [{ type: Input }], nzBanner: [{ type: Input }], nzNoAnimation: [{ type: Input }], nzOnClose: [{ type: Output }] } }); /** * 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 */ class NzAlertModule { } NzAlertModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzAlertModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); NzAlertModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzAlertModule, declarations: [NzAlertComponent], imports: [BidiModule, CommonModule, NzIconModule, NzOutletModule], exports: [NzAlertComponent] }); NzAlertModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzAlertModule, imports: [[BidiModule, CommonModule, NzIconModule, NzOutletModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzAlertModule, decorators: [{ type: NgModule, args: [{ declarations: [NzAlertComponent], exports: [NzAlertComponent], imports: [BidiModule, CommonModule, NzIconModule, NzOutletModule] }] }] }); /** * 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 */ /** * Generated bundle index. Do not edit. */ export { NzAlertComponent, NzAlertModule }; //# sourceMappingURL=ng-zorro-antd-alert.mjs.map