UNPKG

@angular-mdc/web

Version:
86 lines (85 loc) 4.07 kB
import { InjectionToken, Injector, OnDestroy, TemplateRef } from '@angular/core'; import { Observable, Subject } from 'rxjs'; import { Overlay } from '@angular/cdk/overlay'; import { ComponentType } from '@angular/cdk/portal'; import { MdcDialogRef } from './dialog-ref'; import { MdcDialogConfig } from './dialog-config'; /** Injection token that can be used to access the data that was passed in to a dialog. */ export declare const MDC_DIALOG_DATA: InjectionToken<any>; /** Injection token that can be used to specify default dialog options. */ export declare const MDC_DIALOG_DEFAULT_OPTIONS: InjectionToken<MdcDialogConfig<any>>; export declare class MdcDialog implements OnDestroy { private _overlay; private _injector; private _defaultOptions; private _parentDialog; private _openDialogsAtThisLevel; private readonly _afterAllClosedAtThisLevel; private readonly _afterOpenedAtThisLevel; private _ariaHiddenElements; /** Keeps track of the currently-open dialogs. */ get openDialogs(): MdcDialogRef<any>[]; /** Stream that emits when a dialog has been opened. */ get afterOpened(): Subject<MdcDialogRef<any>>; get _afterAllClosed(): Subject<void>; /** * Stream that emits when all open dialog have finished closing. * Will emit on subscribe if there are no open dialogs to begin with. */ readonly afterAllClosed: Observable<void>; constructor(_overlay: Overlay, _injector: Injector, _defaultOptions: MdcDialogConfig, _parentDialog: MdcDialog); /** * Opens a modal dialog containing the given template. * @param componentOrTemplateRef Type of the component to load into the dialog, * or a TemplateRef to instantiate as the dialog content. * @param config Extra configuration options. * @returns Reference to the newly-opened dialog. */ open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>, config?: MdcDialogConfig<D>): MdcDialogRef<T, R>; /** Closes all of the currently-open dialogs. */ closeAll(): void; /** * Finds an open dialog by its id. * @param id ID to use when looking up the dialog. */ getDialogById(id: string): MdcDialogRef<any> | undefined; ngOnDestroy(): void; /** * Creates the overlay into which the dialog will be loaded. * @returns A promise resolving to the OverlayRef for the created overlay. */ private _createOverlay; /** * Attaches an MdcDialogPortal to a dialog's already-created overlay. * @param overlay Reference to the dialog's underlying overlay. * @param config The dialog configuration. * @returns A promise resolving to a ComponentRef for the attached container. */ private _attachDialogContainer; /** * Attaches the user-provided component to the already-created MdcDialogPortal. * @param componentOrTemplateRef The type of component being loaded into the dialog, * or a TemplateRef to instantiate as the content. * @param dialogContainer Reference to the wrapping MdcDialogPortal. * @param overlayRef Reference to the overlay in which the dialog resides. * @param config The dialog configuration. * @returns A promise resolving to the MdcDialogRef that should be returned to the user. */ private _attachDialogContent; /** * Creates a custom injector to be used inside the dialog. This allows a component loaded inside * of a dialog to close itself and, optionally, to return a value. * @param config Config object that is used to construct the dialog. * @param dialogRef Reference to the dialog. * @param container Dialog container element that wraps all of the contents. * @returns The custom injector that can be used inside the dialog. */ private _createInjector; /** * Removes a dialog from the array of open dialogs. * @param dialogRef Dialog to be removed. */ private _removeOpenDialog; /** Closes all of the dialogs in an array. */ private _closeDialogs; }