-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
dialog-content-directives.ts
84 lines (71 loc) · 2.42 KB
/
dialog-content-directives.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
/**
* @license
* Copyright Google Inc. 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 {Directive, Input, Optional, OnInit} from '@angular/core';
import {MdDialogRef} from './dialog-ref';
import {MdDialogContainer} from './dialog-container';
/** Counter used to generate unique IDs for dialog elements. */
let dialogElementUid = 0;
/**
* Button that will close the current dialog.
*/
@Directive({
selector: 'button[md-dialog-close], button[mat-dialog-close],' +
'button[mdDialogClose], button[matDialogClose]',
host: {
'(click)': 'dialogRef.close(dialogResult)',
'[attr.aria-label]': 'ariaLabel',
'type': 'button', // Prevents accidental form submits.
}
})
export class MdDialogClose {
/** Screenreader label for the button. */
@Input('aria-label') ariaLabel: string = 'Close dialog';
/** Dialog close input. */
@Input('md-dialog-close') dialogResult: any;
/** Dialog close input for compatibility mode. */
@Input('mat-dialog-close') set _matDialogClose(value: any) { this.dialogResult = value; }
constructor(public dialogRef: MdDialogRef<any>) { }
}
/**
* Title of a dialog element. Stays fixed to the top of the dialog when scrolling.
*/
@Directive({
selector: '[md-dialog-title], [mat-dialog-title], [mdDialogTitle], [matDialogTitle]',
host: {
'class': 'mat-dialog-title',
'[id]': 'id',
},
})
export class MdDialogTitle implements OnInit {
@Input() id = `md-dialog-title-${dialogElementUid++}`;
constructor(@Optional() private _container: MdDialogContainer) { }
ngOnInit() {
if (this._container && !this._container._ariaLabelledBy) {
Promise.resolve().then(() => this._container._ariaLabelledBy = this.id);
}
}
}
/**
* Scrollable content container of a dialog.
*/
@Directive({
selector: '[md-dialog-content], md-dialog-content, [mat-dialog-content], mat-dialog-content,' +
'[mdDialogContent], [matDialogContent]',
host: {'class': 'mat-dialog-content'}
})
export class MdDialogContent { }
/**
* Container for the bottom action buttons in a dialog.
* Stays fixed to the bottom when scrolling.
*/
@Directive({
selector: '[md-dialog-actions], md-dialog-actions, [mat-dialog-actions], mat-dialog-actions,' +
'[mdDialogActions], [matDialogActions]',
host: {'class': 'mat-dialog-actions'}
})
export class MdDialogActions { }