Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit a7ca243

Browse files
committed
feat(snackbar-demo): Added ngModel binding for Snackbar demo; change snackbar properties dynamically
1 parent 5f2f220 commit a7ca243

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

src/demo-app/app/components/snackbar-demo/snackbar-demo.component.html

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,26 @@ <h1 mdc-typography-headline>Methods</h1>
4343
</div>
4444
</div>
4545
<h1 mdc-typography-headline>Examples</h1>
46-
<div class="mdc-padding">
47-
<button mdc-button [primary]="true" [raised]="true" (click)="showSimple();">Simple</button>
48-
<button mdc-button [primary]="true" [raised]="true" (click)="showActionButton();">Show Action</button>
49-
<button mdc-button [primary]="true" [raised]="true" (click)="showMultiline();">Show Multiline</button>
50-
<button mdc-button [primary]="true" [raised]="true" (click)="showMultilineBottom();">Show Multiline - Bottom</button>
46+
<div fxLayout="column" class="mdc-padding">
47+
<mdc-form-field>
48+
<mdc-checkbox [(ngModel)]="isActionOnBottom"></mdc-checkbox>
49+
<label mdc-checkbox-label>Action on Bottom</label>
50+
</mdc-form-field>
51+
<mdc-form-field>
52+
<mdc-checkbox [(ngModel)]="isMultiline"></mdc-checkbox>
53+
<label mdc-checkbox-label>Multiline</label>
54+
</mdc-form-field>
55+
<mdc-form-field>
56+
<mdc-checkbox [(ngModel)]="isDismissOnAction"></mdc-checkbox>
57+
<label mdc-checkbox-label>Dismiss on Action</label>
58+
</mdc-form-field>
59+
</div>
60+
<div fxLayout="column" fxFlexOffset="1">
61+
<mdc-textfield [(ngModel)]="messageText" label="Message text" [required]="true"></mdc-textfield>
62+
<mdc-textfield [(ngModel)]="actionText" label="Action button text"></mdc-textfield>
63+
</div>
64+
<div class="mdc-padding" fxFlexOffset="2">
65+
<button mdc-button [primary]="true" [raised]="true" (click)="show();">Show</button>
5166
</div>
5267
</div>
5368
<mdc-snackbar #snack></mdc-snackbar>

src/demo-app/app/components/snackbar-demo/snackbar-demo.component.ts

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import {
99
templateUrl: './snackbar-demo.component.html'
1010
})
1111
export class SnackbarDemoComponent implements OnInit {
12+
isActionOnBottom: boolean;
13+
isMultiline: boolean;
14+
isDismissOnAction: boolean = true;
15+
messageText: string = "Sample text";
16+
actionText: string = "Ok";
1217
@ViewChild('snack') snack;
1318

1419
ngOnInit() {
@@ -21,37 +26,14 @@ export class SnackbarDemoComponent implements OnInit {
2126
doc.appendChild(script);
2227
}
2328

24-
showSimple() {
25-
var data = {
26-
message: 'Notification received',
27-
}
28-
this.snack.show(data);
29-
}
30-
showActionButton() {
31-
var data = {
32-
message: 'Notification received',
33-
actionText: 'Ok',
34-
actionHandler: () => { console.log('Action button pressed!') }
35-
}
36-
this.snack.show(data);
37-
}
38-
showMultiline() {
39-
var data = {
40-
message: 'Notification received',
41-
actionText: 'Ok',
42-
multiline: true,
43-
actionHandler: () => { console.log('Action button pressed!') }
44-
}
45-
this.snack.show(data);
46-
}
47-
showMultilineBottom() {
48-
var data = {
49-
message: 'Notification received',
50-
actionText: 'Ok',
51-
multiline: true,
52-
actionOnBottom: true,
53-
actionHandler: () => { console.log('Action button pressed!') }
54-
}
55-
this.snack.show(data);
29+
show() {
30+
this.snack.show({
31+
multiline: this.isMultiline,
32+
actionOnBottom: this.isActionOnBottom,
33+
dismissOnAction: this.isDismissOnAction,
34+
message: this.messageText ? this.messageText : 'Sample text',
35+
actionText: this.actionText,
36+
actionHandler: this.actionText ? () => { console.log('Action button pressed!') } : null
37+
});
5638
}
5739
}

0 commit comments

Comments
 (0)