-
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.
* Adds an initial implementation of the new `MatBottomSheet` service that allows users to display component-based or template-based bottom sheets. * Sets up the various boilerplate and infrastructure necessary for a new component. Note: this is an initial implementation that has the necessary functionality, styles and accessibility. More docs, examples and touch gestures will be added in a follow-up.
- Loading branch information
Showing
29 changed files
with
1,429 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,45 @@ | ||
<h1>Bottom sheet demo</h1> | ||
|
||
<button mat-raised-button color="primary" (click)="openComponent()">Open component sheet</button> | ||
<button mat-raised-button color="accent" (click)="openTemplate()">Open template sheet</button> | ||
|
||
<mat-card class="demo-dialog-card"> | ||
<mat-card-content> | ||
<h2>Options</h2> | ||
|
||
<p> | ||
<mat-checkbox [(ngModel)]="config.hasBackdrop">Has backdrop</mat-checkbox> | ||
</p> | ||
|
||
<p> | ||
<mat-checkbox [(ngModel)]="config.disableClose">Disable close</mat-checkbox> | ||
</p> | ||
|
||
<p> | ||
<mat-form-field> | ||
<input matInput [(ngModel)]="config.backdropClass" placeholder="Backdrop class"> | ||
</mat-form-field> | ||
</p> | ||
|
||
<p> | ||
<mat-form-field> | ||
<mat-select placeholder="Direction" [(ngModel)]="config.direction"> | ||
<mat-option value="ltr">LTR</mat-option> | ||
<mat-option value="rtl">RTL</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
</p> | ||
|
||
</mat-card-content> | ||
</mat-card> | ||
|
||
|
||
<ng-template let-bottomSheetRef="bottomSheetRef"> | ||
<mat-nav-list> | ||
<mat-list-item (click)="bottomSheetRef.dismiss()" *ngFor="let action of [1, 2, 3]"> | ||
<mat-icon mat-list-icon>folder</mat-icon> | ||
<span mat-line>Action {{ link }}</span> | ||
<span mat-line>Description</span> | ||
</mat-list-item> | ||
</mat-nav-list> | ||
</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,8 @@ | ||
.demo-dialog-card { | ||
max-width: 405px; | ||
margin: 20px 0; | ||
} | ||
|
||
.mat-raised-button { | ||
margin-right: 5px; | ||
} |
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,66 @@ | ||
/** | ||
* @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 {Component, ViewEncapsulation, TemplateRef, ViewChild} from '@angular/core'; | ||
import { | ||
MatBottomSheet, | ||
MatBottomSheetRef, | ||
MatBottomSheetConfig, | ||
} from '@angular/material/bottom-sheet'; | ||
|
||
const defaultConfig = new MatBottomSheetConfig(); | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'bottom-sheet-demo', | ||
styleUrls: ['bottom-sheet-demo.css'], | ||
templateUrl: 'bottom-sheet-demo.html', | ||
encapsulation: ViewEncapsulation.None, | ||
preserveWhitespaces: false, | ||
}) | ||
export class BottomSheetDemo { | ||
config: MatBottomSheetConfig = { | ||
hasBackdrop: defaultConfig.hasBackdrop, | ||
disableClose: defaultConfig.disableClose, | ||
backdropClass: defaultConfig.backdropClass, | ||
direction: 'ltr' | ||
}; | ||
|
||
@ViewChild(TemplateRef) template: TemplateRef<any>; | ||
|
||
constructor(private _bottomSheet: MatBottomSheet) {} | ||
|
||
openComponent() { | ||
this._bottomSheet.open(ExampleBottomSheet, this.config); | ||
} | ||
|
||
openTemplate() { | ||
this._bottomSheet.open(this.template, this.config); | ||
} | ||
} | ||
|
||
|
||
@Component({ | ||
template: ` | ||
<mat-nav-list> | ||
<a href="#" mat-list-item (click)="handleClick($event)" *ngFor="let action of [1, 2, 3]"> | ||
<mat-icon mat-list-icon>folder</mat-icon> | ||
<span mat-line>Action {{ link }}</span> | ||
<span mat-line>Description</span> | ||
</a> | ||
</mat-nav-list> | ||
` | ||
}) | ||
export class ExampleBottomSheet { | ||
constructor(private sheet: MatBottomSheetRef) {} | ||
|
||
handleClick(event: MouseEvent) { | ||
event.preventDefault(); | ||
this.sheet.dismiss(); | ||
} | ||
} |
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
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,38 @@ | ||
package(default_visibility=["//visibility:public"]) | ||
load("@angular//:index.bzl", "ng_module") | ||
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary") | ||
|
||
|
||
ng_module( | ||
name = "bottom-sheet", | ||
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), | ||
module_name = "@angular/material/bottom_sheet", | ||
assets = [ | ||
":bottom_sheet_container_css", | ||
], | ||
deps = [ | ||
"//src/lib/core", | ||
"//src/cdk/a11y", | ||
"//src/cdk/overlay", | ||
"//src/cdk/portal", | ||
"//src/cdk/layout", | ||
"@rxjs", | ||
], | ||
tsconfig = ":tsconfig-build.json", | ||
) | ||
|
||
|
||
sass_binary( | ||
name = "bottom_sheet_container_scss", | ||
src = "bottom-sheet-container.scss", | ||
deps = ["//src/lib/core:core_scss_lib"], | ||
) | ||
|
||
# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir. | ||
# Copy the output of the sass_binary such that the filename and path match what we expect. | ||
genrule( | ||
name = "bottom_sheet_container_css", | ||
srcs = [":bottom_sheet_container_scss"], | ||
outs = ["bottom-sheet-container.css"], | ||
cmd = "cat $(locations :bottom_sheet_container_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 @@ | ||
Please see the official documentation at https://material.angular.io/components/component/bottom-sheet |
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,21 @@ | ||
@import '../core/typography/typography-utils'; | ||
@import '../core/theming/palette'; | ||
|
||
@mixin mat-bottom-sheet-theme($theme) { | ||
$background: map-get($theme, background); | ||
$foreground: map-get($theme, foreground); | ||
|
||
.mat-bottom-sheet-container { | ||
background: mat-color($background, dialog); | ||
color: mat-color($foreground, text); | ||
} | ||
} | ||
|
||
@mixin mat-bottom-sheet-typography($config) { | ||
.mat-bottom-sheet-container { | ||
// Note: we don't use the line-height, because it's way too big. | ||
font-family: mat-font-family($config); | ||
font-size: mat-font-size($config, subheading-2); | ||
font-weight: mat-font-weight($config, subheading-2); | ||
} | ||
} |
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,31 @@ | ||
/** | ||
* @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 { | ||
animate, | ||
state, | ||
style, | ||
transition, | ||
trigger, | ||
AnimationTriggerMetadata, | ||
} from '@angular/animations'; | ||
import {AnimationCurves, AnimationDurations} from '@angular/material/core'; | ||
|
||
/** Animations used by the Material bottom sheet. */ | ||
export const matBottomSheetAnimations: { | ||
readonly bottomSheetState: AnimationTriggerMetadata; | ||
} = { | ||
/** Animation that shows and hides a bottom sheet. */ | ||
bottomSheetState: trigger('state', [ | ||
state('void, hidden', style({transform: 'translateY(100%)'})), | ||
state('visible', style({transform: 'translateY(0%)'})), | ||
transition('visible => void, visible => hidden', | ||
animate(`${AnimationDurations.COMPLEX} ${AnimationCurves.ACCELERATION_CURVE}`)), | ||
transition('void => visible', | ||
animate(`${AnimationDurations.EXITING} ${AnimationCurves.DECELERATION_CURVE}`)), | ||
]) | ||
}; |
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,42 @@ | ||
/** | ||
* @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 {ViewContainerRef, InjectionToken} from '@angular/core'; | ||
import {Direction} from '@angular/cdk/bidi'; | ||
|
||
/** Injection token that can be used to access the data that was passed in to a bottom sheet. */ | ||
export const MAT_BOTTOM_SHEET_DATA = new InjectionToken<any>('MatBottomSheetData'); | ||
|
||
/** | ||
* Configuration used when opening a bottom sheet. | ||
*/ | ||
export class MatBottomSheetConfig<D = any> { | ||
/** The view container to place the overlay for the bottom sheet into. */ | ||
viewContainerRef?: ViewContainerRef; | ||
|
||
/** Extra CSS classes to be added to the bottom sheet container. */ | ||
panelClass?: string | string[]; | ||
|
||
/** Text layout direction for the bottom sheet. */ | ||
direction?: Direction = 'ltr'; | ||
|
||
/** Data being injected into the child component. */ | ||
data?: D | null = null; | ||
|
||
/** Whether the bottom sheet has a backdrop. */ | ||
hasBackdrop?: boolean = true; | ||
|
||
/** Custom class for the backdrop. */ | ||
backdropClass?: string; | ||
|
||
/** Whether the user can use escape or clicking outside to close the bottom sheet. */ | ||
disableClose?: boolean = false; | ||
|
||
/** Aria label to assign to the bottom sheet element. */ | ||
ariaLabel?: string | null = null; | ||
} |
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 @@ | ||
<ng-template cdkPortalOutlet></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,31 @@ | ||
@import '../core/style/elevation'; | ||
|
||
// The bottom sheet minimum width on larger screen sizes is based | ||
// on increments of the toolbar, according to the spec. See: | ||
// https://material.io/guidelines/components/bottom-sheets.html#bottom-sheets-specs | ||
$_mat-bottom-sheet-width-increment: 64px; | ||
$mat-bottom-sheet-container-vertical-padding: 8px !default; | ||
$mat-bottom-sheet-container-horizontal-padding: 16px !default; | ||
|
||
.mat-bottom-sheet-container { | ||
@include mat-elevation(16); | ||
|
||
padding: $mat-bottom-sheet-container-vertical-padding | ||
$mat-bottom-sheet-container-horizontal-padding; | ||
min-width: 100vw; | ||
box-sizing: border-box; | ||
display: block; | ||
outline: 0; | ||
} | ||
|
||
.mat-bottom-sheet-container-medium { | ||
min-width: $_mat-bottom-sheet-width-increment * 6; | ||
} | ||
|
||
.mat-bottom-sheet-container-large { | ||
min-width: $_mat-bottom-sheet-width-increment * 8; | ||
} | ||
|
||
.mat-bottom-sheet-container-xlarge { | ||
min-width: $_mat-bottom-sheet-width-increment * 9; | ||
} |
Oops, something went wrong.