Skip to content

Commit d4d40e1

Browse files
authored
Merge pull request #158 from mseemann/dialog-animations
dialog openFrom / closeTo
2 parents f0a71a3 + 07e102d commit d4d40e1

18 files changed

+520
-149
lines changed

src/demo-app/app/app.component.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,3 @@ table.docu {
121121
height: 16px;
122122
vertical-align: middle;
123123
}
124-
125-

src/demo-app/app/dialog-declarative/dialog-declarative.component.html

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ <h5>A custom Dialog - template</h5>
9393
<p>Username: {{ username }}</p>
9494

9595
<button
96+
#editUserButton
9697
mdl-button mdl-button-type="raised" mdl-colored="primary"
9798
mdl-ripple (click)="editUserDialog.show()">Edit User Dialog</button>
9899

99100
<mdl-dialog #editUserDialog
100-
[mdl-dialog-config]="{clickOutsideToClose: true, styles:{'width': '350px'}, isModal: true}"
101+
[mdl-dialog-config]="{
102+
clickOutsideToClose: true,
103+
styles:{'width': '350px'},
104+
isModal: true,
105+
openFrom: editUserButton }"
101106
(show)="onDialogShow($event)"
102107
(hide)="onDialogHide()">
103108
<h3 class="mdl-dialog__title">Edit User</h3>
@@ -112,11 +117,15 @@ <h3 class="mdl-dialog__title">Edit User</h3>
112117

113118
<pre prism>
114119
<![CDATA[
115-
<button mdl-button mdl-button-type="raised" mdl-colored="primary"
120+
<button #editUserButton mdl-button mdl-button-type="raised" mdl-colored="primary"
116121
mdl-ripple (click)="editUserDialog.show()">Edit User Dialog</button>
117122

118123
<mdl-dialog #editUserDialog
119-
[mdl-dialog-config]="{clickOutsideToClose: true, styles:{'width': '350px'}, isModal:true}"
124+
[mdl-dialog-config]="{
125+
clickOutsideToClose: true,
126+
styles:{'width': '300px'},
127+
isModal:true,
128+
openFrom: editUserButton}"
120129
(show)="onDialogShow(dialogRef)"
121130
(hide)="onDialogHide()">
122131
<h3 class="mdl-dialog__title">Edit User</h3>
@@ -167,7 +176,9 @@ <h5>Attributes of the mdl-dialog component</h5>
167176
</table>
168177

169178
<h5>Dialog configuration object</h5>
170-
179+
<p>Not all of these parameters are available for <i>alert</i> and <i>confirm</i>. If you need these
180+
parameters please use the <i>showDialog</i> method of the <i>MdlDialogService</i> to create these
181+
dialogs.</p>
171182
<table class="docu" mdl-shadow="2">
172183
<thead>
173184
<tr>
@@ -215,5 +226,22 @@ <h5>Dialog configuration object</h5>
215226
</td>
216227
</tr>
217228

229+
<tr>
230+
<td>openFrom?: <br/>MdlButtonComponent | <br/>MouseEvent | <br/>OpenCloseRect</td>
231+
<td>
232+
Use a show animation for the dialag that starts at a MdlButtonComponent, a MousEvent or a OpenCloseRect. From all
233+
of these types the top, left, width and height will be used to create the starting point and startings size of
234+
the dialog animation.
235+
</td>
236+
</tr>
237+
238+
<tr>
239+
<td>closeTo?: <br/>MdlButtonComponent | <br/>MouseEvent | <br/>OpenCloseRect</td>
240+
<td>
241+
Use a show animation for the dialag that ends at a MdlButtonComponent, a MousEvent or a OpenCloseRect. From all
242+
of these types the top, left, width and height will be used to create the end point and end size of
243+
the dialog animation.
244+
</td>
245+
</tr>
218246
</tbody>
219247
</table>

src/demo-app/app/dialog-declarative/dialog-declarative.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ export class DialogDeclarativeDemo extends AbstractDemoComponent {
5050
}
5151

5252
public onDialogShow(dialogRef: MdlDialogReference){
53-
this.editedUsername = this.username;
5453
console.log(`dialog shown`, dialogRef);
55-
setTimeout( () => {
56-
this.tfName.setFocus();
57-
});
54+
this.editedUsername = this.username;
55+
this.tfName.setFocus();
5856
}
5957

58+
6059
public onDialogHide(){
6160
console.log(`dialog hidden`);
6261
}

src/demo-app/app/dialog/dialog.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h5>Dialog with choises</h5>
7373
mdl-button-type="raised"
7474
mdl-colored="primary"
7575
mdl-ripple
76-
(click)="showDialogFullWidthAction()">Show Dialog with full width actions</button>
76+
(click)="showDialogFullWidthAction($event)">Show Dialog with full width actions</button>
7777

7878

7979
<pre prism>
@@ -105,7 +105,13 @@ <h5>Dialog with choises</h5>
105105
}
106106
],
107107
fullWidthAction: true,
108-
isModal: false
108+
isModal: false,
109+
openFrom: $event,
110+
closeTo: {
111+
left: document.body.offsetWidth/2,
112+
height: 0,
113+
top: document.body.offsetHeight/2,
114+
width: 0} as OpenCloseRect
109115
});
110116
pDialog.then( (dialogReference) => console.log('dialog visible', dialogReference) );
111117

src/demo-app/app/dialog/dialog.component.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
LoginDialogComponent,
1717
TEST_VALUE
1818
} from './login-dialog.component';
19+
import { OpenCloseRect } from '../../../lib/components/dialog/mdl-dialog-configuration';
1920

2021

2122
@Component({
@@ -54,13 +55,13 @@ export class DialogDemo extends AbstractDemoComponent {
5455
console.log('declined');
5556
}
5657
);
57-
// if you only need the conform answer
58+
// if you only need the confirm answer
5859
result.onErrorResumeNext().subscribe( () => {
5960
console.log('confirmed 2');
6061
})
6162
}
6263

63-
public showDialogFullWidthAction() {
64+
public showDialogFullWidthAction($event: MouseEvent) {
6465
let pDialog = this.dialogService.showDialog({
6566
title: 'Your choice?',
6667
message: 'What drink do you prefer to your meal?',
@@ -86,7 +87,13 @@ export class DialogDemo extends AbstractDemoComponent {
8687
}
8788
],
8889
fullWidthAction: true,
89-
isModal: false
90+
isModal: false,
91+
openFrom: $event,
92+
closeTo: {
93+
left: document.body.offsetWidth/2,
94+
height: 0,
95+
top: document.body.offsetHeight/2,
96+
width: 0} as OpenCloseRect
9097
});
9198
pDialog.subscribe( (dialogReference) => console.log('dialog visible', dialogReference) );
9299
}
@@ -97,8 +104,9 @@ export class DialogDemo extends AbstractDemoComponent {
97104
component: LoginDialogComponent,
98105
providers: [{provide: TEST_VALUE, useValue: 'Just an example'}],
99106
isModal: true,
100-
styles: {'width': '350px'},
101-
clickOutsideToClose: true
107+
styles: {'width': '300px'},
108+
clickOutsideToClose: true,
109+
openFrom: $event
102110
});
103111
pDialog.subscribe( (dialogReference: MdlDialogReference) => {
104112
console.log('dialog visible', dialogReference);

src/demo-app/app/dialog/login-dialog.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ export class LoginDialogComponent implements OnInit {
4747
// just if you want to be informed if the dialog is hidden
4848
this.dialog.onHide().subscribe( () => console.log('login dialog hidden') );
4949

50+
this.dialog.onVisible().subscribe( () => {
51+
console.log('set focus');
52+
this.inputElement.setFocus();
53+
});
54+
5055
}
5156

57+
5258
public ngOnInit() {
5359
this.form = this.fb.group({
5460
'username': this.username,
@@ -57,11 +63,6 @@ export class LoginDialogComponent implements OnInit {
5763
}
5864

5965

60-
public ngAfterViewInit() {
61-
// set the focus - autofocus only works once :(
62-
this.inputElement.setFocus();
63-
}
64-
6566
public login() {
6667
this.processingLogin = true;
6768
this.statusMessage = 'checking your credentials ...';

src/demo-app/favicon.ico

-5.3 KB
Binary file not shown.

src/lib/components/button/mdl-button.component.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ describe('Component: MdlButton', () => {
103103

104104
});
105105

106+
it('should expose the elementRef to be used as openFrom for dialogs', () => {
107+
108+
TestBed.overrideComponent(MdlTestButtonComponent, { set: {
109+
template: '<mdl-button>x</mdl-button>' }
110+
});
111+
let fixture = TestBed.createComponent(MdlTestButtonComponent);
112+
113+
fixture.detectChanges();
114+
115+
let button = fixture.debugElement.query(By.directive(MdlButtonComponent)).componentInstance;
116+
117+
expect(button.elementRef).toBeDefined('elementRef must be present!')
118+
});
119+
106120
});
107121

108122

src/lib/components/button/mdl-button.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class MdlButtonComponent implements OnChanges {
6464
@Input('mdl-colored') private mdlColoredType: 'primary' | 'accent' | '';
6565
@Input() @BooleanProperty() public disabled = false;
6666

67-
constructor(private elementRef: ElementRef, private renderer: Renderer) {
67+
constructor(public elementRef: ElementRef, private renderer: Renderer) {
6868
this.element = elementRef.nativeElement;
6969
}
7070

src/lib/components/dialog/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MdlCommonsModule } from '../common/index';
77
import { MdlDialogHostComponent } from './mdl-dialog-host.component';
88
import { MdlAlertComponent } from './mdl-alert.component';
99
import { MdlDialogOutletModule } from '../dialog-outlet/index';
10+
import { MdlButtonModule } from '../button/mdl-button.component';
1011

1112
export * from './mdl-dialog.component';
1213
export * from './mdl-dialog.service';
@@ -27,6 +28,7 @@ const PRIVATE_COMPONENTS = [
2728
imports: [
2829
CommonModule,
2930
MdlCommonsModule,
31+
MdlButtonModule,
3032
MdlDialogOutletModule.forRoot()
3133
],
3234
exports: [

0 commit comments

Comments
 (0)