ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
705 lines (704 loc) • 21.6 kB
JavaScript
import { NgTemplateOutlet } from "@angular/common";
import * as i0 from "@angular/core";
import { Component, ElementRef, EventEmitter, Injectable, Input, Output, ViewEncapsulation, viewChild } from "@angular/core";
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 { onConfigChangeEventForComponent } from "ng-zorro-antd/core/config";
import { toCssPixel } from "ng-zorro-antd/core/util";
var NzNotificationComponent = class NzNotificationComponent extends NzMNComponent {
instance;
index;
placement;
destroyed = new EventEmitter();
animationElement = viewChild.required("animationElement", {
...ngDevMode ? { debugName: "animationElement" } : /* istanbul ignore next */ {},
read: ElementRef
});
_animationKeyframeMap = {
enter: [
"antNotificationFadeIn",
"antNotificationTopFadeIn",
"antNotificationBottomFadeIn",
"antNotificationLeftFadeIn"
],
leave: "antNotificationFadeOut"
};
_animationClassMap = {
enter: "ant-notification-fade-enter",
leave: "ant-notification-fade-leave"
};
constructor() {
super();
this.destroyRef.onDestroy(() => {
this.instance.onClick.complete();
});
}
onClick(event) {
this.instance.onClick.next(event);
}
close() {
this.destroy(true);
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzNotificationComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "17.0.0",
version: "22.2.2",
type: NzNotificationComponent,
isStandalone: true,
selector: "nz-notification",
inputs: {
instance: "instance",
index: "index",
placement: "placement"
},
outputs: { destroyed: "destroyed" },
viewQueries: [{
propertyName: "animationElement",
first: true,
predicate: ["animationElement"],
descendants: true,
read: ElementRef,
isSignal: true
}],
exportAs: ["nzNotification"],
usesInheritance: true,
ngImport: i0,
template: `
<div
#animationElement
class="ant-notification-notice ant-notification-notice-closable"
[style]="instance.options?.nzStyle || null"
[class]="instance.options?.nzClass || ''"
(click)="onClick($event)"
(mouseenter)="onEnter()"
(mouseleave)="onLeave()"
>
(instance.template) {
<ng-template
[ngTemplateOutlet]="instance.template!"
[ngTemplateOutletContext]="{ $implicit: this, data: instance.options?.nzData }"
/>
} {
<div class="ant-notification-notice-content">
<div class="ant-notification-notice-content">
<div [class.ant-notification-notice-with-icon]="instance.type !== 'blank'">
(instance.type) {
('success') {
<nz-icon
nzType="check-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-success"
/>
}
('info') {
<nz-icon
nzType="info-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-info"
/>
}
('warning') {
<nz-icon
nzType="exclamation-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-warning"
/>
}
('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>
(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">
(instance.options?.nzCloseIcon) {
<ng-container *nzStringTemplateOutlet="instance.options?.nzCloseIcon; let closeIcon">
<nz-icon [nzType]="closeIcon" />
</ng-container>
} {
<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: [
"nzType",
"nzTheme",
"nzTwotoneColor",
"nzSpin",
"nzRotate",
"nzIconfont",
"aria-label"
],
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"
]
}
],
encapsulation: i0.ViewEncapsulation.None
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzNotificationComponent,
decorators: [{
type: Component,
args: [{
selector: "nz-notification",
exportAs: "nzNotification",
imports: [
NzIconModule,
NzOutletModule,
NgTemplateOutlet
],
template: `
<div
#animationElement
class="ant-notification-notice ant-notification-notice-closable"
[style]="instance.options?.nzStyle || null"
[class]="instance.options?.nzClass || ''"
(click)="onClick($event)"
(mouseenter)="onEnter()"
(mouseleave)="onLeave()"
>
(instance.template) {
<ng-template
[ngTemplateOutlet]="instance.template!"
[ngTemplateOutletContext]="{ $implicit: this, data: instance.options?.nzData }"
/>
} {
<div class="ant-notification-notice-content">
<div class="ant-notification-notice-content">
<div [class.ant-notification-notice-with-icon]="instance.type !== 'blank'">
(instance.type) {
('success') {
<nz-icon
nzType="check-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-success"
/>
}
('info') {
<nz-icon
nzType="info-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-info"
/>
}
('warning') {
<nz-icon
nzType="exclamation-circle"
class="ant-notification-notice-icon ant-notification-notice-icon-warning"
/>
}
('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>
(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">
(instance.options?.nzCloseIcon) {
<ng-container *nzStringTemplateOutlet="instance.options?.nzCloseIcon; let closeIcon">
<nz-icon [nzType]="closeIcon" />
</ng-container>
} {
<nz-icon nzType="close" class="ant-notification-close-icon" />
}
</span>
</a>
</div>
`,
encapsulation: ViewEncapsulation.None
}]
}],
ctorParameters: () => [],
propDecorators: {
instance: [{ type: Input }],
index: [{ type: Input }],
placement: [{ type: Input }],
destroyed: [{ type: Output }],
animationElement: [{
type: i0.ViewChild,
args: ["animationElement", {
read: ElementRef,
isSignal: true
}]
}]
}
});
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"
};
var NzNotificationContainerComponent = 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() {
onConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME, () => {
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) => {
switch (m.options.nzPlacement) {
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: "22.2.2",
ngImport: i0,
type: NzNotificationContainerComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "17.0.0",
version: "22.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'"
>
(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'"
>
(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'"
>
(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'"
>
(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%)'"
>
(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%)'"
>
(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"]
}],
encapsulation: i0.ViewEncapsulation.None
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzNotificationContainerComponent,
decorators: [{
type: Component,
args: [{
selector: "nz-notification-container",
exportAs: "nzNotificationContainer",
encapsulation: ViewEncapsulation.None,
template: `
<div
class="ant-notification ant-notification-topLeft"
[class.ant-notification-rtl]="dir === 'rtl'"
[style.top]="top"
[style.left]="'0px'"
>
(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'"
>
(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'"
>
(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'"
>
(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%)'"
>
(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%)'"
>
(instance of bottomInstances; track instance) {
<nz-notification [instance]="instance" placement="bottom" (destroyed)="remove($event.id, $event.userAction)" />
}
</div>
`,
imports: [NzNotificationComponent]
}]
}],
ctorParameters: () => []
});
let notificationId = 0;
var NzNotificationService = class NzNotificationService extends NzMNService {
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: /* @__PURE__ */ new Date(),
messageId: options?.nzKey || this.generateMessageId(),
options
});
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzNotificationService,
deps: null,
target: i0.ɵɵFactoryTarget.Injectable
});
static ɵprov = i0.ɵɵngDeclareInjectable({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzNotificationService,
providedIn: "root"
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzNotificationService,
decorators: [{
type: Injectable,
args: [{ providedIn: "root" }]
}]
});
export { NzNotificationComponent, NzNotificationContainerComponent, NzNotificationService };
//# sourceMappingURL=ng-zorro-antd-notification.mjs.map