UNPKG

6.44 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Akveo. All Rights Reserved.
4 * Licensed under the MIT License. See License.txt in the project root for license information.
5 */
6import { ComponentFactoryResolver, Injector, TemplateRef, Type } from '@angular/core';
7import { NbComponentPortal, NbOverlayRef, NbScrollStrategy, NbTemplatePortal } from '../cdk/overlay/mapping';
8import { NbGlobalPositionStrategy, NbPositionBuilderService } from '../cdk/overlay/overlay-position';
9import { NbOverlayService } from '../cdk/overlay/overlay-service';
10import { NbDialogConfig } from './dialog-config';
11import { NbDialogRef } from './dialog-ref';
12import { NbDialogContainerComponent } from './dialog-container';
13import * as i0 from "@angular/core";
14/**
15 * The `NbDialogService` helps to open dialogs.
16 *
17 * @stacked-example(Showcase, dialog/dialog-showcase.component)
18 *
19 * A new dialog is opened by calling the `open` method with a component to be loaded and an optional configuration.
20 * `open` method will return `NbDialogRef` that can be used for the further manipulations.
21 *
22 * ### Installation
23 *
24 * Import `NbDialogModule.forRoot()` to your app module.
25 * ```ts
26 * @NgModule({
27 * imports: [
28 * // ...
29 * NbDialogModule.forRoot(config),
30 * ],
31 * })
32 * export class AppModule { }
33 * ```
34 *
35 * If you are using it in a lazy loaded module than you have to install it with `NbDialogModule.forChild()`:
36 * ```ts
37 * @NgModule({
38 * imports: [
39 * // ...
40 * NbDialogModule.forChild(config),
41 * ],
42 * })
43 * export class LazyLoadedModule { }
44 * ```
45 *
46 * ### Usage
47 *
48 * ```ts
49 * const dialogRef = this.dialogService.open(MyDialogComponent, { ... });
50 * ```
51 *
52 * `NbDialogRef` gives capability access reference to the rendered dialog component,
53 * destroy dialog and some other options described below.
54 *
55 * Also, you can inject `NbDialogRef` in dialog component.
56 *
57 * ```ts
58 * this.dialogService.open(MyDialogComponent, { ... });
59 *
60 * // my-dialog.component.ts
61 * constructor(protected dialogRef: NbDialogRef) {
62 * }
63 *
64 * close() {
65 * this.dialogRef.close();
66 * }
67 * ```
68 *
69 * Instead of component you can create dialog from TemplateRef:
70 *
71 * @stacked-example(Template ref, dialog/dialog-template.component)
72 *
73 * The dialog may return result through `NbDialogRef`. Calling component can receive this result with `onClose`
74 * stream of `NbDialogRef`.
75 *
76 * @stacked-example(Result, dialog/dialog-result.component)
77 *
78 * ### Configuration
79 *
80 * As we mentioned above, `open` method of the `NbDialogService` may receive optional configuration options.
81 * Also, you can provide global dialogs configuration through `NbDialogModule.forRoot({ ... })`.
82 *
83 * This config may contain the following:
84 *
85 * `context` - both, template and component may receive data through `config.context` property.
86 * For components, this data will be assigned through inputs.
87 * For templates, you can access it inside template as $implicit.
88 *
89 * ```ts
90 * this.dialogService.open(template, { context: 'pass data in template' });
91 * ```
92 *
93 * ```html
94 * <ng-template let-some-additional-data>
95 * {{ some-additional-data }}
96 * <ng-template/>
97 * ```
98 *
99 * `hasBackdrop` - determines is service have to render backdrop under the dialog.
100 * Default is true.
101 * @stacked-example(Backdrop, dialog/dialog-has-backdrop.component)
102 *
103 * `closeOnBackdropClick` - close dialog on backdrop click if true.
104 * Default is true.
105 * @stacked-example(Backdrop click, dialog/dialog-backdrop-click.component)
106 *
107 * `closeOnEsc` - close dialog on escape button on the keyboard.
108 * Default is true.
109 * @stacked-example(Escape hit, dialog/dialog-esc.component)
110 *
111 * `hasScroll` - Disables scroll on content under dialog if true and does nothing otherwise.
112 * Default is false.
113 * Please, open dialogs in the separate window and try to scroll.
114 * @stacked-example(Scroll, dialog/dialog-scroll.component)
115 *
116 * `autoFocus` - Focuses dialog automatically after open if true. It's useful to prevent misclicks on
117 * trigger elements and opening multiple dialogs.
118 * Default is true.
119 *
120 * As you can see, if you open dialog with auto focus dialog will focus first focusable element
121 * or just blur previously focused automatically.
122 * Otherwise, without auto focus, the focus will stay on the previously focused element.
123 * Please, open dialogs in the separate window and try to click on the button without focus
124 * and then hit space any times. Multiple same dialogs will be opened.
125 * @stacked-example(Auto focus, dialog/dialog-auto-focus.component)
126 * */
127export declare class NbDialogService {
128 protected document: any;
129 protected globalConfig: any;
130 protected positionBuilder: NbPositionBuilderService;
131 protected overlay: NbOverlayService;
132 protected injector: Injector;
133 protected cfr: ComponentFactoryResolver;
134 constructor(document: any, globalConfig: any, positionBuilder: NbPositionBuilderService, overlay: NbOverlayService, injector: Injector, cfr: ComponentFactoryResolver);
135 /**
136 * Opens new instance of the dialog, may receive optional config.
137 * */
138 open<T>(content: Type<T> | TemplateRef<T>, userConfig?: Partial<NbDialogConfig<Partial<T> | string>>): NbDialogRef<T>;
139 protected createOverlay(config: NbDialogConfig): NbOverlayRef;
140 protected createPositionStrategy(): NbGlobalPositionStrategy;
141 protected createScrollStrategy(hasScroll: boolean): NbScrollStrategy;
142 protected createContainer(config: NbDialogConfig, overlayRef: NbOverlayRef): NbDialogContainerComponent;
143 protected createContent<T>(config: NbDialogConfig, content: Type<T> | TemplateRef<T>, container: NbDialogContainerComponent, dialogRef: NbDialogRef<T>): void;
144 protected createTemplatePortal<T>(config: NbDialogConfig, content: TemplateRef<T>, dialogRef: NbDialogRef<T>): NbTemplatePortal;
145 /**
146 * We're creating portal with custom injector provided through config or using global injector.
147 * This approach provides us capability inject `NbDialogRef` in dialog component.
148 * */
149 protected createComponentPortal<T>(config: NbDialogConfig, content: Type<T>, dialogRef: NbDialogRef<T>): NbComponentPortal;
150 protected createInjector(config: NbDialogConfig): Injector;
151 protected registerCloseListeners<T>(config: NbDialogConfig, overlayRef: NbOverlayRef, dialogRef: NbDialogRef<T>): void;
152 static ɵfac: i0.ɵɵFactoryDeclaration<NbDialogService, never>;
153 static ɵprov: i0.ɵɵInjectableDeclaration<NbDialogService>;
154}