-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material-experimental/snack-bar): add MDC-based snack-bar (#19800)
* feat(material-experimental/snack-bar): add MDC-based snack-bar * prefix underscores for snackbar * remove underscore from simple snackbar interface * remove docs private from TextOnlySnackBar
- Loading branch information
1 parent
589c5b4
commit 3d1c539
Showing
46 changed files
with
1,736 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary") | ||
load("//tools:defaults.bzl", "ng_module") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ng_module( | ||
name = "mdc-snack-bar", | ||
srcs = glob(["**/*.ts"]), | ||
assets = [ | ||
"mdc-snack-bar-demo.html", | ||
":mdc_snack_bar_demo_scss", | ||
], | ||
deps = [ | ||
"//src/cdk/bidi", | ||
"//src/material-experimental/mdc-snack-bar", | ||
"//src/material/button", | ||
"//src/material/checkbox", | ||
"//src/material/form-field", | ||
"//src/material/input", | ||
"//src/material/select", | ||
"@npm//@angular/forms", | ||
"@npm//@angular/router", | ||
], | ||
) | ||
|
||
sass_binary( | ||
name = "mdc_snack_bar_demo_scss", | ||
src = "mdc-snack-bar-demo.scss", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @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 {NgModule} from '@angular/core'; | ||
import {MatSnackBarModule} from '@angular/material-experimental/mdc-snack-bar'; | ||
import {RouterModule} from '@angular/router'; | ||
import {MdcSnackBarDemo} from './mdc-snack-bar-demo'; | ||
import {CommonModule} from '@angular/common'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {MatButtonModule} from '@angular/material/button'; | ||
import {MatCheckboxModule} from '@angular/material/checkbox'; | ||
import {MatFormFieldModule} from '@angular/material/form-field'; | ||
import {MatInputModule} from '@angular/material/input'; | ||
import {MatSelectModule} from '@angular/material/select'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
MatSnackBarModule, | ||
CommonModule, | ||
FormsModule, | ||
MatButtonModule, | ||
MatCheckboxModule, | ||
MatFormFieldModule, | ||
MatInputModule, | ||
MatSelectModule, | ||
RouterModule.forChild([{path: '', component: MdcSnackBarDemo}]), | ||
], | ||
declarations: [MdcSnackBarDemo], | ||
}) | ||
export class MdcSnackBarDemoModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<h1>SnackBar demo</h1> | ||
<div> | ||
<div> | ||
Message: <mat-form-field><input matInput type="text" [(ngModel)]="message"></mat-form-field> | ||
</div> | ||
<div> | ||
<div>Position in page: </div> | ||
<mat-form-field> | ||
<mat-select [(ngModel)]="horizontalPosition"> | ||
<mat-option value="start">Start</mat-option> | ||
<mat-option value="end">End</mat-option> | ||
<mat-option value="left">Left</mat-option> | ||
<mat-option value="right">Right</mat-option> | ||
<mat-option value="center">Center</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
<mat-form-field> | ||
<mat-select [(ngModel)]="verticalPosition"> | ||
<mat-option value="top">Top</mat-option> | ||
<mat-option value="bottom">Bottom</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
</div> | ||
<div> | ||
<mat-checkbox [(ngModel)]="action"> | ||
<p *ngIf="!action">Show button on snack bar</p> | ||
<mat-form-field *ngIf="action"> | ||
<mat-label>Snack bar action label</mat-label> | ||
<input matInput | ||
type="text" | ||
[(ngModel)]="actionButtonLabel"> | ||
</mat-form-field> | ||
</mat-checkbox> | ||
</div> | ||
<div> | ||
<mat-checkbox [(ngModel)]="setAutoHide"> | ||
<p *ngIf="!setAutoHide">Auto hide after duration</p> | ||
<mat-form-field *ngIf="setAutoHide"> | ||
<mat-label>Auto hide duration in ms</mat-label> | ||
<input matInput | ||
type="number" | ||
[(ngModel)]="autoHide"> | ||
</mat-form-field> | ||
</mat-checkbox> | ||
</div> | ||
<p> | ||
<mat-checkbox [(ngModel)]="addExtraClass">Add extra class to container</mat-checkbox> | ||
</p> | ||
</div> | ||
|
||
<p> | ||
<button mat-raised-button (click)="open()">OPEN</button> | ||
</p> | ||
|
||
<button mat-raised-button (click)="openTemplate()">OPEN TEMPLATE</button> | ||
|
||
<ng-template #template> | ||
Template snack bar: {{message}} | ||
</ng-template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.demo-party .mdc-snackbar__surface { | ||
animation: demo-party 5000ms infinite; | ||
} | ||
|
||
@keyframes demo-party { | ||
0% { background: #00f; } | ||
10% { background: #8e44ad; } | ||
20% { background: #1abc9c; } | ||
30% { background: #d35400; } | ||
40% { background: #00f; } | ||
50% { background: #34495e; } | ||
60% { background: #00f; } | ||
70% { background: #2980b9; } | ||
80% { background: #f1c40f; } | ||
90% { background: #2980b9; } | ||
100% { background: #0ff; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @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 {Directionality} from '@angular/cdk/bidi'; | ||
import {Component, TemplateRef, ViewChild, ViewEncapsulation} from '@angular/core'; | ||
import {MatSnackBar} from '@angular/material-experimental/mdc-snack-bar'; | ||
import { | ||
MatSnackBarConfig, | ||
MatSnackBarHorizontalPosition, | ||
MatSnackBarVerticalPosition | ||
} from '@angular/material/snack-bar'; | ||
|
||
@Component({ | ||
selector: 'mdc-snack-bar-demo', | ||
templateUrl: 'mdc-snack-bar-demo.html', | ||
styleUrls: ['mdc-snack-bar-demo.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class MdcSnackBarDemo { | ||
|
||
@ViewChild('template') template: TemplateRef<any>; | ||
message = 'Snack Bar opened.'; | ||
actionButtonLabel = 'Retry'; | ||
action = false; | ||
setAutoHide = true; | ||
autoHide = 10000; | ||
addExtraClass = false; | ||
horizontalPosition: MatSnackBarHorizontalPosition = 'center'; | ||
verticalPosition: MatSnackBarVerticalPosition = 'bottom'; | ||
|
||
constructor(public snackBar: MatSnackBar, private _dir: Directionality) {} | ||
|
||
open() { | ||
const config = this._createConfig(); | ||
this.snackBar.open(this.message, this.action ? this.actionButtonLabel : undefined, config); | ||
} | ||
|
||
openTemplate() { | ||
const config = this._createConfig(); | ||
this.snackBar.openFromTemplate(this.template, config); | ||
} | ||
|
||
private _createConfig() { | ||
const config = new MatSnackBarConfig(); | ||
config.verticalPosition = this.verticalPosition; | ||
config.horizontalPosition = this.horizontalPosition; | ||
config.duration = this.setAutoHide ? this.autoHide : 0; | ||
config.panelClass = this.addExtraClass ? ['demo-party'] : undefined; | ||
config.direction = this._dir.value; | ||
return config; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.