UNPKG

ng-zorro-antd

Version:

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

646 lines (636 loc) 26.3 kB
import { NgTemplateOutlet } from '@angular/common'; import * as i0 from '@angular/core'; import { EventEmitter, Output, Input, ViewEncapsulation, Component, 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 '@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 { instance; index; placement; 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 ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.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" [style]="instance.options?.nzStyle || null" [class]="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') { <nz-icon nzType="check-circle" class="ant-notification-notice-icon ant-notification-notice-icon-success" /> } @case ('info') { <nz-icon nzType="info-circle" class="ant-notification-notice-icon ant-notification-notice-icon-info" /> } @case ('warning') { <nz-icon nzType="exclamation-circle" class="ant-notification-notice-icon ant-notification-notice-icon-warning" /> } @case ('error') { <nz-icon nzType="close-circle" class="ant-notification-notice-icon ant-notification-notice-icon-error" /> } } <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; context: { $implicit: this, data: instance.options?.nzData } " > <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"> <nz-icon [nzType]="closeIcon" /> </ng-container> } @else { <nz-icon nzType="close" class="ant-notification-close-icon" /> } </span> </a> </div> `, isInline: true, dependencies: [{ kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i1.NzIconDirective, selector: "nz-icon,[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: "19.2.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" [style]="instance.options?.nzStyle || null" [class]="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') { <nz-icon nzType="check-circle" class="ant-notification-notice-icon ant-notification-notice-icon-success" /> } @case ('info') { <nz-icon nzType="info-circle" class="ant-notification-notice-icon ant-notification-notice-icon-info" /> } @case ('warning') { <nz-icon nzType="exclamation-circle" class="ant-notification-notice-icon ant-notification-notice-icon-warning" /> } @case ('error') { <nz-icon nzType="close-circle" class="ant-notification-notice-icon ant-notification-notice-icon-error" /> } } <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; context: { $implicit: this, data: instance.options?.nzData } " > <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"> <nz-icon [nzType]="closeIcon" /> </ng-container> } @else { <nz-icon nzType="close" class="ant-notification-close-icon" /> } </span> </a> </div> `, imports: [NzIconModule, NzOutletModule, NgTemplateOutlet] }] }], 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 { dir = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME)?.nzDirection || 'ltr'; bottom; top; topLeftInstances = []; topRightInstances = []; bottomLeftInstances = []; bottomRightInstances = []; topInstances = []; bottomInstances = []; constructor() { super(); this.updateConfig(); } create(notification) { const instance = this.onCreate(notification); const key = instance.options.nzKey; const notificationWithSameKey = this.instances.find(msg => msg.options.nzKey === notification.options.nzKey); if (key && notificationWithSameKey) { this.replaceNotification(notificationWithSameKey, instance); } else { if (this.instances.length >= this.config.nzMaxStack) { this.instances = this.instances.slice(1); } this.instances = [...this.instances, instance]; } this.readyInstances(); return instance; } 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(); this.dir = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME)?.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 ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.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: "19.2.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] }] }], ctorParameters: () => [] }); /** * 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 */ /** * @deprecated This module is no longer needed, will be removed in v20, please remove its import. */ class NzNotificationModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationModule, imports: [NzNotificationComponent, NzNotificationContainerComponent] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationModule, imports: [NzNotificationComponent, NzNotificationContainerComponent] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.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 { componentPrefix = 'notification-'; constructor(overlay, injector) { super(overlay, injector); } 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 ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationService, deps: [{ token: i1$1.Overlay }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationService, providedIn: 'root' }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1$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 */ /** * @deprecated This module is no longer needed, will be removed in v20, please remove its import. */ class NzNotificationServiceModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationServiceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationServiceModule }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzNotificationServiceModule }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.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