@euro-ombudsman/ngx-modal-dialog
Version:
Dynamic modal dialog for Angular 21
180 lines (172 loc) • 6.29 kB
TypeScript
import * as i0 from '@angular/core';
import { ComponentRef, OnDestroy, OnInit, ElementRef, ViewContainerRef, InjectionToken, ModuleWithProviders } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import * as i3 from '@angular/common';
interface IModalDialog {
dialogInit: (reference: ComponentRef<IModalDialog>, options: Partial<IModalDialogOptions<any>>) => void;
}
interface IModalDialogOptions<T> {
title: string;
childComponent: any;
onClose: () => Promise<any> | Observable<any> | boolean;
actionButtons: IModalDialogButton[];
data: T;
placeOnTop: boolean;
settings: Partial<IModalDialogSettings>;
closeDialogSubject: Subject<void>;
}
type ModalDialogOnAction = () => Promise<any> | Observable<any> | boolean | void;
interface IModalDialogButton {
text: string;
buttonClass?: string;
onAction?: ModalDialogOnAction;
}
interface IModalDialogSettings {
overlayClass: string;
overlayAnimationTriggerClass: string;
modalClass: string;
modalAnimationTriggerClass: string;
modalDialogClass: string;
contentClass: string;
headerClass: string;
headerTitleClass: string;
closeButtonClass: string;
closeButtonTitle: string;
bodyClass: string;
footerClass: string;
alertClass: string;
alertDuration: number;
buttonClass: string;
notifyWithAlert: boolean;
}
/**
* Modal dialog component
*/
declare class ModalDialogComponent implements IModalDialog, OnDestroy, OnInit {
protected _element: ElementRef;
dynamicComponentTarget: ViewContainerRef;
private dialogElement;
reference: ComponentRef<IModalDialog>;
/** Modal dialog style settings */
settings: IModalDialogSettings;
actionButtons: IModalDialogButton[];
title: string;
onClose: () => Promise<any> | Observable<any> | boolean;
showAlert: boolean;
animateOverlayClass: string;
animateModalClass: string;
showOverlay: boolean;
private _inProgress;
private _alertTimeout;
private _childInstance;
private _closeDialog$;
/**
* CTOR
* @param _element
*/
constructor(_element: ElementRef);
onClick(event: any): void;
/**
* Initialize dialog with reference to instance and options
* @param reference
* @param options
*/
dialogInit(reference: ComponentRef<IModalDialog>, options?: Partial<IModalDialogOptions<any>>): void;
ngOnInit(): void;
/**
* Cleanup on destroy
*/
ngOnDestroy(): void;
/**
* Run action defined on action button
* @param action
*/
doAction(action?: ModalDialogOnAction): void;
/**
* Method to run on close
* if action buttons are defined, it will not close
*/
close(): void;
/**
* Pass options from dialog setup to component
* @param {IModalDialogOptions} options?
*/
private _setOptions;
/**
* Close if successful
* @param callback
*/
private _closeIfSuccessful;
private _finalizeAndDestroy;
private _triggerAlert;
private isPromise;
private isObservable;
static ɵfac: i0.ɵɵFactoryDeclaration<ModalDialogComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<ModalDialogComponent, "modal-dialog", never, {}, {}, never, never, false, never>;
}
interface ISimpleModalDataOptions {
text: string;
}
declare class SimpleModalComponent implements IModalDialog {
text: string;
/**
* Initialize dialog with simple HTML content
* @param {ComponentRef<IModalDialog>} reference
* @param {Partial<IModalDialogOptions>} options
*/
dialogInit(reference: ComponentRef<IModalDialog>, options: Partial<IModalDialogOptions<ISimpleModalDataOptions>>): void;
static ɵfac: i0.ɵɵFactoryDeclaration<SimpleModalComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<SimpleModalComponent, "simple-modal-dialog", never, {}, {}, never, never, false, never>;
}
/**
* Guard to make sure we have single initialization of forRoot
* @type {InjectionToken<ModalDialogModule>}
*/
declare const MODAL_DIALOG_FORROOT_GUARD: InjectionToken<ModalDialogModule>;
declare class ModalDialogModule {
static forRoot(): ModuleWithProviders<ModalDialogModule>;
static ɵfac: i0.ɵɵFactoryDeclaration<ModalDialogModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<ModalDialogModule, [typeof ModalDialogComponent, typeof SimpleModalComponent], [typeof i3.CommonModule], [typeof ModalDialogComponent, typeof SimpleModalComponent]>;
static ɵinj: i0.ɵɵInjectorDeclaration<ModalDialogModule>;
}
/**
* @param dialogModule
* @returns {string}
*/
declare function provideForRootGuard(dialogModule: ModalDialogModule): string;
declare class ModalDialogInstanceService {
/**
* Used to make sure there is exactly one instance of Modal Dialog
*/
private componentRefs;
/**
* Closes existing modal dialog
*/
closeAnyExistingModalDialog(): void;
/**
* Save component ref for future comparison
* @param componentRef
*/
saveExistingModalDialog(componentRef: ComponentRef<ModalDialogComponent>): void;
setOverlayForTopDialog(value: boolean): void;
static ɵfac: i0.ɵɵFactoryDeclaration<ModalDialogInstanceService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ModalDialogInstanceService>;
}
declare class ModalDialogService {
private modalDialogInstanceService;
/**
* CTOR
* @param modalDialogInstanceService
*/
constructor(modalDialogInstanceService: ModalDialogInstanceService);
/**
* Open dialog in given target element with given options
* @param {ViewContainerRef} target
* @param {IModalDialogOptions} options?
*/
openDialog(target: ViewContainerRef, options?: Partial<IModalDialogOptions<any>>): void;
static ɵfac: i0.ɵɵFactoryDeclaration<ModalDialogService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ModalDialogService>;
}
export { MODAL_DIALOG_FORROOT_GUARD, ModalDialogComponent, ModalDialogInstanceService, ModalDialogModule, ModalDialogService, SimpleModalComponent, provideForRootGuard };
export type { IModalDialog, IModalDialogButton, IModalDialogOptions, IModalDialogSettings, ISimpleModalDataOptions, ModalDialogOnAction };