Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(elevation): add guide for elevation helpers #8172

Merged
merged 3 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions guides/elevation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Angular Material's elevation classes and mixins allow you to add separation between elements along
the z-axis. All material design elements have resting elevations. In addition, some elements may
change their elevation in response to user interaction. The
[Material Design spec](https://material.io/guidelines/material-design/elevation-shadows.html)
explains how to best use elevation.

Angular Material provides two ways to control the elevation of elements: predefined CSS classes
and mixins.

### Predefined CSS classes

The easiest way to add elevation to an element is to simply add one of the predefined CSS classes
`mat-elevation-z#` where `#` is the elevation number you want, 0-24. Dynamic elevation can be
achieved by switching elevation classes:

```html
<div [class.mat-elevation-z2]="!isActive" [class.mat-elevation-z8]="isActive"></div>
```

<!-- example(elevation-overview) -->

### Mixins

Elevations can also be added in CSS via the `mat-elevation` mixin, which takes a number 0-24
indicating the elevation of the element. In order to use the mixin, you must import
`~@angular/material/theming`:

```scss
@import '~@angular/material/theming';

.my-class {
@include mat-elevation(2);
}
```

For convenience, you can use the `mat-elevation-transition` mixin to add a transition between
elevation changes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... add a transition when the elevation changes


```scss
@import '~@angular/material/theming';

.my-class {
@include mat-elevation-transition;
@include mat-elevation(2);

&:active {
@include mat-elevation(8);
}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add an embedded example here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't export very well to plunker will it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I forgot our examples use plain CSS

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.example-container {
padding: 16px;
margin-bottom: 16px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="example-container"
[class.mat-elevation-z2]="!isActive"
[class.mat-elevation-z8]="isActive">
Example
</div>

<button mat-button (click)="isActive = !isActive">Toggle Elevation</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Component} from '@angular/core';

/**
* @title Elevation CSS classes
*/
@Component({
selector: 'elevation-overview-example',
styleUrls: ['elevation-overview-example.css'],
templateUrl: 'elevation-overview-example.html',
})
export class ElevationOverviewExample {
isActive = false;
}
8 changes: 8 additions & 0 deletions src/material-examples/example-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {DialogContentExampleDialog,DialogContentExample} from './dialog-content/
import {DialogDataExampleDialog,DialogDataExample} from './dialog-data/dialog-data-example';
import {DialogElementsExampleDialog,DialogElementsExample} from './dialog-elements/dialog-elements-example';
import {DialogOverviewExampleDialog,DialogOverviewExample} from './dialog-overview/dialog-overview-example';
import {ElevationOverviewExample} from './elevation-overview/elevation-overview-example';
import {ExpansionOverviewExample} from './expansion-overview/expansion-overview-example';
import {ExpansionStepsExample} from './expansion-steps/expansion-steps-example';
import {MyTelInput,FormFieldCustomControlExample} from './form-field-custom-control/form-field-custom-control-example';
Expand Down Expand Up @@ -312,6 +313,12 @@ export const EXAMPLE_COMPONENTS = {
additionalFiles: ["dialog-overview-example-dialog.html"],
selectorName: 'DialogOverviewExample, DialogOverviewExampleDialog'
},
'elevation-overview': {
title: 'Elevation CSS classes',
component: ElevationOverviewExample,
additionalFiles: null,
selectorName: null
},
'expansion-overview': {
title: 'Basic expansion panel',
component: ExpansionOverviewExample,
Expand Down Expand Up @@ -785,6 +792,7 @@ export const EXAMPLE_LIST = [
DialogDataExampleDialog,DialogDataExample,
DialogElementsExampleDialog,DialogElementsExample,
DialogOverviewExampleDialog,DialogOverviewExample,
ElevationOverviewExample,
ExpansionOverviewExample,
ExpansionStepsExample,
MyTelInput,FormFieldCustomControlExample,
Expand Down