Skip to content

Commit 372436c

Browse files
mmalerbaandrewseguin
authored andcommitted
refactor(sidenav): split into drawer and sidenav (#6260)
* refactor(sidenav): split into drawer and sidenav * s/side/position * fix tests * fix bad rebase
1 parent 0f02a11 commit 372436c

13 files changed

+700
-619
lines changed

src/demo-app/sidenav/sidenav-demo.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2>Basic Use Case</h2>
1515
<input #myinput>
1616
</md-sidenav>
1717

18-
<md-sidenav #end align="end">
18+
<md-sidenav #end position="end">
1919
End Side Drawer
2020
<br>
2121
<button md-button (click)="end.close()">Close</button>
@@ -48,14 +48,14 @@ <h2>Sidenav Already Opened</h2>
4848
</div>
4949
</md-sidenav-container>
5050

51-
<h2>Dynamic Alignment Sidenav</h2>
51+
<h2>Dynamic Position Sidenav</h2>
5252

5353
<md-sidenav-container class="demo-sidenav-container">
54-
<md-sidenav #dynamicAlignSidenav1 mode="side" [align]="invert ? 'end' : 'start'">Start</md-sidenav>
55-
<md-sidenav #dynamicAlignSidenav2 mode="side" [align]="invert ? 'start' : 'end'">End</md-sidenav>
54+
<md-sidenav #dynamicPosSidenav1 mode="side" [position]="invert ? 'end' : 'start'">Start</md-sidenav>
55+
<md-sidenav #dynamicPosSidenav2 mode="side" [position]="invert ? 'start' : 'end'">End</md-sidenav>
5656

5757
<div class="demo-sidenav-content">
58-
<button (click)="dynamicAlignSidenav1.toggle(); dynamicAlignSidenav2.toggle()">
58+
<button (click)="dynamicPosSidenav1.toggle(); dynamicPosSidenav2.toggle()">
5959
Toggle sidenavs
6060
</button>
6161
<button (click)="invert = !invert">Change sides</button>

src/lib/sidenav/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The sidenav panel.
2323

2424
| Name | Type | Description |
2525
| --- | --- | --- |
26-
| `align` | `"start"\|"end"` | The alignment of this sidenav. In LTR direction, `"start"` will be shown on the left, `"end"` on the right. In RTL, it is reversed. `"start"` is used by default. If there is more than 1 sidenav on either side the container will be considered invalid and none of the sidenavs will be visible or toggleable until the container is valid again. |
26+
| `position` | `"start"\|"end"` | The position of this sidenav. In LTR direction, `"start"` will be shown on the left, `"end"` on the right. In RTL, it is reversed. `"start"` is used by default. If there is more than 1 sidenav on either side the container will be considered invalid and none of the sidenavs will be visible or toggleable until the container is valid again. |
2727
| `mode` | `"over"\|"push"\|"side"` | The mode or styling of the sidenav, default being `"over"`. With `"over"` the sidenav will appear above the content, and a backdrop will be shown. With `"push"` the sidenav will push the content of the `<md-sidenav-container>` to the side, and show a backdrop over it. `"side"` will resize the content and keep the sidenav opened. Clicking the backdrop will close sidenavs that do not have `mode="side"`. |
2828
| `opened` | `boolean` | Whether or not the sidenav is opened. Use this binding to open/close the sidenav. |
2929

@@ -68,7 +68,7 @@ Here's a simple example of using the sidenav:
6868
<br>
6969
<button md-button #closeStartButton (click)="start.close()">Close</button>
7070
</md-sidenav>
71-
<md-sidenav #end align="end">
71+
<md-sidenav #end position="end">
7272
End Sidenav.
7373
<button md-button (click)="end.close()">Close</button>
7474
</md-sidenav>

src/lib/sidenav/_sidenav-theme.scss

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
// We use invert() here to have the darken the background color expected to be used. If the
1313
// background is light, we use a dark backdrop. If the background is dark,
1414
// we use a light backdrop.
15-
$sidenav-backdrop-color: invert(mat-color($background, card, 0.6)) !default;
16-
$sidenav-background-color: mat-color($background, dialog) !default;
17-
$sidenav-container-background-color: mat-color($background, background) !default;
18-
$sidenav-push-background-color: mat-color($background, dialog) !default;
15+
$drawer-backdrop-color: invert(mat-color($background, card, 0.6)) !default;
16+
$drawer-background-color: mat-color($background, dialog) !default;
17+
$drawer-container-background-color: mat-color($background, background) !default;
18+
$drawer-push-background-color: mat-color($background, dialog) !default;
1919

20-
.mat-sidenav-container {
21-
background-color: $sidenav-container-background-color;
20+
.mat-drawer-container {
21+
background-color: $drawer-container-background-color;
2222
color: mat-color($foreground, text);
2323
}
2424

25-
.mat-sidenav {
26-
background-color: $sidenav-background-color;
25+
.mat-drawer {
26+
background-color: $drawer-background-color;
2727
color: mat-color($foreground, text);
2828

29-
&.mat-sidenav-push {
30-
background-color: $sidenav-push-background-color;
29+
&.mat-drawer-push {
30+
background-color: $drawer-push-background-color;
3131
}
3232
}
3333

34-
.mat-sidenav-backdrop.mat-sidenav-shown {
35-
background-color: $sidenav-backdrop-color;
34+
.mat-drawer-backdrop.mat-drawer-shown {
35+
background-color: $drawer-backdrop-color;
3636
}
3737
}
3838

src/lib/sidenav/drawer-container.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="mat-drawer-backdrop" (click)="_onBackdropClicked()"
2+
[class.mat-drawer-shown]="_isShowingBackdrop()"></div>
3+
4+
<ng-content select="md-drawer, mat-drawer, md-sidenav, mat-sidenav"></ng-content>
5+
6+
<div class="mat-drawer-content" [ngStyle]="_styles" cdk-scrollable>
7+
<ng-content></ng-content>
8+
</div>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Separate transitions to be able to disable them in unit tests by omitting this file.
22
@import '../core/style/variables';
33

4-
.mat-sidenav-transition {
5-
.mat-sidenav-content {
4+
.mat-drawer-transition {
5+
.mat-drawer-content {
66
transition: {
77
duration: $swift-ease-out-duration;
88
timing-function: $swift-ease-out-timing-function;
99
property: transform, margin-left, margin-right;
1010
}
1111
}
1212

13-
.mat-sidenav-backdrop.mat-sidenav-shown {
13+
.mat-drawer-backdrop.mat-drawer-shown {
1414
transition: background-color $swift-ease-out-duration $swift-ease-out-timing-function;
1515
}
1616
}
File renamed without changes.

src/lib/sidenav/sidenav.scss renamed to src/lib/sidenav/drawer.scss

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,40 @@
77
// Mixin that creates a new stacking context.
88
// see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
99
// stylelint-enable
10-
@mixin mat-sidenav-stacking-context() {
10+
@mixin mat-drawer-stacking-context() {
1111
position: relative;
1212

1313
// Use a transform to create a new stacking context.
1414
transform: translate3d(0, 0, 0);
1515
}
1616

17-
.mat-sidenav-container {
17+
.mat-drawer-container {
1818
// We need a stacking context here so that the backdrop and drawers are clipped to the
19-
// MdSidenavContainer. This creates a new z-index stack so we use low numbered z-indices.
20-
// We create another stacking context in the '.mat-sidenav-content' and in each sidenav so that
19+
// MdDrawerContainer. This creates a new z-index stack so we use low numbered z-indices.
20+
// We create another stacking context in the '.mat-drawer-content' and in each drawer so that
2121
// the application content does not get messed up with our own CSS.
22-
@include mat-sidenav-stacking-context();
22+
@include mat-drawer-stacking-context();
2323

2424
box-sizing: border-box;
2525
-webkit-overflow-scrolling: touch;
2626

2727
// Need this to take up space in the layout.
2828
display: block;
2929

30-
// Hide the sidenavs when they're closed.
30+
// Hide the drawers when they're closed.
3131
overflow: hidden;
3232

3333
// TODO(hansl): Update this with a more robust solution.
3434
&[fullscreen] {
3535
@include mat-fill();
3636

37-
&.mat-sidenav-opened {
37+
&.mat-drawer-opened {
3838
overflow: hidden;
3939
}
4040
}
4141
}
4242

43-
.mat-sidenav-backdrop {
43+
.mat-drawer-backdrop {
4444
@include mat-fill();
4545

4646
display: block;
@@ -55,7 +55,7 @@
5555
// section.
5656
visibility: hidden;
5757

58-
&.mat-sidenav-shown {
58+
&.mat-drawer-shown {
5959
visibility: visible;
6060
}
6161

@@ -64,16 +64,16 @@
6464
}
6565
}
6666

67-
.mat-sidenav-content {
68-
@include mat-sidenav-stacking-context();
67+
.mat-drawer-content {
68+
@include mat-drawer-stacking-context();
6969

7070
display: block;
7171
height: 100%;
7272
overflow: auto;
7373
}
7474

75-
.mat-sidenav {
76-
@include mat-sidenav-stacking-context();
75+
.mat-drawer {
76+
@include mat-drawer-stacking-context();
7777

7878
display: block;
7979
position: absolute;
@@ -84,30 +84,30 @@
8484
outline: 0;
8585
box-sizing: border-box;
8686
height: 100%;
87-
overflow-y: auto; // TODO(kara): revisit scrolling behavior for sidenavs
87+
overflow-y: auto; // TODO(kara): revisit scrolling behavior for drawers
8888
transform: translate3d(-100%, 0, 0);
8989

90-
&.mat-sidenav-side {
90+
&.mat-drawer-side {
9191
z-index: 1;
9292
}
9393

94-
&.mat-sidenav-end {
94+
&.mat-drawer-end {
9595
right: 0;
9696
transform: translate3d(100%, 0, 0);
9797
}
9898

9999
[dir='rtl'] & {
100100
transform: translate3d(100%, 0, 0);
101101

102-
&.mat-sidenav-end {
102+
&.mat-drawer-end {
103103
left: 0;
104104
right: auto;
105105
transform: translate3d(-100%, 0, 0);
106106
}
107107
}
108108

109-
&.mat-sidenav-opening, &.mat-sidenav-opened {
110-
&:not(.mat-sidenav-side) {
109+
&.mat-drawer-opening, &.mat-drawer-opened {
110+
&:not(.mat-drawer-side) {
111111
// The elevation of z-16 is noted in the design specifications.
112112
// See https://material.io/guidelines/patterns/navigation-drawer.html#
113113
@include mat-elevation(16);

0 commit comments

Comments
 (0)