ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
500 lines (491 loc) • 23.4 kB
JavaScript
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 { NzMNComponent, NzMNContainerComponent, NzMNService } from 'ng-zorro-antd/message';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from 'ng-zorro-antd/icon';
import { NzIconModule } from 'ng-zorro-antd/icon';
import * as i3 from 'ng-zorro-antd/core/outlet';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { BidiModule } from '@angular/cdk/bidi';
import * as i2$1 from '@angular/cdk/overlay';
import { OverlayModule } from '@angular/cdk/overlay';
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';
/**
* 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') {
if (this.placement === 'topLeft' || this.placement === 'bottomLeft') {
return 'enterLeft';
}
else {
return 'enterRight';
}
}
else {
return this.instance.state;
}
}
}
NzNotificationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
NzNotificationComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzNotificationComponent, 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 || ''"
[ ]="state"
( .done)="animationStateChanged.next($event)"
(click)="onClick($event)"
(mouseenter)="onEnter()"
(mouseleave)="onLeave()"
>
<div *ngIf="!instance.template" class="ant-notification-notice-content">
<div
class="ant-notification-notice-content"
[ngClass]="{ 'ant-notification-notice-with-icon': instance.type !== 'blank' }"
>
<div [class.ant-notification-notice-with-icon]="instance.type !== 'blank'">
<ng-container [ngSwitch]="instance.type">
<i
*ngSwitchCase="'success'"
nz-icon
nzType="check-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-success"
></i>
<i
*ngSwitchCase="'info'"
nz-icon
nzType="info-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-info"
></i>
<i
*ngSwitchCase="'warning'"
nz-icon
nzType="exclamation-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-warning"
></i>
<i
*ngSwitchCase="'error'"
nz-icon
nzType="close-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-error"
></i>
</ng-container>
<div class="ant-notification-notice-message" [innerHTML]="instance.title"></div>
<div class="ant-notification-notice-description" [innerHTML]="instance.content"></div>
</div>
</div>
</div>
<ng-template
[ngIf]="instance.template"
[ngTemplateOutlet]="instance.template!"
[ngTemplateOutletContext]="{ $implicit: this, data: instance.options?.nzData }"
></ng-template>
<a tabindex="0" class="ant-notification-notice-close" (click)="close()">
<span class="ant-notification-notice-close-x">
<ng-container *ngIf="instance.options?.nzCloseIcon; else iconTpl">
<ng-container *nzStringTemplateOutlet="instance.options?.nzCloseIcon; let closeIcon">
<i nz-icon [nzType]="closeIcon"></i>
</ng-container>
</ng-container>
<ng-template #iconTpl>
<i nz-icon nzType="close" class="ant-notification-close-icon"></i>
</ng-template>
</span>
</a>
</div>
`, isInline: true, directives: [{ type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { type: i2.NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }, { type: i3.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }], animations: [notificationMotion], encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", 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 || ''"
[ ]="state"
( .done)="animationStateChanged.next($event)"
(click)="onClick($event)"
(mouseenter)="onEnter()"
(mouseleave)="onLeave()"
>
<div *ngIf="!instance.template" class="ant-notification-notice-content">
<div
class="ant-notification-notice-content"
[ngClass]="{ 'ant-notification-notice-with-icon': instance.type !== 'blank' }"
>
<div [class.ant-notification-notice-with-icon]="instance.type !== 'blank'">
<ng-container [ngSwitch]="instance.type">
<i
*ngSwitchCase="'success'"
nz-icon
nzType="check-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-success"
></i>
<i
*ngSwitchCase="'info'"
nz-icon
nzType="info-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-info"
></i>
<i
*ngSwitchCase="'warning'"
nz-icon
nzType="exclamation-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-warning"
></i>
<i
*ngSwitchCase="'error'"
nz-icon
nzType="close-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-error"
></i>
</ng-container>
<div class="ant-notification-notice-message" [innerHTML]="instance.title"></div>
<div class="ant-notification-notice-description" [innerHTML]="instance.content"></div>
</div>
</div>
</div>
<ng-template
[ngIf]="instance.template"
[ngTemplateOutlet]="instance.template!"
[ngTemplateOutletContext]="{ $implicit: this, data: instance.options?.nzData }"
></ng-template>
<a tabindex="0" class="ant-notification-notice-close" (click)="close()">
<span class="ant-notification-notice-close-x">
<ng-container *ngIf="instance.options?.nzCloseIcon; else iconTpl">
<ng-container *nzStringTemplateOutlet="instance.options?.nzCloseIcon; let closeIcon">
<i nz-icon [nzType]="closeIcon"></i>
</ng-container>
</ng-container>
<ng-template #iconTpl>
<i nz-icon nzType="close" class="ant-notification-close-icon"></i>
</ng-template>
</span>
</a>
</div>
`
}]
}], ctorParameters: function () { return [{ 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: 7,
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 = [];
const config = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME);
this.dir = (config === null || config === void 0 ? void 0 : 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 = Object.assign(Object.assign(Object.assign({}, 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() {
this.topLeftInstances = this.instances.filter(m => m.options.nzPlacement === 'topLeft');
this.topRightInstances = this.instances.filter(m => m.options.nzPlacement === 'topRight' || !m.options.nzPlacement);
this.bottomLeftInstances = this.instances.filter(m => m.options.nzPlacement === 'bottomLeft');
this.bottomRightInstances = this.instances.filter(m => m.options.nzPlacement === 'bottomRight');
this.cdr.detectChanges();
}
mergeOptions(options) {
const { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement } = this.config;
return Object.assign({ nzDuration, nzAnimate, nzPauseOnHover, nzPlacement }, options);
}
}
NzNotificationContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationContainerComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1$1.NzConfigService }], target: i0.ɵɵFactoryTarget.Component });
NzNotificationContainerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzNotificationContainerComponent, 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'"
>
<nz-notification
*ngFor="let instance of topLeftInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
<div
class="ant-notification ant-notification-topRight"
[class.ant-notification-rtl]="dir === 'rtl'"
[style.top]="top"
[style.right]="'0px'"
>
<nz-notification
*ngFor="let instance of topRightInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
<div
class="ant-notification ant-notification-bottomLeft"
[class.ant-notification-rtl]="dir === 'rtl'"
[style.bottom]="bottom"
[style.left]="'0px'"
>
<nz-notification
*ngFor="let instance of bottomLeftInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
<div
class="ant-notification ant-notification-bottomRight"
[class.ant-notification-rtl]="dir === 'rtl'"
[style.bottom]="bottom"
[style.right]="'0px'"
>
<nz-notification
*ngFor="let instance of bottomRightInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
`, isInline: true, components: [{ type: NzNotificationComponent, selector: "nz-notification", inputs: ["instance", "index", "placement"], outputs: ["destroyed"], exportAs: ["nzNotification"] }], directives: [{ type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", 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'"
>
<nz-notification
*ngFor="let instance of topLeftInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
<div
class="ant-notification ant-notification-topRight"
[class.ant-notification-rtl]="dir === 'rtl'"
[style.top]="top"
[style.right]="'0px'"
>
<nz-notification
*ngFor="let instance of topRightInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
<div
class="ant-notification ant-notification-bottomLeft"
[class.ant-notification-rtl]="dir === 'rtl'"
[style.bottom]="bottom"
[style.left]="'0px'"
>
<nz-notification
*ngFor="let instance of bottomLeftInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
<div
class="ant-notification ant-notification-bottomRight"
[class.ant-notification-rtl]="dir === 'rtl'"
[style.bottom]="bottom"
[style.right]="'0px'"
>
<nz-notification
*ngFor="let instance of bottomRightInstances"
[instance]="instance"
[placement]="config.nzPlacement"
(destroyed)="remove($event.id, $event.userAction)"
></nz-notification>
</div>
`
}]
}], ctorParameters: function () { return [{ 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 NzNotificationServiceModule {
}
NzNotificationServiceModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationServiceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NzNotificationServiceModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationServiceModule });
NzNotificationServiceModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationServiceModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", 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
*/
class NzNotificationModule {
}
NzNotificationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NzNotificationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationModule, declarations: [NzNotificationComponent, NzNotificationContainerComponent], imports: [BidiModule, CommonModule, OverlayModule, NzIconModule, NzOutletModule, NzNotificationServiceModule] });
NzNotificationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationModule, imports: [[BidiModule, CommonModule, OverlayModule, NzIconModule, NzOutletModule, NzNotificationServiceModule]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationModule, decorators: [{
type: NgModule,
args: [{
imports: [BidiModule, CommonModule, OverlayModule, NzIconModule, NzOutletModule, NzNotificationServiceModule],
declarations: [NzNotificationComponent, NzNotificationContainerComponent],
entryComponents: [NzNotificationContainerComponent]
}]
}] });
let notificationId = 0;
class NzNotificationService extends NzMNService {
constructor(nzSingletonService, overlay, injector) {
super(nzSingletonService, overlay, injector);
this.componentPrefix = 'notification-';
}
success(title, content, options) {
return this.createInstance({ type: 'success', title, content }, options);
}
error(title, content, options) {
return this.createInstance({ type: 'error', title, content }, options);
}
info(title, content, options) {
return this.createInstance({ type: 'info', title, content }, options);
}
warning(title, content, options) {
return this.createInstance({ type: 'warning', title, content }, options);
}
blank(title, content, options) {
return this.createInstance({ type: '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(Object.assign(Object.assign({}, message), {
createdAt: new Date(),
messageId: this.generateMessageId(),
options
}));
}
}
NzNotificationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationService, deps: [{ token: i1$2.NzSingletonService }, { token: i2$1.Overlay }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
NzNotificationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationService, providedIn: NzNotificationServiceModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzNotificationService, decorators: [{
type: Injectable,
args: [{
providedIn: NzNotificationServiceModule
}]
}], ctorParameters: function () { return [{ 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
*/
/**
* Generated bundle index. Do not edit.
*/
export { NzNotificationComponent, NzNotificationContainerComponent, NzNotificationModule, NzNotificationService, NzNotificationServiceModule };
//# sourceMappingURL=ng-zorro-antd-notification.mjs.map