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 (Guides): Mat elevation guide #3917

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 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
33 changes: 33 additions & 0 deletions guides/mat-elevation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# mat-elevation
Copy link
Contributor

Choose a reason for hiding this comment

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

how do you feel about this?

# Elevation
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 best to 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 acheived 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 level of the element. In order to use the mixin you must import `~@angular/material/theming`.

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

.myClass {
  @include mat-elevation(2);

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

mat-elevation exists to give you separation between elements.
All material design elements have resting elevations.
[`Material design`](https://material.io/guidelines/material-design/elevation-shadows.html)
explains how best to use elevation.


Elevation is implemented with a class, simply adding the class `mat-elevation-z#` where # is the elevation number you want, 0-24.

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


## Mixins
In order to use the mixin for Elevation you must
`@import '~@angular/material/theming';`
$zValue must be a value between 0 and 24, inclusive.
`@include mat-elevation($zValue);`


How to use the mixin
```scss
.myClass {
@include $mat-elevation(2);

Choose a reason for hiding this comment

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

shouldn't this be without the $? -> @include mat-elevation(2);


&:active {
@include $mat-elevation(8);

Choose a reason for hiding this comment

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

same here

}
}
```

## Deprecated
The use of `mdElevation($zValue)` is deprecated.
Copy link
Member

Choose a reason for hiding this comment

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

Should we use the words attribute / directive in this text to be more clear?

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="dynamimc">Hover over me!</div>
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean dynamic?


<div class"no-elevation">No Elevation</div>
Copy link
Member

Choose a reason for hiding this comment

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

Does adding the no-elevation class here create confusion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point, I removed it in the next commit


<div class="mat-elevation-z24">Static class for styling</div>
20 changes: 20 additions & 0 deletions src/examples/elevation-overview/elevation-overview-example.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@import '~@angular/material/theming';

div {
width: auto;
display: block;
text-align: center;
height: 50px;
margin-left: auto;
margin-right: auto;
background-color: lightblue;
margin-top: 10px;
}

.dynamimc {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@include $mat-elevation(2);

Choose a reason for hiding this comment

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

Also without $ ? At least in my Project it won't compile with a $


&:active {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be &:hover?

@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.

newline

9 changes: 9 additions & 0 deletions src/examples/elevation-overview/elevation-overview-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Component} from '@angular/core';

@Component({
selector: 'elevation-overview-example',
styleUrls: ['./elevation-overview-example.scss'],
templateUrl: './elevation-overview-example.html',
})

export class ElevationOverviewExample {}