-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
dialog-container.ts
124 lines (116 loc) · 3.88 KB
/
dialog-container.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
/**
* @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 {AnimationEvent} from '@angular/animations';
import {FocusMonitor, FocusTrapFactory, InteractivityChecker} from '@angular/cdk/a11y';
import {OverlayRef} from '@angular/cdk/overlay';
import {DOCUMENT} from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
Inject,
NgZone,
Optional,
ViewEncapsulation,
} from '@angular/core';
import {defaultParams} from './dialog-animations';
import {MatLegacyDialogConfig} from './dialog-config';
import {
_MatDialogContainerBase,
matDialogAnimations,
MatDialogConfig as DialogConfigToken,
} from '@angular/material/dialog';
/**
* Internal component that wraps user-provided dialog content.
* Animation is based on https://material.io/guidelines/motion/choreography.html.
* @docs-private
*/
@Component({
selector: 'mat-dialog-container',
templateUrl: 'dialog-container.html',
styleUrls: ['dialog.css'],
encapsulation: ViewEncapsulation.None,
// Using OnPush for dialogs caused some G3 sync issues. Disabled until we can track them down.
// tslint:disable-next-line:validate-decorators
changeDetection: ChangeDetectionStrategy.Default,
animations: [matDialogAnimations.dialogContainer],
host: {
'class': 'mat-dialog-container',
'tabindex': '-1',
'[attr.aria-modal]': '_config.ariaModal',
'[id]': '_config.id',
'[attr.role]': '_config.role',
'[attr.aria-labelledby]': '_config.ariaLabel ? null : _ariaLabelledBy',
'[attr.aria-label]': '_config.ariaLabel',
'[attr.aria-describedby]': '_config.ariaDescribedBy || null',
'[@dialogContainer]': `_getAnimationState()`,
'(@dialogContainer.start)': '_onAnimationStart($event)',
'(@dialogContainer.done)': '_onAnimationDone($event)',
},
})
export class MatLegacyDialogContainer extends _MatDialogContainerBase {
/** State of the dialog animation. */
_state: 'void' | 'enter' | 'exit' = 'enter';
/** Callback, invoked whenever an animation on the host completes. */
_onAnimationDone({toState, totalTime}: AnimationEvent) {
if (toState === 'enter') {
this._openAnimationDone(totalTime);
} else if (toState === 'exit') {
this._animationStateChanged.next({state: 'closed', totalTime});
}
}
/** Callback, invoked when an animation on the host starts. */
_onAnimationStart({toState, totalTime}: AnimationEvent) {
if (toState === 'enter') {
this._animationStateChanged.next({state: 'opening', totalTime});
} else if (toState === 'exit' || toState === 'void') {
this._animationStateChanged.next({state: 'closing', totalTime});
}
}
/** Starts the dialog exit animation. */
_startExitAnimation(): void {
this._state = 'exit';
// Mark the container for check so it can react if the
// view container is using OnPush change detection.
this._changeDetectorRef.markForCheck();
}
constructor(
elementRef: ElementRef,
focusTrapFactory: FocusTrapFactory,
@Optional() @Inject(DOCUMENT) document: any,
@Inject(DialogConfigToken) dialogConfig: MatLegacyDialogConfig,
checker: InteractivityChecker,
ngZone: NgZone,
overlayRef: OverlayRef,
private _changeDetectorRef: ChangeDetectorRef,
focusMonitor?: FocusMonitor,
) {
super(
elementRef,
focusTrapFactory,
document,
dialogConfig,
checker,
ngZone,
overlayRef,
focusMonitor,
);
}
_getAnimationState() {
return {
value: this._state,
params: {
'enterAnimationDuration':
this._config.enterAnimationDuration || defaultParams.params.enterAnimationDuration,
'exitAnimationDuration':
this._config.exitAnimationDuration || defaultParams.params.exitAnimationDuration,
},
};
}
}