Skip to content

Commit c1299ea

Browse files
committed
feat(md-snack-bar): Create initial MdSnackBar.
1 parent 6cade28 commit c1299ea

21 files changed

+572
-0
lines changed

src/demo-app/demo-app-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {MdCheckboxDemoNestedChecklist, CheckboxDemo} from './checkbox/checkbox-d
2929
import {SelectDemo} from './select/select-demo';
3030
import {SliderDemo} from './slider/slider-demo';
3131
import {SidenavDemo} from './sidenav/sidenav-demo';
32+
import {SnackBarDemo} from './snack-bar/snack-bar-demo';
3233
import {PortalDemo, ScienceJoke} from './portal/portal-demo';
3334
import {MenuDemo} from './menu/menu-demo';
3435
import {TabsDemo} from './tabs/tab-group-demo';
@@ -61,6 +62,7 @@ import {TabsDemo} from './tabs/tab-group-demo';
6162
LiveAnnouncerDemo,
6263
MdCheckboxDemoNestedChecklist,
6364
MenuDemo,
65+
SnackBarDemo,
6466
OverlayDemo,
6567
PortalDemo,
6668
ProgressBarDemo,

src/demo-app/demo-app/demo-app.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<a md-list-item [routerLink]="['sidenav']">Sidenav</a>
2424
<a md-list-item [routerLink]="['slider']">Slider</a>
2525
<a md-list-item [routerLink]="['slide-toggle']">Slide Toggle</a>
26+
<a md-list-item [routerLink]="['snack-bar']">Snack Bar</a>
2627
<a md-list-item [routerLink]="['tabs']">Tabs</a>
2728
<a md-list-item [routerLink]="['toolbar']">Toolbar</a>
2829
<a md-list-item [routerLink]="['tooltip']">Tooltip</a>

src/demo-app/demo-app/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {MenuDemo} from '../menu/menu-demo';
2626
import {RippleDemo} from '../ripple/ripple-demo';
2727
import {DialogDemo} from '../dialog/dialog-demo';
2828
import {TooltipDemo} from '../tooltip/tooltip-demo';
29+
import {SnackBarDemo} from '../snack-bar/snack-bar-demo';
2930

3031

3132
export const DEMO_APP_ROUTES: Routes = [
@@ -56,4 +57,5 @@ export const DEMO_APP_ROUTES: Routes = [
5657
{path: 'ripple', component: RippleDemo},
5758
{path: 'dialog', component: DialogDemo},
5859
{path: 'tooltip', component: TooltipDemo},
60+
{path: 'snack-bar', component: SnackBarDemo},
5961
];
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h1>SnackBar demo</h1>
2+
<div>
3+
<div>Message: <md-input type="text" [(ngModel)]="message"></md-input></div>
4+
<div>
5+
<md-checkbox [(ngModel)]="action">
6+
<p *ngIf="!action">Show button on snack bar</p>
7+
<md-input type="text" class="button-label-input"
8+
*ngIf="action"
9+
placeholder="Snack bar action label"
10+
[(ngModel)]="actionButtonLabel"></md-input>
11+
</md-checkbox>
12+
</div>
13+
</div>
14+
15+
<button md-raised-button (click)="open()">OPEN</button>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.button-label-input {
2+
display: inline-block;
3+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Component, ViewContainerRef} from '@angular/core';
2+
import {MdSnackBar, MdSnackBarConfig} from '@angular/material';
3+
4+
@Component({
5+
moduleId: module.id,
6+
selector: 'snack-bar-demo',
7+
templateUrl: 'snack-bar-demo.html',
8+
})
9+
export class SnackBarDemo {
10+
message: string = 'Snack Bar opened.';
11+
actionButtonLabel: string = 'Retry';
12+
action: boolean = false;
13+
14+
constructor(
15+
public snackBar: MdSnackBar,
16+
public viewContainerRef: ViewContainerRef) { }
17+
18+
open() {
19+
let config = new MdSnackBarConfig(this.viewContainerRef);
20+
this.snackBar.open(this.message, this.action && this.actionButtonLabel, config);
21+
}
22+
}
23+
24+
25+
@Component({
26+
moduleId: module.id,
27+
selector: 'demo-snack',
28+
templateUrl: 'snack-bar-demo.html',
29+
styleUrls: ['./snack-bar-demo.css'],
30+
})
31+
export class DemoSnack {}

src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './select/index';
1818
export * from './sidenav/index';
1919
export * from './slider/index';
2020
export * from './slide-toggle/index';
21+
export * from './snack-bar/index';
2122
export * from './tabs/index';
2223
export * from './toolbar/index';
2324
export * from './tooltip/index';

src/lib/module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {MdIconModule} from './icon/index';
2323
import {MdProgressCircleModule} from './progress-circle/index';
2424
import {MdProgressBarModule} from './progress-bar/index';
2525
import {MdInputModule} from './input/index';
26+
import {MdSnackBarModule} from './snack-bar/snack-bar';
2627
import {MdTabsModule} from './tabs/index';
2728
import {MdToolbarModule} from './toolbar/index';
2829
import {MdTooltipModule} from './tooltip/index';
@@ -49,6 +50,7 @@ const MATERIAL_MODULES = [
4950
MdSidenavModule,
5051
MdSliderModule,
5152
MdSlideToggleModule,
53+
MdSnackBarModule,
5254
MdTabsModule,
5355
MdToolbarModule,
5456
MdTooltipModule,
@@ -83,6 +85,7 @@ const MATERIAL_MODULES = [
8385
MdRadioModule.forRoot(),
8486
MdSliderModule.forRoot(),
8587
MdSlideToggleModule.forRoot(),
88+
MdSnackBarModule.forRoot(),
8689
MdTooltipModule.forRoot(),
8790
OverlayModule.forRoot(),
8891
],

src/lib/snack-bar/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# MdSnackBar
2+
`MdSnackBar` is a service, which opens snack bar notifications in the view.
3+
4+
### Methods
5+
6+
| Name | Description |
7+
| --- | --- |
8+
| `open(message: string,<br> actionLabel: string, config: MdSnackBarConfig): MdSnackBarRef<SimpleSnackBar>` | Creates and opens a simple snack bar noticiation matching material spec. |
9+
| `openFromComponent(component: ComponentType<T>, config: MdSnackBarConfig): MdSnackBarRef<T>` | Creates and opens a snack bar noticiation with a custom component as content. |
10+
11+
### Config
12+
13+
| Key | Description |
14+
| --- | --- |
15+
| `viewContainerRef: ViewContainerRef` | The view container ref to attach the snack bar to. |
16+
| `role: AriaLivePoliteness = 'assertive'` | The politeness level to announce the snack bar with. |
17+
| `announcementMessage: string` | The message to announce with the snack bar. |
18+
19+
20+
### Example
21+
The service can be injected in a component.
22+
```ts
23+
@Component({
24+
selector: 'my-component'
25+
providers: [MdSnackBar]
26+
})
27+
export class MyComponent {
28+
29+
constructor(snackBar: MdSnackBar
30+
viewContainerRef: ViewContainerRef) {}
31+
32+
failedAttempt() {
33+
config = new MdSnackBarConfig(this.viewContainerRef);
34+
this.snackBar.open('It didn\'t quite work!', 'Try Again', config);
35+
}
36+
37+
}
38+
```

src/lib/snack-bar/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './snack-bar';

0 commit comments

Comments
 (0)