Skip to content

Commit c1f92cc

Browse files
committed
docs(material/theming): rewrite elevation guide
This change updates the elevation guide to be more clear, concise, and complete. The changes include: * Drop content about the general concept of elevation, deferring that to the Material Design spec. * Document the `overridable-elevation` mixin * Mention that the elevation CSS classes are emitted by `core-theme`. * Switch to `@use`
1 parent d030a87 commit c1f92cc

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

guides/elevation.md

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,73 @@
1-
# Setting Element Elevation
1+
# Applying Elevation
22

3-
Angular Material's elevation classes and mixins allow you to add separation between elements along
4-
the z-axis. All material design elements have resting elevations. In addition, some elements may
5-
change their elevation in response to user interaction. The
6-
[Material Design spec](https://material.io/design/environment/elevation.html)
7-
explains how to best use elevation.
3+
[The Material Design specification][material-elevation] gives guidance on expressing elevation on
4+
UI elements by adding shadows. Angular Material provides CSS classes and Sass mixins for adding
5+
these shadows.
86

9-
Angular Material provides two ways to control the elevation of elements: predefined CSS classes
10-
and mixins.
7+
[material-elevation]: https://material.io/design/environment/elevation.html
118

12-
## Predefined CSS classes
9+
## Elevation CSS classes
1310

14-
The easiest way to add elevation to an element is to simply add one of the predefined CSS classes
15-
`mat-elevation-z#` where `#` is the elevation number you want, 0-24. Dynamic elevation can be
16-
achieved by switching elevation classes:
11+
The `core-theme` Sass mixin, described in the [theming guide][], emits CSS classes for applying
12+
elevation. These classes follow the pattern `mat-elevation-z#`, where `#` is the elevation number
13+
you want, 0 to 24. These predefined classes use the CSS `box-shadow` settings defined by the
14+
Material Design specification.
15+
16+
You can dynamically change elevation on an element by swapping elevation CSS classes.
1717

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

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

24-
## Mixins
25-
26-
Elevations can also be added in CSS via the `mat-elevation` mixin, which takes a number 0-24
27-
indicating the elevation of the element as well as optional arguments for the elevation shadow's
28-
color tone and opacity.
24+
[theming-guide]: https://material.angular.io/guide/theming#applying-a-theme-to-components
2925

30-
Since an elevation shadow consists of multiple shadow components of varying opacities, the
31-
`$opacity` argument of the mixin is considered a factor by which to scale these initial values
32-
rather than an absolute value.
26+
## Elevation Sass mixins
3327

34-
In order to use the mixin, you must import `~@angular/material/theming`:
28+
In addition to the predefined CSS classes, you can apply elevation styles using the `elevation`
29+
Sass mixin. This mixin accepts a `$zValue`, an optional `$color`, and an optional `$opacity`. The
30+
`$zValue` is number from 0 to 24, representing the semantic elevation of the element, that controls
31+
the intensity of the box-shadow. You can use the `$color` and `$opacity` parameters to further
32+
customize the shadow appearance. Because an elevation shadow consists of multiple shadow components
33+
of varying opacities, the `$opacity` argument of the mixin acts as a factor by which to scale these
34+
initial values rather than an absolute value.
3535

3636
```scss
37-
@import '~@angular/material/theming';
37+
@use '~@angular/material' as mat;
3838

3939
.my-class-with-default-shadow {
4040
// Adds a shadow for elevation level 2 with default color and full opacity:
41-
@include mat-elevation(2);
41+
@include mat.elevation(2);
4242
}
4343

4444
.my-class-with-custom-shadow {
4545
// Adds a shadow for elevation level 2 with color #e91e63 and 80% of the default opacity:
46-
@include mat-elevation(2, #e91e63, 0.8);
46+
@include mat.elevation(2, #e91e63, 0.8);
4747
}
4848
```
4949

50-
For convenience, you can use the `mat-elevation-transition` mixin to add a transition when the
51-
elevation changes:
50+
### Overridable elevation
51+
52+
When authoring a component, you may want to specify a default elevation that the component consumer
53+
can override. You can accomplish this by using the `overridable-elevation` Sass mixin. This behaves
54+
identically to the `elevation` mixin, except that the styles only apply when the element does not
55+
have a CSS class matching the pattern `mat-elevation-z#`, as described in
56+
[Elevation CSS classes](#elevation-css-classes) above.
57+
58+
### Animating elevation
59+
60+
You can use the `elevation-transition` mixin to add a transition when elevation changes.
5261

5362
```scss
54-
@import '~@angular/material/theming';
63+
@use '~@angular/material' as mat;
5564

5665
.my-class {
57-
@include mat-elevation-transition;
58-
@include mat-elevation(2);
66+
@include mat.elevation-transition();
67+
@include mat.elevation(2);
5968

6069
&:active {
61-
@include mat-elevation(8);
70+
@include mat.elevation(8);
6271
}
6372
}
6473
```

0 commit comments

Comments
 (0)