File tree 4 files changed +22
-5
lines changed
4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,13 @@ <h1>SnackBar demo</h1>
3
3
< div >
4
4
Message: < md-input-container > < input mdInput type ="text " [(ngModel)] ="message "> </ md-input-container >
5
5
</ div >
6
+ < div >
7
+ < span > Position in page: </ span >
8
+ < md-radio-group [(ngModel)] ="position ">
9
+ < md-radio-button value ="left "> Left</ md-radio-button >
10
+ < md-radio-button value ="center "> Center</ md-radio-button >
11
+ </ md-radio-group >
12
+ </ div >
6
13
< div >
7
14
< md-checkbox [(ngModel)] ="action ">
8
15
< p *ngIf ="!action "> Show button on snack bar</ p >
@@ -27,7 +34,6 @@ <h1>SnackBar demo</h1>
27
34
</ md-input-container >
28
35
</ md-checkbox >
29
36
</ div >
30
-
31
37
< p >
32
38
< md-checkbox [(ngModel)] ="addExtraClass "> Add extra class to container</ md-checkbox >
33
39
</ p >
Original file line number Diff line number Diff line change @@ -15,12 +15,14 @@ export class SnackBarDemo {
15
15
setAutoHide : boolean = true ;
16
16
autoHide : number = 10000 ;
17
17
addExtraClass : boolean = false ;
18
+ position : 'center' | 'left' = 'center' ;
18
19
19
20
constructor ( public snackBar : MdSnackBar ) { }
20
21
21
22
open ( ) {
22
23
let config = new MdSnackBarConfig ( ) ;
23
- config . duration = this . autoHide ;
24
+ config . position = this . position ;
25
+ config . duration = this . setAutoHide ? this . autoHide : 0 ;
24
26
config . extraClasses = this . addExtraClass ? [ 'party' ] : null ;
25
27
this . snackBar . open ( this . message , this . action && this . actionButtonLabel , config ) ;
26
28
}
Original file line number Diff line number Diff line change @@ -19,4 +19,7 @@ export class MdSnackBarConfig {
19
19
20
20
/** Extra CSS classes to be added to the snack bar container. */
21
21
extraClasses ?: string [ ] ;
22
+
23
+ /** The position to place the snack bar in the view, either 'left' or 'center'. */
24
+ position ?: string = 'center' ;
22
25
}
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ export class MdSnackBar {
54
54
*/
55
55
openFromComponent < T > ( component : ComponentType < T > , config ?: MdSnackBarConfig ) : MdSnackBarRef < T > {
56
56
config = _applyConfigDefaults ( config ) ;
57
- let overlayRef = this . _createOverlay ( ) ;
57
+ let overlayRef = this . _createOverlay ( config ) ;
58
58
let snackBarContainer = this . _attachSnackBarContainer ( overlayRef , config ) ;
59
59
let snackBarRef = this . _attachSnackbarContent ( component , snackBarContainer , overlayRef ) ;
60
60
@@ -140,11 +140,17 @@ export class MdSnackBar {
140
140
/**
141
141
* Creates a new overlay and places it in the correct location.
142
142
*/
143
- private _createOverlay ( ) : OverlayRef {
143
+ private _createOverlay ( config : MdSnackBarConfig ) : OverlayRef {
144
144
let state = new OverlayState ( ) ;
145
- state . positionStrategy = this . _overlay . position ( ) . global ( )
145
+ if ( config . position === 'left' ) {
146
+ state . positionStrategy = this . _overlay . position ( ) . global ( )
147
+ . left ( '24px' )
148
+ . bottom ( '24px' ) ;
149
+ } else {
150
+ state . positionStrategy = this . _overlay . position ( ) . global ( )
146
151
. centerHorizontally ( )
147
152
. bottom ( '0' ) ;
153
+ }
148
154
return this . _overlay . create ( state ) ;
149
155
}
150
156
}
You can’t perform that action at this time.
0 commit comments