UNPKG

ng-zorro-antd

Version:

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

576 lines (569 loc) • 17 kB
import * as i0 from "@angular/core"; import { ANIMATION_MODULE_TYPE, ChangeDetectorRef, Component, DestroyRef, EventEmitter, Input, NgModule, Output, ViewEncapsulation, afterNextRender, booleanAttribute, computed, inject, input, numberAttribute, signal, viewChild } from "@angular/core"; import { __esDecorate, __runInitializers } from "tslib"; import { Directionality } from "@angular/cdk/bidi"; import { NzNoAnimationDirective } from "ng-zorro-antd/core/animation"; import { WithConfig, onConfigChangeEventForComponent } from "ng-zorro-antd/core/config"; 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"; var NzAlertMarqueeComponent = class NzAlertMarqueeComponent { destroyRef = inject(DestroyRef); nzPauseOnHover = input(false, { ...ngDevMode ? { debugName: "nzPauseOnHover" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzSpeed = input(50, { ...ngDevMode ? { debugName: "nzSpeed" } : /* istanbul ignore next */ {}, transform: numberAttribute }); track1Ref = viewChild.required("track1", ...ngDevMode ? [{ debugName: "track1Ref" }] : /* istanbul ignore next */ []); track2Ref = viewChild.required("track2", ...ngDevMode ? [{ debugName: "track2Ref" }] : /* istanbul ignore next */ []); trackWidth = signal(0, ...ngDevMode ? [{ debugName: "trackWidth" }] : /* istanbul ignore next */ []); animationDuration = computed(() => { const width = this.trackWidth(); const speed = this.nzSpeed(); return width > 0 && speed > 0 ? width / speed : 20; }, ...ngDevMode ? [{ debugName: "animationDuration" }] : /* istanbul ignore next */ []); class = computed(() => ({ "ant-alert-marquee": true, "ant-alert-marquee-pause-on-hover": this.nzPauseOnHover() }), ...ngDevMode ? [{ debugName: "class" }] : /* istanbul ignore next */ []); constructor() { afterNextRender(() => { const track1 = this.track1Ref().nativeElement; const track2 = this.track2Ref().nativeElement; const updateWidth = () => { this.trackWidth.set(track1.offsetWidth); }; Array.from(track1.childNodes).forEach((node) => { track2.appendChild(node.cloneNode(true)); }); updateWidth(); if (typeof ResizeObserver !== "undefined") { const resizeObserver = new ResizeObserver(updateWidth); resizeObserver.observe(track1); this.destroyRef.onDestroy(() => resizeObserver.disconnect()); } }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAlertMarqueeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.2", type: NzAlertMarqueeComponent, isStandalone: true, selector: "nz-alert-marquee", inputs: { nzPauseOnHover: { classPropertyName: "nzPauseOnHover", publicName: "nzPauseOnHover", isSignal: true, isRequired: false, transformFunction: null }, nzSpeed: { classPropertyName: "nzSpeed", publicName: "nzSpeed", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class": "class()" } }, viewQueries: [{ propertyName: "track1Ref", first: true, predicate: ["track1"], descendants: true, isSignal: true }, { propertyName: "track2Ref", first: true, predicate: ["track2"], descendants: true, isSignal: true }], ngImport: i0, template: ` <div #track1 class="ant-alert-marquee-track" [style.animation-duration.s]="animationDuration()"> <ng-content /> </div> <div #track2 class="ant-alert-marquee-track" aria-hidden="true" [style.animation-duration.s]="animationDuration()" ></div> `, isInline: true, encapsulation: i0.ViewEncapsulation.None }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAlertMarqueeComponent, decorators: [{ type: Component, args: [{ selector: "nz-alert-marquee", encapsulation: ViewEncapsulation.None, template: ` <div #track1 class="ant-alert-marquee-track" [style.animation-duration.s]="animationDuration()"> <ng-content /> </div> <div #track2 class="ant-alert-marquee-track" aria-hidden="true" [style.animation-duration.s]="animationDuration()" ></div> `, host: { "[class]": "class()" } }] }], ctorParameters: () => [], propDecorators: { nzPauseOnHover: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzPauseOnHover", required: false }] }], nzSpeed: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzSpeed", required: false }] }], track1Ref: [{ type: i0.ViewChild, args: ["track1", { isSignal: true }] }], track2Ref: [{ type: i0.ViewChild, args: ["track2", { isSignal: true }] }] } }); const NZ_CONFIG_MODULE_NAME = "alert"; let NzAlertComponent = (() => { let _nzCloseable_decorators; let _nzCloseable_initializers = []; let _nzCloseable_extraInitializers = []; let _nzShowIcon_decorators; let _nzShowIcon_initializers = []; let _nzShowIcon_extraInitializers = []; return class NzAlertComponent { static { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; _nzCloseable_decorators = [WithConfig()]; _nzShowIcon_decorators = [WithConfig()]; __esDecorate(null, null, _nzCloseable_decorators, { kind: "field", name: "nzCloseable", static: false, private: false, access: { has: (obj) => "nzCloseable" in obj, get: (obj) => obj.nzCloseable, set: (obj, value) => { obj.nzCloseable = value; } }, metadata: _metadata }, _nzCloseable_initializers, _nzCloseable_extraInitializers); __esDecorate(null, null, _nzShowIcon_decorators, { kind: "field", name: "nzShowIcon", static: false, private: false, access: { has: (obj) => "nzShowIcon" in obj, get: (obj) => obj.nzShowIcon, set: (obj, value) => { obj.nzShowIcon = value; } }, metadata: _metadata }, _nzShowIcon_initializers, _nzShowIcon_extraInitializers); if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); } cdr = inject(ChangeDetectorRef); animationType = inject(ANIMATION_MODULE_TYPE, { optional: true }); dir = inject(Directionality).valueSignal; _nzModuleName = NZ_CONFIG_MODULE_NAME; nzAction = null; nzCloseText = null; nzIconType = null; nzMessage = null; nzDescription = null; nzType = "info"; nzCloseable = __runInitializers(this, _nzCloseable_initializers, false); nzShowIcon = (__runInitializers(this, _nzCloseable_extraInitializers), __runInitializers(this, _nzShowIcon_initializers, false)); nzBanner = (__runInitializers(this, _nzShowIcon_extraInitializers), false); nzNoAnimation = false; nzIcon = null; nzOnClose = new EventEmitter(); closed = false; iconTheme = "fill"; inferredIconType = "info-circle"; isTypeSet = false; isShowIconSet = false; constructor() { onConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME, () => this.cdr.markForCheck()); } closeAlert() { this.closed = true; if (this.nzNoAnimation || this.animationType === "NoopAnimations") this.nzOnClose.emit(true); } onLeaveAnimationDone(event) { const element = event.target; if (this.nzNoAnimation || this.animationType === "NoopAnimations") { event.animationComplete(); return; } element.classList.add("ant-alert-motion-leave", "ant-alert-motion-leave-active"); const onTransitionEnd = () => { element.removeEventListener("transitionend", onTransitionEnd); this.nzOnClose.emit(true); event.animationComplete(); }; element.addEventListener("transitionend", onTransitionEnd); } 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"; } } if (nzDescription) this.iconTheme = this.nzDescription ? "outline" : "fill"; if (nzBanner) { if (!this.isTypeSet) this.nzType = "warning"; if (!this.isShowIconSet) this.nzShowIcon = true; } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAlertComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.2", type: NzAlertComponent, isStandalone: true, selector: "nz-alert", inputs: { nzAction: "nzAction", nzCloseText: "nzCloseText", nzIconType: "nzIconType", nzMessage: "nzMessage", nzDescription: "nzDescription", nzType: "nzType", nzCloseable: [ "nzCloseable", "nzCloseable", booleanAttribute ], nzShowIcon: [ "nzShowIcon", "nzShowIcon", booleanAttribute ], nzBanner: [ "nzBanner", "nzBanner", booleanAttribute ], nzNoAnimation: [ "nzNoAnimation", "nzNoAnimation", booleanAttribute ], nzIcon: "nzIcon" }, outputs: { nzOnClose: "nzOnClose" }, exportAs: ["nzAlert"], usesOnChanges: true, ngImport: i0, template: ` @if (!closed) { <div class="ant-alert" [nzNoAnimation]="nzNoAnimation" [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" (animate.leave)="onLeaveAnimationDone($event)" > @if (nzShowIcon) { <div class="ant-alert-icon"> @if (nzIcon) { <ng-container *nzStringTemplateOutlet="nzIcon" /> } @else { <nz-icon [nzType]="nzIconType || inferredIconType" [nzTheme]="iconTheme" /> } </div> } @if (nzMessage || nzDescription) { <div class="ant-alert-content"> @if (nzMessage) { <span class="ant-alert-message"> <ng-container *nzStringTemplateOutlet="nzMessage">{{ nzMessage }}</ng-container> </span> } @if (nzDescription) { <span class="ant-alert-description"> <ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container> </span> } </div> } @if (nzAction) { <div class="ant-alert-action"> <ng-container *nzStringTemplateOutlet="nzAction">{{ nzAction }}</ng-container> </div> } @if (nzCloseable || nzCloseText) { <button type="button" tabindex="0" class="ant-alert-close-icon" (click)="closeAlert()"> @if (nzCloseText) { <ng-container *nzStringTemplateOutlet="nzCloseText"> <span class="ant-alert-close-text">{{ nzCloseText }}</span> </ng-container> } @else { <nz-icon nzType="close" /> } </button> } </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: NzNoAnimationDirective, selector: "[nzNoAnimation]", inputs: ["nzNoAnimation"], exportAs: ["nzNoAnimation"] } ], encapsulation: i0.ViewEncapsulation.None }); }; })(); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAlertComponent, decorators: [{ type: Component, args: [{ selector: "nz-alert", exportAs: "nzAlert", imports: [ NzIconModule, NzOutletModule, NzNoAnimationDirective ], template: ` @if (!closed) { <div class="ant-alert" [nzNoAnimation]="nzNoAnimation" [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" (animate.leave)="onLeaveAnimationDone($event)" > @if (nzShowIcon) { <div class="ant-alert-icon"> @if (nzIcon) { <ng-container *nzStringTemplateOutlet="nzIcon" /> } @else { <nz-icon [nzType]="nzIconType || inferredIconType" [nzTheme]="iconTheme" /> } </div> } @if (nzMessage || nzDescription) { <div class="ant-alert-content"> @if (nzMessage) { <span class="ant-alert-message"> <ng-container *nzStringTemplateOutlet="nzMessage">{{ nzMessage }}</ng-container> </span> } @if (nzDescription) { <span class="ant-alert-description"> <ng-container *nzStringTemplateOutlet="nzDescription">{{ nzDescription }}</ng-container> </span> } </div> } @if (nzAction) { <div class="ant-alert-action"> <ng-container *nzStringTemplateOutlet="nzAction">{{ nzAction }}</ng-container> </div> } @if (nzCloseable || nzCloseText) { <button type="button" tabindex="0" class="ant-alert-close-icon" (click)="closeAlert()"> @if (nzCloseText) { <ng-container *nzStringTemplateOutlet="nzCloseText"> <span class="ant-alert-close-text">{{ nzCloseText }}</span> </ng-container> } @else { <nz-icon nzType="close" /> } </button> } </div> } `, encapsulation: ViewEncapsulation.None }] }], ctorParameters: () => [], propDecorators: { nzAction: [{ type: Input }], nzCloseText: [{ type: Input }], nzIconType: [{ type: Input }], nzMessage: [{ type: Input }], nzDescription: [{ type: Input }], nzType: [{ type: Input }], nzCloseable: [{ type: Input, args: [{ transform: booleanAttribute }] }], nzShowIcon: [{ type: Input, args: [{ transform: booleanAttribute }] }], nzBanner: [{ type: Input, args: [{ transform: booleanAttribute }] }], nzNoAnimation: [{ type: Input, args: [{ transform: booleanAttribute }] }], nzIcon: [{ type: Input }], nzOnClose: [{ type: Output }] } }); var NzAlertModule = class NzAlertModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAlertModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzAlertModule, imports: [NzAlertComponent, NzAlertMarqueeComponent], exports: [NzAlertComponent, NzAlertMarqueeComponent] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAlertModule, imports: [NzAlertComponent] }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAlertModule, decorators: [{ type: NgModule, args: [{ exports: [NzAlertComponent, NzAlertMarqueeComponent], imports: [NzAlertComponent, NzAlertMarqueeComponent] }] }] }); export { NzAlertComponent, NzAlertMarqueeComponent, NzAlertModule }; //# sourceMappingURL=ng-zorro-antd-alert.mjs.map