Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 85f3f5c

Browse files
committed
docs(elevation): Simplify README to follow proposed best practices (#826)
1 parent 092e47b commit 85f3f5c

File tree

1 file changed

+16
-111
lines changed

1 file changed

+16
-111
lines changed

packages/mdc-elevation/README.md

+16-111
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ path: /catalog/elevation/
1616
</a>
1717
</div>-->
1818

19-
MDC Elevation provides Sass mixins and CSS classes which are used to provide [shadows and
20-
elevation](https://material.io/guidelines/what-is-material/elevation-shadows.html) to our material
21-
components.
22-
23-
The elevation values are mapped out in a "z-space" and range from `0` to `24`.
24-
Our implementation is based on [Scott Hyndman's work](http://codepen.io/shyndman/full/ojxmdY/),
25-
which was created in collaboration with the designers on the Material Design team.
19+
Shadows provide important visual cues about objects’ depth and directional movement. They are the only visual cue indicating the amount of separation between surfaces. An object’s elevation determines the appearance of its shadow. The elevation values are mapped out in a "z-space" and range from `0` to `24`.
2620

2721
> **A note about "z-space"**: Within the spec, elevation is normally referred to as having a `dp`
2822
> value. In other words, how many "pixels" above the base material is a piece of material elevated.
@@ -50,124 +44,35 @@ npm install --save @material/elevation
5044

5145
## Usage
5246

53-
### Sass Mixin
54-
55-
MDC Elevation exports an `mdc-elevation` mixin which can be used to set the elevation on a selector.
56-
It works by assigning the correct elevation value to a selector's `box-shadow` property.
47+
### Sass Mixins, Variables, and Functions
5748

58-
`mdc-elevation` takes one `$z-value` argument which represents the z-space for that given elevation. For example, [cards](https://material.io/guidelines/components/cards.html) have a resting elevation of `2dp`. Implementing that using MDC Elevation looks like the following:
49+
| Mixin | Description |
50+
| ----------------------------------------------- | - |
51+
| `mdc-elevation($z-value)` | Sets the elevation to the z-space for that given elevation |
52+
| `mdc-elevation-transition($duration, $easing)` | Applies the correct css rules to transition an element between elevations |
5953

60-
```scss
61-
@import "@material/elevation/mixins";
62-
63-
.mdc-card {
64-
@include mdc-elevation(2);
65-
// ...
66-
}
67-
```
54+
| Variable | Description |
55+
| ------------------------------------------- | - |
56+
| `mdc-elevation-transition-duration` | Default duration value for elevation transitions |
57+
| `mdc-elevation-transition-timing-function` | Default easing value for elevation transitions |
6858

69-
It is also quite simple to alias common elevations throughout your application by leveraging this
70-
mixin to export classes:
71-
72-
```scss
73-
$elevations: (low, medium-low, medium, medium-high, high);
74-
75-
@for $i from 1 through length($elevations) {
76-
$elev: nth($elevations, $i);
77-
$z: $i * 2;
78-
.my-app-elevation--#{$elev} {
79-
@include mdc-elevation($z);
80-
}
81-
}
82-
```
83-
84-
Note that importing `mdc-elevation/mixins` does not output any CSS.
85-
86-
### CSS Classes
87-
88-
MDC Elevation also includes a CSS file that exports all z values as `mdc-elevation--z<N>` modifier
89-
classes that can be easily used within HTML.
90-
91-
> NOTE: dist/ dir will be available post-alpha in the distributed npm package.
92-
93-
```html
94-
<!-- in <head> -->
95-
<link rel="stylesheet" href="/path/to/mdc-elevation/dist/mdc-elevation.css">
96-
<!-- ... -->
97-
<!-- in <body> -->
98-
<p class="mdc-elevation--z2">Text that floats near the material surface</p>
99-
<p class="mdc-elevation--z18">Text that floats far away from the material surface</p>
100-
```
101-
102-
### Handling elevation transitions
103-
104-
MDC Elevation includes utilities for transitioning between elevations.
105-
106-
#### Sass functions/mixins
107-
108-
The `mdc-elevation-transition-rule` function takes an optional duration and optional easing curve and
109-
spits out a `transition` property value shorthand with `box-shadow` specified as the property, and
110-
either the supplied or default durations / easings for the transition.
111-
112-
You can also use the `mdc-elevation-transition` mixin - which takes the same arguments as the above
113-
function - to output a `transition` property with the correct values as well as a `will-change`
114-
property with `box-shadow` set.
115-
116-
```scss
117-
@import "@material/animation/variables";
118-
@import "@material/elevation/mixins";
119-
120-
.my-component {
121-
@include mdc-elevation(2);
122-
@include mdc-elevation-transition;
123-
124-
&--fast-transitions {
125-
transition: mdc-elevation-transition-rule(180ms);
126-
}
127-
128-
&--default-ease-transitions {
129-
transition: mdc-elevation-transition-rule($mdc-elevation-transition-duration, ease);
130-
}
131-
132-
&:focus {
133-
@include mdc-elevation(4);
134-
}
135-
136-
&:active {
137-
@include mdc-elevation(8);
138-
}
139-
}
140-
```
141-
142-
If you need more configurability over your transitions, you can easily accomplish this by using
143-
the `mdc-elevation-transition-rule` function in conjunctions with the exported sass variables that
144-
mdc-elevation exposes for purposes of transitioning.
59+
If you need more configurability over your transitions, use the `mdc-elevation-transition-rule` function in conjunction with the exported sass variables.
14560

14661
```scss
14762
.my-component-with-custom-transitions {
148-
@include mdc-elevation(2);
14963

15064
transition:
15165
mdc-elevation-transition-rule(),
15266
/* Configure opacity to use same duration and easing values as elevation */
15367
opacity $mdc-elevation-transition-duration $mdc-elevation-transition-timing-function;
15468
opacity: .7;
15569
will-change: $mdc-elevation-property, opacity;
156-
157-
&:hover {
158-
opacity: 1;
159-
}
160-
161-
&:active {
162-
@include mdc-elevation(6);
163-
}
16470
}
16571
```
16672

167-
#### CSS Classes
168-
169-
MDC Elevation also exports an `mdc-elevation-transition` CSS class which can be used within HTML.
73+
### CSS Classes
17074

171-
```html
172-
<p class="mdc-elevation-transition mdc-elevation--z2">My elevation will change at some point...</p>
173-
```
75+
| CSS Class | Description |
76+
| --------------------------- | - |
77+
| `mdc-elevation--z<N>` | Sets the elevation to the (N)dp, where 1 <= N <= 24. |
78+
| `mdc-elevation-transition` | Applies the correct css rules to transition an element between elevations. |

0 commit comments

Comments
 (0)