Skip to content

Commit 3b50d3d

Browse files
willshowellandrewseguin
authored andcommitted
docs(elevation): add guide for elevation helpers (#8172)
* docs(elevation): add guide for elevation helpers - Credit to @M-a-c for intitial version * Remove extra newlines * Address comments
1 parent c5eaa7c commit 3b50d3d

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

guides/elevation.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Angular Material's elevation classes and mixins allow you to add separation between elements along
2+
the z-axis. All material design elements have resting elevations. In addition, some elements may
3+
change their elevation in response to user interaction. The
4+
[Material Design spec](https://material.io/guidelines/material-design/elevation-shadows.html)
5+
explains how to best use elevation.
6+
7+
Angular Material provides two ways to control the elevation of elements: predefined CSS classes
8+
and mixins.
9+
10+
### Predefined CSS classes
11+
12+
The easiest way to add elevation to an element is to simply add one of the predefined CSS classes
13+
`mat-elevation-z#` where `#` is the elevation number you want, 0-24. Dynamic elevation can be
14+
achieved by switching elevation classes:
15+
16+
```html
17+
<div [class.mat-elevation-z2]="!isActive" [class.mat-elevation-z8]="isActive"></div>
18+
```
19+
20+
<!-- example(elevation-overview) -->
21+
22+
### Mixins
23+
24+
Elevations can also be added in CSS via the `mat-elevation` mixin, which takes a number 0-24
25+
indicating the elevation of the element. In order to use the mixin, you must import
26+
`~@angular/material/theming`:
27+
28+
```scss
29+
@import '~@angular/material/theming';
30+
31+
.my-class {
32+
@include mat-elevation(2);
33+
}
34+
```
35+
36+
For convenience, you can use the `mat-elevation-transition` mixin to add a transition when the
37+
elevation changes:
38+
39+
```scss
40+
@import '~@angular/material/theming';
41+
42+
.my-class {
43+
@include mat-elevation-transition;
44+
@include mat-elevation(2);
45+
46+
&:active {
47+
@include mat-elevation(8);
48+
}
49+
}
50+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.example-container {
2+
padding: 16px;
3+
margin-bottom: 16px;
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="example-container"
2+
[class.mat-elevation-z2]="!isActive"
3+
[class.mat-elevation-z8]="isActive">
4+
Example
5+
</div>
6+
7+
<button mat-button (click)="isActive = !isActive">Toggle Elevation</button>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component} from '@angular/core';
2+
3+
/**
4+
* @title Elevation CSS classes
5+
*/
6+
@Component({
7+
selector: 'elevation-overview-example',
8+
styleUrls: ['elevation-overview-example.css'],
9+
templateUrl: 'elevation-overview-example.html',
10+
})
11+
export class ElevationOverviewExample {
12+
isActive = false;
13+
}

src/material-examples/example-module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {DialogContentExampleDialog,DialogContentExample} from './dialog-content/
4545
import {DialogDataExampleDialog,DialogDataExample} from './dialog-data/dialog-data-example';
4646
import {DialogElementsExampleDialog,DialogElementsExample} from './dialog-elements/dialog-elements-example';
4747
import {DialogOverviewExampleDialog,DialogOverviewExample} from './dialog-overview/dialog-overview-example';
48+
import {ElevationOverviewExample} from './elevation-overview/elevation-overview-example';
4849
import {ExpansionOverviewExample} from './expansion-overview/expansion-overview-example';
4950
import {ExpansionStepsExample} from './expansion-steps/expansion-steps-example';
5051
import {MyTelInput,FormFieldCustomControlExample} from './form-field-custom-control/form-field-custom-control-example';
@@ -312,6 +313,12 @@ export const EXAMPLE_COMPONENTS = {
312313
additionalFiles: ["dialog-overview-example-dialog.html"],
313314
selectorName: 'DialogOverviewExample, DialogOverviewExampleDialog'
314315
},
316+
'elevation-overview': {
317+
title: 'Elevation CSS classes',
318+
component: ElevationOverviewExample,
319+
additionalFiles: null,
320+
selectorName: null
321+
},
315322
'expansion-overview': {
316323
title: 'Basic expansion panel',
317324
component: ExpansionOverviewExample,
@@ -785,6 +792,7 @@ export const EXAMPLE_LIST = [
785792
DialogDataExampleDialog,DialogDataExample,
786793
DialogElementsExampleDialog,DialogElementsExample,
787794
DialogOverviewExampleDialog,DialogOverviewExample,
795+
ElevationOverviewExample,
788796
ExpansionOverviewExample,
789797
ExpansionStepsExample,
790798
MyTelInput,FormFieldCustomControlExample,

0 commit comments

Comments
 (0)