/
dialog-config.ts
163 lines (130 loc) · 5.68 KB
/
dialog-config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {
ViewContainerRef,
ComponentFactoryResolver,
Injector,
StaticProvider,
Type,
} from '@angular/core';
import {Direction} from '@angular/cdk/bidi';
import {PositionStrategy, ScrollStrategy} from '@angular/cdk/overlay';
import {BasePortalOutlet} from '@angular/cdk/portal';
/** Options for where to set focus to automatically on dialog open */
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';
/** Valid ARIA roles for a dialog. */
export type DialogRole = 'dialog' | 'alertdialog';
/** Configuration for opening a modal dialog. */
export class DialogConfig<D = unknown, R = unknown, C extends BasePortalOutlet = BasePortalOutlet> {
/**
* Where the attached component should live in Angular's *logical* component tree.
* This affects what is available for injection and the change detection order for the
* component instantiated inside of the dialog. This does not affect where the dialog
* content will be rendered.
*/
viewContainerRef?: ViewContainerRef;
/**
* Injector used for the instantiation of the component to be attached. If provided,
* takes precedence over the injector indirectly provided by `ViewContainerRef`.
*/
injector?: Injector;
/** ID for the dialog. If omitted, a unique one will be generated. */
id?: string;
/** The ARIA role of the dialog element. */
role?: DialogRole = 'dialog';
/** Optional CSS class or classes applied to the overlay panel. */
panelClass?: string | string[] = '';
/** Whether the dialog has a backdrop. */
hasBackdrop?: boolean = true;
/** Optional CSS class or classes applied to the overlay backdrop. */
backdropClass?: string | string[] = '';
/** Whether the dialog closes with the escape key or pointer events outside the panel element. */
disableClose?: boolean = false;
/** Width of the dialog. */
width?: string = '';
/** Height of the dialog. */
height?: string = '';
/** Min-width of the dialog. If a number is provided, assumes pixel units. */
minWidth?: number | string;
/** Min-height of the dialog. If a number is provided, assumes pixel units. */
minHeight?: number | string;
/** Max-width of the dialog. If a number is provided, assumes pixel units. Defaults to 80vw. */
maxWidth?: number | string;
/** Max-height of the dialog. If a number is provided, assumes pixel units. */
maxHeight?: number | string;
/** Strategy to use when positioning the dialog. Defaults to centering it on the page. */
positionStrategy?: PositionStrategy;
/** Data being injected into the child component. */
data?: D | null = null;
/** Layout direction for the dialog's content. */
direction?: Direction;
/** ID of the element that describes the dialog. */
ariaDescribedBy?: string | null = null;
/** ID of the element that labels the dialog. */
ariaLabelledBy?: string | null = null;
/** Dialog label applied via `aria-label` */
ariaLabel?: string | null = null;
/** Whether this is a modal dialog. Used to set the `aria-modal` attribute. */
ariaModal?: boolean = true;
/**
* Where the dialog should focus on open.
* @breaking-change 14.0.0 Remove boolean option from autoFocus. Use string or
* AutoFocusTarget instead.
*/
autoFocus?: AutoFocusTarget | string | boolean = 'first-tabbable';
/**
* Whether the dialog should restore focus to the previously-focused element upon closing.
* Has the following behavior based on the type that is passed in:
* - `boolean` - when true, will return focus to the element that was focused before the dialog
* was opened, otherwise won't restore focus at all.
* - `string` - focus will be restored to the first element that matches the CSS selector.
* - `HTMLElement` - focus will be restored to the specific element.
*/
restoreFocus?: boolean | string | HTMLElement = true;
/**
* Scroll strategy to be used for the dialog. This determines how
* the dialog responds to scrolling underneath the panel element.
*/
scrollStrategy?: ScrollStrategy;
/**
* Whether the dialog should close when the user navigates backwards or forwards through browser
* history. This does not apply to navigation via anchor element unless using URL-hash based
* routing (`HashLocationStrategy` in the Angular router).
*/
closeOnNavigation?: boolean = true;
/**
* Whether the dialog should close when the dialog service is destroyed. This is useful if
* another service is wrapping the dialog and is managing the destruction instead.
*/
closeOnDestroy?: boolean = true;
/** Alternate `ComponentFactoryResolver` to use when resolving the associated component. */
componentFactoryResolver?: ComponentFactoryResolver;
/**
* Providers that will be exposed to the contents of the dialog. Can also
* be provided as a function in order to generate the providers lazily.
*/
providers?:
| StaticProvider[]
| ((dialogRef: R, config: DialogConfig<D, R, C>, container: C) => StaticProvider[]);
/**
* Component into which the dialog content will be rendered. Defaults to `CdkDialogContainer`.
* A configuration object can be passed in to customize the providers that will be exposed
* to the dialog container.
*/
container?:
| Type<C>
| {
type: Type<C>;
providers: (config: DialogConfig<D, R, C>) => StaticProvider[];
};
/**
* Context that will be passed to template-based dialogs.
* A function can be passed in to resolve the context lazily.
*/
templateContext?: Record<string, any> | (() => Record<string, any>);
}