UNPKG

ng-zorro-antd

Version:

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

646 lines (636 loc) 27.1 kB
import { NgStyle, NgClass, NgTemplateOutlet } from '@angular/common'; import * as i0 from '@angular/core'; import { EventEmitter, Component, ViewEncapsulation, Input, Output, ChangeDetectionStrategy, NgModule, Injectable } from '@angular/core'; import { notificationMotion } from 'ng-zorro-antd/core/animation'; import * as i2 from 'ng-zorro-antd/core/outlet'; import { NzOutletModule } from 'ng-zorro-antd/core/outlet'; import * as i1 from 'ng-zorro-antd/icon'; import { NzIconModule } from 'ng-zorro-antd/icon'; import { NzMNComponent, NzMNContainerComponent, NzMNService } from 'ng-zorro-antd/message'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { toCssPixel } from 'ng-zorro-antd/core/util'; import * as i1$1 from 'ng-zorro-antd/core/config'; import * as i1$2 from 'ng-zorro-antd/core/services'; import * as i2$1 from '@angular/cdk/overlay'; /** * 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 NzNotificationComponent extends NzMNComponent { constructor(cdr) { super(cdr); this.destroyed = new EventEmitter(); } ngOnDestroy() { super.ngOnDestroy(); this.instance.onClick.complete(); } onClick(event) { this.instance.onClick.next(event); } close() { this.destroy(true); } get state() { if (this.instance.state === 'enter') { switch (this.placement) { case 'topLeft': case 'bottomLeft': return 'enterLeft'; case 'topRight': case 'bottomRight': return 'enterRight'; case 'top': return 'enterTop'; case 'bottom': return 'enterBottom'; default: return 'enterRight'; } } else { return this.instance.state; } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.1.2", type: NzNotificationComponent, isStandalone: true, selector: "nz-notification", inputs: { instance: "instance", index: "index", placement: "placement" }, outputs: { destroyed: "destroyed" }, exportAs: ["nzNotification"], usesInheritance: true, ngImport: i0, template: ` <div class="ant-notification-notice ant-notification-notice-closable" [ngStyle]="instance.options?.nzStyle || null" [ngClass]="instance.options?.nzClass || ''" [@notificationMotion]="state" (@notificationMotion.done)="animationStateChanged.next($event)" (click)="onClick($event)" (mouseenter)="onEnter()" (mouseleave)="onLeave()" > @if (instance.template) { <ng-template [ngTemplateOutlet]="instance.template!" [ngTemplateOutletContext]="{ $implicit: this, data: instance.options?.nzData }" /> } @else { <div class="ant-notification-notice-content"> <div class="ant-notification-notice-content"> <div [class.ant-notification-notice-with-icon]="instance.type !== 'blank'"> @switch (instance.type) { @case ('success') { <span nz-icon nzType="check-circle" class="ant-notification-notice-icon ant-notification-notice-icon-success" ></span> } @case ('info') { <span nz-icon nzType="info-circle" class="ant-notification-notice-icon ant-notification-notice-icon-info" ></span> } @case ('warning') { <span nz-icon nzType="exclamation-circle" class="ant-notification-notice-icon ant-notification-notice-icon-warning" ></span> } @case ('error') { <span nz-icon nzType="close-circle" class="ant-notification-notice-icon ant-notification-notice-icon-error" ></span> } } <div class="ant-notification-notice-message"> <ng-container *nzStringTemplateOutlet="instance.title"> <div [innerHTML]="instance.title"></div> </ng-container> </div> <div class="ant-notification-notice-description"> <ng-container *nzStringTemplateOutlet="instance.content"> <div [innerHTML]="instance.content"></div> </ng-container> </div> @if (instance.options?.nzButton; as btn) { <span class="ant-notification-notice-btn"> <ng-template [ngTemplateOutlet]="btn" [ngTemplateOutletContext]="{ $implicit: this }" /> </span> } </div> </div> </div> } <a tabindex="0" class="ant-notification-notice-close" (click)="close()"> <span class="ant-notification-notice-close-x"> @if (instance.options?.nzCloseIcon) { <ng-container *nzStringTemplateOutlet="instance.options?.nzCloseIcon; let closeIcon"> <span nz-icon [nzType]="closeIcon"></span> </ng-container> } @else { <span nz-icon nzType="close" class="ant-notification-close-icon"></span> } </span> </a> </div> `, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i1.NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { kind: "ngmodule", type: NzOutletModule }, { kind: "directive", type: i2.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], animations: [notificationMotion], encapsulation: i0.ViewEncapsulation.None }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationComponent, decorators: [{ type: Component, args: [{ encapsulation: ViewEncapsulation.None, selector: 'nz-notification', exportAs: 'nzNotification', preserveWhitespaces: false, animations: [notificationMotion], template: ` <div class="ant-notification-notice ant-notification-notice-closable" [ngStyle]="instance.options?.nzStyle || null" [ngClass]="instance.options?.nzClass || ''" [@notificationMotion]="state" (@notificationMotion.done)="animationStateChanged.next($event)" (click)="onClick($event)" (mouseenter)="onEnter()" (mouseleave)="onLeave()" > @if (instance.template) { <ng-template [ngTemplateOutlet]="instance.template!" [ngTemplateOutletContext]="{ $implicit: this, data: instance.options?.nzData }" /> } @else { <div class="ant-notification-notice-content"> <div class="ant-notification-notice-content"> <div [class.ant-notification-notice-with-icon]="instance.type !== 'blank'"> @switch (instance.type) { @case ('success') { <span nz-icon nzType="check-circle" class="ant-notification-notice-icon ant-notification-notice-icon-success" ></span> } @case ('info') { <span nz-icon nzType="info-circle" class="ant-notification-notice-icon ant-notification-notice-icon-info" ></span> } @case ('warning') { <span nz-icon nzType="exclamation-circle" class="ant-notification-notice-icon ant-notification-notice-icon-warning" ></span> } @case ('error') { <span nz-icon nzType="close-circle" class="ant-notification-notice-icon ant-notification-notice-icon-error" ></span> } } <div class="ant-notification-notice-message"> <ng-container *nzStringTemplateOutlet="instance.title"> <div [innerHTML]="instance.title"></div> </ng-container> </div> <div class="ant-notification-notice-description"> <ng-container *nzStringTemplateOutlet="instance.content"> <div [innerHTML]="instance.content"></div> </ng-container> </div> @if (instance.options?.nzButton; as btn) { <span class="ant-notification-notice-btn"> <ng-template [ngTemplateOutlet]="btn" [ngTemplateOutletContext]="{ $implicit: this }" /> </span> } </div> </div> </div> } <a tabindex="0" class="ant-notification-notice-close" (click)="close()"> <span class="ant-notification-notice-close-x"> @if (instance.options?.nzCloseIcon) { <ng-container *nzStringTemplateOutlet="instance.options?.nzCloseIcon; let closeIcon"> <span nz-icon [nzType]="closeIcon"></span> </ng-container> } @else { <span nz-icon nzType="close" class="ant-notification-close-icon"></span> } </span> </a> </div> `, imports: [NgStyle, NgClass, NzIconModule, NzOutletModule, NgTemplateOutlet], standalone: true }] }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { instance: [{ type: Input }], index: [{ type: Input }], placement: [{ type: Input }], destroyed: [{ type: Output }] } }); const NZ_CONFIG_MODULE_NAME = 'notification'; const NZ_NOTIFICATION_DEFAULT_CONFIG = { nzTop: '24px', nzBottom: '24px', nzPlacement: 'topRight', nzDuration: 4500, nzMaxStack: 8, nzPauseOnHover: true, nzAnimate: true, nzDirection: 'ltr' }; class NzNotificationContainerComponent extends NzMNContainerComponent { constructor(cdr, nzConfigService) { super(cdr, nzConfigService); this.dir = 'ltr'; this.instances = []; this.topLeftInstances = []; this.topRightInstances = []; this.bottomLeftInstances = []; this.bottomRightInstances = []; this.topInstances = []; this.bottomInstances = []; const config = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME); this.dir = config?.nzDirection || 'ltr'; } create(notification) { const noti = this.onCreate(notification); const key = noti.options.nzKey; const notificationWithSameKey = this.instances.find(msg => msg.options.nzKey === notification.options.nzKey); if (key && notificationWithSameKey) { this.replaceNotification(notificationWithSameKey, noti); } else { if (this.instances.length >= this.config.nzMaxStack) { this.instances = this.instances.slice(1); } this.instances = [...this.instances, noti]; } this.readyInstances(); return noti; } onCreate(instance) { instance.options = this.mergeOptions(instance.options); instance.onClose = new Subject(); instance.onClick = new Subject(); return instance; } subscribeConfigChange() { this.nzConfigService .getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME) .pipe(takeUntil(this.destroy$)) .subscribe(() => { this.updateConfig(); const config = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME); if (config) { const { nzDirection } = config; this.dir = nzDirection || this.dir; } }); } updateConfig() { this.config = { ...NZ_NOTIFICATION_DEFAULT_CONFIG, ...this.config, ...this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME) }; this.top = toCssPixel(this.config.nzTop); this.bottom = toCssPixel(this.config.nzBottom); this.cdr.markForCheck(); } replaceNotification(old, _new) { old.title = _new.title; old.content = _new.content; old.template = _new.template; old.type = _new.type; old.options = _new.options; } readyInstances() { const instancesMap = { topLeft: [], topRight: [], bottomLeft: [], bottomRight: [], top: [], bottom: [] }; this.instances.forEach(m => { const placement = m.options.nzPlacement; switch (placement) { case 'topLeft': instancesMap.topLeft.unshift(m); break; case 'topRight': instancesMap.topRight.unshift(m); break; case 'bottomLeft': instancesMap.bottomLeft.unshift(m); break; case 'bottomRight': instancesMap.bottomRight.unshift(m); break; case 'top': instancesMap.top.unshift(m); break; case 'bottom': instancesMap.bottom.unshift(m); break; default: instancesMap.topRight.unshift(m); } }); this.topLeftInstances = instancesMap.topLeft; this.topRightInstances = instancesMap.topRight; this.bottomLeftInstances = instancesMap.bottomLeft; this.bottomRightInstances = instancesMap.bottomRight; this.topInstances = instancesMap.top; this.bottomInstances = instancesMap.bottom; this.cdr.detectChanges(); } mergeOptions(options) { const { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement } = this.config; return { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement, ...options }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationContainerComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1$1.NzConfigService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.1.2", type: NzNotificationContainerComponent, isStandalone: true, selector: "nz-notification-container", exportAs: ["nzNotificationContainer"], usesInheritance: true, ngImport: i0, template: ` <div class="ant-notification ant-notification-topLeft" [class.ant-notification-rtl]="dir === 'rtl'" [style.top]="top" [style.left]="'0px'" > @for (instance of topLeftInstances; track instance) { <nz-notification [instance]="instance" [placement]="'topLeft'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-topRight" [class.ant-notification-rtl]="dir === 'rtl'" [style.top]="top" [style.right]="'0px'" > @for (instance of topRightInstances; track instance) { <nz-notification [instance]="instance" [placement]="'topRight'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-bottomLeft" [class.ant-notification-rtl]="dir === 'rtl'" [style.bottom]="bottom" [style.left]="'0px'" > @for (instance of bottomLeftInstances; track instance) { <nz-notification [instance]="instance" [placement]="'bottomLeft'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-bottomRight" [class.ant-notification-rtl]="dir === 'rtl'" [style.bottom]="bottom" [style.right]="'0px'" > @for (instance of bottomRightInstances; track instance) { <nz-notification [instance]="instance" [placement]="'bottomRight'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-top" [class.ant-notification-rtl]="dir === 'rtl'" [style.top]="top" [style.left]="'50%'" [style.transform]="'translateX(-50%)'" > @for (instance of topInstances; track instance) { <nz-notification [instance]="instance" [placement]="'top'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-bottom" [class.ant-notification-rtl]="dir === 'rtl'" [style.bottom]="bottom" [style.left]="'50%'" [style.transform]="'translateX(-50%)'" > @for (instance of bottomInstances; track instance) { <nz-notification [instance]="instance" [placement]="'bottom'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> `, isInline: true, dependencies: [{ kind: "component", type: NzNotificationComponent, selector: "nz-notification", inputs: ["instance", "index", "placement"], outputs: ["destroyed"], exportAs: ["nzNotification"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationContainerComponent, decorators: [{ type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-notification-container', exportAs: 'nzNotificationContainer', preserveWhitespaces: false, template: ` <div class="ant-notification ant-notification-topLeft" [class.ant-notification-rtl]="dir === 'rtl'" [style.top]="top" [style.left]="'0px'" > @for (instance of topLeftInstances; track instance) { <nz-notification [instance]="instance" [placement]="'topLeft'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-topRight" [class.ant-notification-rtl]="dir === 'rtl'" [style.top]="top" [style.right]="'0px'" > @for (instance of topRightInstances; track instance) { <nz-notification [instance]="instance" [placement]="'topRight'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-bottomLeft" [class.ant-notification-rtl]="dir === 'rtl'" [style.bottom]="bottom" [style.left]="'0px'" > @for (instance of bottomLeftInstances; track instance) { <nz-notification [instance]="instance" [placement]="'bottomLeft'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-bottomRight" [class.ant-notification-rtl]="dir === 'rtl'" [style.bottom]="bottom" [style.right]="'0px'" > @for (instance of bottomRightInstances; track instance) { <nz-notification [instance]="instance" [placement]="'bottomRight'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-top" [class.ant-notification-rtl]="dir === 'rtl'" [style.top]="top" [style.left]="'50%'" [style.transform]="'translateX(-50%)'" > @for (instance of topInstances; track instance) { <nz-notification [instance]="instance" [placement]="'top'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> <div class="ant-notification ant-notification-bottom" [class.ant-notification-rtl]="dir === 'rtl'" [style.bottom]="bottom" [style.left]="'50%'" [style.transform]="'translateX(-50%)'" > @for (instance of bottomInstances; track instance) { <nz-notification [instance]="instance" [placement]="'bottom'" (destroyed)="remove($event.id, $event.userAction)" /> } </div> `, imports: [NzNotificationComponent], standalone: true }] }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i1$1.NzConfigService }] }); /** * 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 NzNotificationModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationModule, imports: [NzNotificationComponent, NzNotificationContainerComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationModule, imports: [NzNotificationComponent, NzNotificationContainerComponent] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationModule, decorators: [{ type: NgModule, args: [{ imports: [NzNotificationComponent, NzNotificationContainerComponent] }] }] }); /** * 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 */ let notificationId = 0; class NzNotificationService extends NzMNService { constructor(nzSingletonService, overlay, injector) { super(nzSingletonService, overlay, injector); this.componentPrefix = 'notification-'; } success(title, content, options) { return this.create('success', title, content, options); } error(title, content, options) { return this.create('error', title, content, options); } info(title, content, options) { return this.create('info', title, content, options); } warning(title, content, options) { return this.create('warning', title, content, options); } blank(title, content, options) { return this.create('blank', title, content, options); } create(type, title, content, options) { return this.createInstance({ type, title, content }, options); } template(template, options) { return this.createInstance({ template }, options); } generateMessageId() { return `${this.componentPrefix}-${notificationId++}`; } createInstance(message, options) { this.container = this.withContainer(NzNotificationContainerComponent); return this.container.create({ ...message, ...{ createdAt: new Date(), messageId: options?.nzKey || this.generateMessageId(), options } }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationService, deps: [{ token: i1$2.NzSingletonService }, { token: i2$1.Overlay }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationService, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1$2.NzSingletonService }, { type: i2$1.Overlay }, { type: i0.Injector }] }); /** * 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 NzNotificationServiceModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationServiceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationServiceModule }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationServiceModule }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzNotificationServiceModule, decorators: [{ type: NgModule }] }); /** * 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 { NzNotificationComponent, NzNotificationContainerComponent, NzNotificationModule, NzNotificationService, NzNotificationServiceModule }; //# sourceMappingURL=ng-zorro-antd-notification.mjs.map