-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathdialog-demo.ts
214 lines (185 loc) · 5.81 KB
/
dialog-demo.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* @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 {DOCUMENT} from '@angular/common';
import {Component, Inject, TemplateRef, ViewEncapsulation} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialog, MatDialogConfig, MatDialogRef} from '@angular/material';
const defaultDialogConfig = new MatDialogConfig();
@Component({
moduleId: module.id,
selector: 'dialog-demo',
templateUrl: 'dialog-demo.html',
styleUrls: ['dialog-demo.css'],
})
export class DialogDemo {
dialogRef: MatDialogRef<JazzDialog> | null;
lastAfterClosedResult: string;
lastBeforeCloseResult: string;
actionsAlignment: string;
config = {
disableClose: false,
panelClass: 'custom-overlay-pane-class',
hasBackdrop: true,
backdropClass: '',
width: defaultDialogConfig.width,
height: defaultDialogConfig.height,
minWidth: defaultDialogConfig.minWidth,
minHeight: defaultDialogConfig.minHeight,
maxWidth: defaultDialogConfig.maxWidth,
maxHeight: defaultDialogConfig.maxHeight,
position: {
top: '',
bottom: '',
left: '',
right: ''
},
data: {
message: 'Jazzy jazz jazz'
}
};
numTemplateOpens = 0;
constructor(public dialog: MatDialog, @Inject(DOCUMENT) doc: any) {
// Possible useful example for the open and closeAll events.
// Adding a class to the body if a dialog opens and
// removing it after all open dialogs are closed
dialog.afterOpen.subscribe(() => {
if (!doc.body.classList.contains('no-scroll')) {
doc.body.classList.add('no-scroll');
}
});
dialog.afterAllClosed.subscribe(() => {
doc.body.classList.remove('no-scroll');
});
}
openJazz() {
this.dialogRef = this.dialog.open(JazzDialog, this.config);
this.dialogRef.beforeClosed().subscribe((result: string) => {
this.lastBeforeCloseResult = result;
});
this.dialogRef.afterClosed().subscribe((result: string) => {
this.lastAfterClosedResult = result;
this.dialogRef = null;
});
}
openContentElement() {
const dialogRef = this.dialog.open(ContentElementDialog, this.config);
dialogRef.componentInstance.actionsAlignment = this.actionsAlignment;
}
openTemplate(template: TemplateRef<any>) {
this.numTemplateOpens++;
this.dialog.open(template, this.config);
}
}
@Component({
selector: 'demo-jazz-dialog',
template: `
<div cdkDrag cdkDragRootElement=".cdk-overlay-pane">
<p>It's Jazz!</p>
<mat-form-field>
<mat-label>How much?</mat-label>
<input matInput #howMuch>
</mat-form-field>
<p cdkDragHandle> {{ data.message }} </p>
<button type="button" (click)="dialogRef.close(howMuch.value)">Close dialog</button>
<button (click)="togglePosition()">Change dimensions</button>
<button (click)="temporarilyHide()">Hide for 2 seconds</button>
</div>
`,
encapsulation: ViewEncapsulation.None,
styles: [`.hidden-dialog { opacity: 0; }`]
})
export class JazzDialog {
private _dimesionToggle = false;
constructor(
public dialogRef: MatDialogRef<JazzDialog>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
togglePosition(): void {
this._dimesionToggle = !this._dimesionToggle;
if (this._dimesionToggle) {
this.dialogRef
.updateSize('500px', '500px')
.updatePosition({ top: '25px', left: '25px' });
} else {
this.dialogRef
.updateSize()
.updatePosition();
}
}
temporarilyHide(): void {
this.dialogRef.addPanelClass('hidden-dialog');
setTimeout(() => {
this.dialogRef.removePanelClass('hidden-dialog');
}, 2000);
}
}
@Component({
selector: 'demo-content-element-dialog',
styles: [`
img {
max-width: 100%;
}
`],
template: `
<h2 mat-dialog-title>Neptune</h2>
<mat-dialog-content>
<img src="https://upload.wikimedia.org/wikipedia/commons/5/56/Neptune_Full.jpg"/>
<p>
Neptune is the eighth and farthest known planet from the Sun in the Solar System. In the
Solar System, it is the fourth-largest planet by diameter, the third-most-massive planet,
and the densest giant planet. Neptune is 17 times the mass of Earth and is slightly more
massive than its near-twin Uranus, which is 15 times the mass of Earth and slightly larger
than Neptune. Neptune orbits the Sun once every 164.8 years at an average distance of 30.1
astronomical units (4.50×109 km). It is named after the Roman god of the sea and has the
astronomical symbol ♆, a stylised version of the god Neptune's trident.
</p>
</mat-dialog-content>
<mat-dialog-actions [attr.align]="actionsAlignment">
<button
mat-raised-button
color="primary"
mat-dialog-close>Close</button>
<a
mat-button
color="primary"
href="https://en.wikipedia.org/wiki/Neptune"
target="_blank">Read more on Wikipedia</a>
<button
mat-button
color="secondary"
(click)="showInStackedDialog()">
Show in Dialog</button>
</mat-dialog-actions>
`
})
export class ContentElementDialog {
actionsAlignment: string;
constructor(public dialog: MatDialog) { }
showInStackedDialog() {
this.dialog.open(IFrameDialog);
}
}
@Component({
selector: 'demo-iframe-dialog',
styles: [`
iframe {
width: 800px;
}
`],
template: `
<h2 mat-dialog-title>Neptune</h2>
<mat-dialog-content>
<iframe frameborder="0" src="https://en.wikipedia.org/wiki/Neptune"></iframe>
</mat-dialog-content>
<mat-dialog-actions>
<button
mat-raised-button
color="primary"
mat-dialog-close>Close</button>
</mat-dialog-actions>
`
})
export class IFrameDialog {}