ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
573 lines • 21 kB
TypeScript
import { Direction } from "@angular/cdk/bidi";
import * as i0 from "@angular/core";
import { ChangeDetectorRef, ComponentRef, DestroyRef, ElementRef, EmbeddedViewRef, EventEmitter, InjectionToken, NgZone, OnChanges, OnDestroy, OnInit, Renderer2, SimpleChanges, TemplateRef, Type, ViewContainerRef } from "@angular/core";
import { NzButtonShape, NzButtonSize, NzButtonType } from "ng-zorro-antd/button";
import { NzSafeAny } from "ng-zorro-antd/core/types";
import { Observable, ReplaySubject, Subject } from "rxjs";
import * as i1 from "@angular/cdk/overlay";
import { OverlayRef } from "@angular/cdk/overlay";
import { FocusTrapFactory } from "@angular/cdk/a11y";
import { BasePortalOutlet, CdkPortalOutlet, ComponentPortal, TemplatePortal } from "@angular/cdk/portal";
import { NzConfigService } from "ng-zorro-antd/core/config";
import { CdkDragEnd } from "@angular/cdk/drag-drop";
export type OnClickCallback<T> = (instance: T) => (false | void | {}) | Promise<false | void | {}>;
export type ModalTypes = 'default' | 'confirm';
export type ConfirmType = 'confirm' | 'info' | 'success' | 'error' | 'warning';
export interface StyleObjectLike {
[key: string]: string;
}
export declare class ModalOptions<T = NzSafeAny, D = NzSafeAny, R = NzSafeAny> {
nzCentered?: boolean;
nzClosable?: boolean;
nzOkLoading?: boolean;
nzOkDisabled?: boolean;
nzCancelDisabled?: boolean;
nzCancelLoading?: boolean;
nzDraggable?: boolean;
nzNoAnimation?: boolean;
nzAutofocus?: 'ok' | 'cancel' | 'auto' | null;
nzMask?: boolean;
nzMaskClosable?: boolean;
nzKeyboard?: boolean;
nzZIndex?: number;
nzWidth?: number | string;
nzCloseIcon?: string | TemplateRef<void>;
nzOkType?: NzButtonType;
nzOkDanger?: boolean;
nzModalType?: ModalTypes;
nzOnCancel?: EventEmitter<T> | OnClickCallback<T>;
nzOnOk?: EventEmitter<T> | OnClickCallback<T>;
nzData?: D;
nzMaskStyle?: StyleObjectLike;
nzBodyStyle?: StyleObjectLike;
nzWrapClassName?: string;
nzClassName?: string;
nzStyle?: object;
nzTitle?: string | TemplateRef<{}>;
nzFooter?: string | TemplateRef<{}> | Array<ModalButtonOptions<T>> | null;
nzCancelText?: string | null;
nzOkText?: string | null;
nzContent?: string | TemplateRef<NzSafeAny> | Type<T>;
nzCloseOnNavigation?: boolean;
nzViewContainerRef?: ViewContainerRef;
nzAfterOpen?: EventEmitter<void>;
nzAfterClose?: EventEmitter<R>;
nzIconType?: string;
nzDirection?: Direction;
}
export interface ModalButtonOptions<T = NzSafeAny> {
label: string;
type?: NzButtonType;
danger?: boolean;
shape?: NzButtonShape;
ghost?: boolean;
size?: NzButtonSize;
autoLoading?: boolean;
show?: boolean | ((this: ModalButtonOptions<T>, contentComponentInstance?: T) => boolean);
loading?: boolean | ((this: ModalButtonOptions<T>, contentComponentInstance?: T) => boolean);
disabled?: boolean | ((this: ModalButtonOptions<T>, contentComponentInstance?: T) => boolean);
onClick?(this: ModalButtonOptions<T>, contentComponentInstance?: T): NzSafeAny | Promise<NzSafeAny>;
[key: string]: NzSafeAny;
}
export declare function throwNzModalContentAlreadyAttachedError(): never;
type AnimationState = 'enter-start' | 'enter-active' | 'leave-start' | 'leave-active' | 'void';
export declare class BaseModalContainerComponent extends BasePortalOutlet {
readonly document: Document;
readonly cdr: ChangeDetectorRef;
readonly config: ModalOptions<any, any, any>;
protected readonly ngZone: NgZone;
protected readonly host: ElementRef<HTMLElement>;
protected readonly focusTrapFactory: FocusTrapFactory;
protected readonly renderer: Renderer2;
protected readonly overlayRef: OverlayRef;
protected readonly nzConfigService: NzConfigService;
protected readonly animationType: "BrowserAnimations" | "NoopAnimations" | null;
protected readonly destroyRef: DestroyRef;
portalOutlet: CdkPortalOutlet;
modalElementRef: ElementRef<HTMLDivElement>;
animationStateChanged: EventEmitter<AnimationState>;
containerClick: EventEmitter<void>;
cancelTriggered: EventEmitter<void>;
okTriggered: EventEmitter<void>;
modalRef: NzModalRef;
isStringContent: boolean;
dir: Direction;
private elementFocusedBeforeModalWasOpened;
private focusTrap;
private mouseDown;
private oldMaskStyle;
get showMask(): boolean;
get maskClosable(): boolean;
constructor();
onContainerClick(e: MouseEvent): void;
onCloseClick(): void;
onOkClick(): void;
markForCheck(): void;
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T>;
attachTemplatePortal<C>(portal: TemplatePortal<C>): EmbeddedViewRef<C>;
attachStringContent(): void;
getNativeElement(): HTMLElement;
private animationDisabled;
private setModalTransformOrigin;
private savePreviouslyFocusedElement;
private trapFocus;
private restoreFocus;
/**
* `animationend` never fires for an animation the browser does not start
*/
private isAnimating;
private setEnterInitialClass;
private setEnterActiveClass;
private setExitAnimationClass;
private setMaskExitAnimationClass;
private cleanAnimationClass;
private setZIndexForBackdrop;
bindBackdropStyle(): void;
updateMaskClassname(): void;
_startEnterAnimation(): void;
_startLeaveAnimation(backdropElement: HTMLElement | null): void;
protected setupMouseListeners(modalContainer: ElementRef<HTMLElement>): void;
static ɵfac: i0.ɵɵFactoryDeclaration<BaseModalContainerComponent, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<BaseModalContainerComponent, never, never, {}, {}, never, never, true, never>;
}
export declare abstract class NzModalLegacyAPI<T, R> {
abstract afterOpen: Observable<void>;
abstract afterClose: Observable<R | undefined>;
abstract close(result?: R): void;
abstract destroy(result?: R): void;
/**
* Trigger the nzOnOk/nzOnCancel by manual
*/
abstract triggerOk(): void;
abstract triggerCancel(): void;
/**
* Return the component instance of nzContent when specify nzContent as a Component
*/
abstract getContentComponent(): T | void;
/**
* Get the dom element of this Modal
*/
abstract getElement(): HTMLElement | void;
}
export declare const NzModalState: {
readonly OPEN: 0;
readonly CLOSING: 1;
readonly CLOSED: 2;
};
export type NzModalState = (typeof NzModalState)[keyof typeof NzModalState];
export declare const NzTriggerAction: {
readonly CANCEL: "cancel";
readonly OK: "ok";
};
export type NzTriggerAction = (typeof NzTriggerAction)[keyof typeof NzTriggerAction];
export declare class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAPI<T, R> {
private overlayRef;
private config;
containerInstance: BaseModalContainerComponent;
componentInstance: T | null;
componentRef: ComponentRef<T> | null;
result?: R;
state: NzModalState;
afterClose: Subject<R | undefined>;
/**
* Without animation the modal opens synchronously, before callers can subscribe
* to the returned ref, so the event must be replayed.
*/
afterOpen: ReplaySubject<void>;
private destroy$;
constructor(overlayRef: OverlayRef, config: ModalOptions, containerInstance: BaseModalContainerComponent);
getContentComponent(): T;
getContentComponentRef(): Readonly<ComponentRef<T> | null>;
getElement(): HTMLElement;
destroy(result?: R): void;
triggerOk(): Promise<void>;
triggerCancel(): Promise<void>;
close(result?: R): void;
updateConfig(config: ModalOptions): void;
getState(): NzModalState;
getConfig(): ModalOptions;
getBackdropElement(): HTMLElement | null;
private trigger;
private closeWhitResult;
_finishDialogClose(): void;
}
export declare class NzModalService implements OnDestroy {
private readonly injector;
private readonly nzConfigService;
private readonly directionality;
private readonly parentModal;
private openModalsAtThisLevel;
private readonly afterAllClosedAtThisLevel;
get openModals(): NzModalRef[];
get _afterAllClosed(): Subject<void>;
readonly afterAllClose: Observable<void>;
create<T, D = NzSafeAny, R = NzSafeAny>(config: ModalOptions<T, D, R>): NzModalRef<T, R>;
closeAll(): void;
confirm<T>(options?: ModalOptions<T>, confirmType?: ConfirmType): NzModalRef<T>;
info<T>(options?: ModalOptions<T>): NzModalRef<T>;
success<T>(options?: ModalOptions<T>): NzModalRef<T>;
error<T>(options?: ModalOptions<T>): NzModalRef<T>;
warning<T>(options?: ModalOptions<T>): NzModalRef<T>;
private open;
private removeOpenModal;
private closeModals;
private createOverlay;
private attachModalContainer;
private attachModalContent;
private createInjector;
private confirmFactory;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
}
export declare const ZOOM_CLASS_NAME_MAP: {
enter: string;
enterActive: string;
leave: string;
leaveActive: string;
};
export declare const FADE_CLASS_NAME_MAP: {
enter: string;
enterActive: string;
leave: string;
leaveActive: string;
};
export declare const MODAL_MASK_CLASS_NAME = "ant-modal-mask";
export declare const NZ_CONFIG_MODULE_NAME = "modal";
export declare const NZ_MODAL_DATA: InjectionToken<any>;
declare namespace modal_component_d_exports {
export { NzModalComponent };
}
export declare class NzModalComponent<T extends ModalOptions = NzSafeAny, R = NzSafeAny> implements OnChanges, NzModalLegacyAPI<T, R> {
private cdr;
private modal;
private viewContainerRef;
private destroyRef;
nzMask?: boolean;
nzMaskClosable?: boolean;
nzCloseOnNavigation?: boolean;
nzVisible: boolean;
nzClosable: boolean;
nzOkLoading: boolean;
nzOkDisabled: boolean;
nzCancelDisabled: boolean;
nzCancelLoading: boolean;
nzKeyboard: boolean;
nzNoAnimation: boolean;
nzCentered: boolean;
nzDraggable: boolean;
nzContent?: string | TemplateRef<{}> | Type<T>;
nzFooter?: string | TemplateRef<{}> | Array<ModalButtonOptions<T>> | null;
nzZIndex: number;
nzWidth: number | string;
nzWrapClassName?: string;
nzClassName?: string;
nzStyle?: object;
nzTitle?: string | TemplateRef<{}>;
nzCloseIcon: string | TemplateRef<void>;
nzMaskStyle?: StyleObjectLike;
nzBodyStyle?: StyleObjectLike;
nzOkText?: string | null;
nzCancelText?: string | null;
nzOkType: NzButtonType;
nzOkDanger: boolean;
nzIconType: string;
nzModalType: ModalTypes;
nzAutofocus: 'ok' | 'cancel' | 'auto' | null;
readonly nzOnOk: EventEmitter<T>;
readonly nzOnCancel: EventEmitter<T>;
readonly nzAfterOpen: EventEmitter<void>;
readonly nzAfterClose: EventEmitter<R>;
readonly nzVisibleChange: EventEmitter<boolean>;
set modalTitle(value: TemplateRef<NzSafeAny>);
contentFromContentChild: TemplateRef<NzSafeAny>;
set modalFooter(value: TemplateRef<NzSafeAny>);
private modalRef;
get afterOpen(): Observable<void>;
get afterClose(): Observable<R>;
constructor();
open(): void;
close(result?: R): void;
destroy(result?: R): void;
triggerOk(): void;
triggerCancel(): void;
getContentComponent(): T | void;
getElement(): HTMLElement | void;
getModalRef(): NzModalRef | null;
private setTitleWithTemplate;
private setFooterWithTemplate;
private getConfig;
ngOnChanges(changes: SimpleChanges): void;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalComponent<any, any>, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NzModalComponent<any, any>, "nz-modal", ["nzModal"], {
"nzMask": {
"alias": "nzMask";
"required": false;
};
"nzMaskClosable": {
"alias": "nzMaskClosable";
"required": false;
};
"nzCloseOnNavigation": {
"alias": "nzCloseOnNavigation";
"required": false;
};
"nzVisible": {
"alias": "nzVisible";
"required": false;
};
"nzClosable": {
"alias": "nzClosable";
"required": false;
};
"nzOkLoading": {
"alias": "nzOkLoading";
"required": false;
};
"nzOkDisabled": {
"alias": "nzOkDisabled";
"required": false;
};
"nzCancelDisabled": {
"alias": "nzCancelDisabled";
"required": false;
};
"nzCancelLoading": {
"alias": "nzCancelLoading";
"required": false;
};
"nzKeyboard": {
"alias": "nzKeyboard";
"required": false;
};
"nzNoAnimation": {
"alias": "nzNoAnimation";
"required": false;
};
"nzCentered": {
"alias": "nzCentered";
"required": false;
};
"nzDraggable": {
"alias": "nzDraggable";
"required": false;
};
"nzContent": {
"alias": "nzContent";
"required": false;
};
"nzFooter": {
"alias": "nzFooter";
"required": false;
};
"nzZIndex": {
"alias": "nzZIndex";
"required": false;
};
"nzWidth": {
"alias": "nzWidth";
"required": false;
};
"nzWrapClassName": {
"alias": "nzWrapClassName";
"required": false;
};
"nzClassName": {
"alias": "nzClassName";
"required": false;
};
"nzStyle": {
"alias": "nzStyle";
"required": false;
};
"nzTitle": {
"alias": "nzTitle";
"required": false;
};
"nzCloseIcon": {
"alias": "nzCloseIcon";
"required": false;
};
"nzMaskStyle": {
"alias": "nzMaskStyle";
"required": false;
};
"nzBodyStyle": {
"alias": "nzBodyStyle";
"required": false;
};
"nzOkText": {
"alias": "nzOkText";
"required": false;
};
"nzCancelText": {
"alias": "nzCancelText";
"required": false;
};
"nzOkType": {
"alias": "nzOkType";
"required": false;
};
"nzOkDanger": {
"alias": "nzOkDanger";
"required": false;
};
"nzIconType": {
"alias": "nzIconType";
"required": false;
};
"nzModalType": {
"alias": "nzModalType";
"required": false;
};
"nzAutofocus": {
"alias": "nzAutofocus";
"required": false;
};
}, {
"nzOnOk": "nzOnOk";
"nzOnCancel": "nzOnCancel";
"nzAfterOpen": "nzAfterOpen";
"nzAfterClose": "nzAfterClose";
"nzVisibleChange": "nzVisibleChange";
}, ["modalTitle", "contentFromContentChild", "modalFooter"], never, true, never>;
static ngAcceptInputType_nzMask: unknown;
static ngAcceptInputType_nzMaskClosable: unknown;
static ngAcceptInputType_nzCloseOnNavigation: unknown;
static ngAcceptInputType_nzVisible: unknown;
static ngAcceptInputType_nzClosable: unknown;
static ngAcceptInputType_nzOkLoading: unknown;
static ngAcceptInputType_nzOkDisabled: unknown;
static ngAcceptInputType_nzCancelDisabled: unknown;
static ngAcceptInputType_nzCancelLoading: unknown;
static ngAcceptInputType_nzKeyboard: unknown;
static ngAcceptInputType_nzNoAnimation: unknown;
static ngAcceptInputType_nzCentered: unknown;
static ngAcceptInputType_nzDraggable: unknown;
static ngAcceptInputType_nzZIndex: unknown;
static ngAcceptInputType_nzOkDanger: unknown;
}
declare namespace modal_title_directive_d_exports {
export { NzModalTitleDirective };
}
export declare class NzModalTitleDirective {
readonly templateRef: TemplateRef<{}>;
private nzModalRef;
constructor();
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalTitleDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NzModalTitleDirective, "[nzModalTitle]", ["nzModalTitle"], {}, {}, never, never, true, never>;
}
declare namespace modal_footer_directive_d_exports {
export { NzModalFooterDirective };
}
export declare class NzModalFooterDirective {
readonly templateRef: TemplateRef<{}>;
private nzModalRef;
constructor();
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalFooterDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NzModalFooterDirective, "[nzModalFooter]", ["nzModalFooter"], {}, {}, never, never, true, never>;
}
declare namespace modal_content_directive_d_exports {
export { NzModalContentDirective };
}
export declare class NzModalContentDirective {
readonly templateRef: TemplateRef<{}>;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalContentDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NzModalContentDirective, "[nzModalContent]", ["nzModalContent"], {}, {}, never, never, true, never>;
}
declare namespace modal_close_component_d_exports {
export { NzModalCloseComponent };
}
export declare class NzModalCloseComponent {
readonly config: ModalOptions<any, any, any>;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalCloseComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NzModalCloseComponent, "button[nz-modal-close]", ["nzModalCloseBuiltin"], {}, {}, never, never, true, never>;
}
declare namespace modal_footer_component_d_exports {
export { NzModalFooterComponent };
}
export declare class NzModalFooterComponent {
private readonly cdr;
readonly config: ModalOptions<any, any, any>;
readonly modalRef: import("@angular/core").InputSignal<NzModalRef<any, any>>;
readonly cancelTriggered: import("@angular/core").OutputEmitterRef<void>;
readonly okTriggered: import("@angular/core").OutputEmitterRef<void>;
protected buttons: ModalButtonOptions<any>[] | null;
onCancel(): void;
onOk(): void;
markForCheck(): void;
/**
* Returns the value of the specified key.
* If it is a function, run and return the return value of the function.
*/
getButtonCallableProp(options: ModalButtonOptions, prop: keyof ModalButtonOptions): boolean;
/**
* Run function based on the type and set its `loading` prop if needed.
*/
onButtonClick(options: ModalButtonOptions): void;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalFooterComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NzModalFooterComponent, "div[nz-modal-footer]", ["nzModalFooterBuiltin"], {
"modalRef": {
"alias": "modalRef";
"required": true;
"isSignal": true;
};
}, {
"cancelTriggered": "cancelTriggered";
"okTriggered": "okTriggered";
}, never, never, true, never>;
}
declare namespace modal_title_component_d_exports {
export { NzModalTitleComponent };
}
export declare class NzModalTitleComponent {
config: ModalOptions<any, any, any>;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalTitleComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NzModalTitleComponent, "div[nz-modal-title]", ["nzModalTitleBuiltin"], {}, {}, never, never, true, never>;
}
declare namespace modal_container_component_d_exports {
export { NzModalContainerComponent };
}
export declare class NzModalContainerComponent extends BaseModalContainerComponent implements OnInit {
set _portalOutlet(portalOutlet: CdkPortalOutlet);
set _modalElementRef(elementRef: ElementRef<HTMLDivElement>);
private modalFooter?;
markForCheck(): void;
ngOnInit(): void;
protected onDragEnded(event: CdkDragEnd): void;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalContainerComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NzModalContainerComponent, "nz-modal-container", ["nzModalContainer"], {}, {}, never, never, true, [{
directive: typeof i1.CdkScrollable;
inputs: {};
outputs: {};
}]>;
}
declare namespace modal_confirm_container_component_d_exports {
export { NzModalConfirmContainerComponent };
}
export declare class NzModalConfirmContainerComponent extends BaseModalContainerComponent implements OnInit {
set _portalOutlet(portalOutlet: CdkPortalOutlet);
set _modalElementRef(elementRef: ElementRef<HTMLDivElement>);
readonly cancelTriggered: EventEmitter<void>;
readonly okTriggered: EventEmitter<void>;
ngOnInit(): void;
onCancel(): void;
onOk(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalConfirmContainerComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NzModalConfirmContainerComponent, "nz-modal-confirm-container", ["nzModalConfirmContainer"], {}, {
"cancelTriggered": "cancelTriggered";
"okTriggered": "okTriggered";
}, never, never, true, [{
directive: typeof i1.CdkScrollable;
inputs: {};
outputs: {};
}]>;
}
export declare class NzModalModule {
static ɵfac: i0.ɵɵFactoryDeclaration<NzModalModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<NzModalModule, never, [typeof NzModalComponent, typeof NzModalFooterDirective, typeof NzModalContentDirective, typeof NzModalCloseComponent, typeof NzModalFooterComponent, typeof NzModalTitleComponent, typeof NzModalTitleDirective, typeof NzModalContainerComponent, typeof NzModalConfirmContainerComponent], [typeof NzModalComponent, typeof NzModalFooterDirective, typeof NzModalContentDirective, typeof NzModalTitleDirective]>;
static ɵinj: i0.ɵɵInjectorDeclaration<NzModalModule>;
}
export declare function applyConfigDefaults(config: ModalOptions, defaultOptions: ModalOptions): ModalOptions;
export declare function getValueWithConfig<T>(userValue: T | undefined, configValue: T | undefined, defaultValue: T): T | undefined;
export declare function getConfigFromComponent<T extends ModalOptions>(component: T): ModalOptions;