Skip to content

Commit d587abe

Browse files
CaerusKarutinayuangao
authored andcommitted
fix(divider): add inset styles for icons and lists in cards (#9242)
* Add mixin to dynamically apply inset divider offset based on the precursor in the list item * Add inset divider example using icons as precursor
1 parent 37575c9 commit d587abe

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

src/demo-app/list/list-demo.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h4 mat-line>{{message.from}}</h4>
3131
<span>{{message.subject}} -- </span>
3232
<span class="demo-secondary-text">{{message.message}}</span>
3333
</p>
34-
<mat-divider [inset]="true" *ngIf="!last"></mat-divider>
34+
<mat-divider inset *ngIf="!last"></mat-divider>
3535
</mat-list-item>
3636
<mat-divider></mat-divider>
3737
<mat-list-item *ngFor="let message of messages">
@@ -87,10 +87,11 @@ <h2>Nav lists</h2>
8787
</mat-list-item>
8888
</mat-nav-list>
8989
<mat-nav-list>
90-
<a mat-list-item *ngFor="let link of links" href="http://www.google.com">
90+
<a mat-list-item *ngFor="let link of links; last as last" href="http://www.google.com">
9191
<mat-icon mat-list-icon>folder</mat-icon>
9292
<span mat-line>{{ link.name }}</span>
9393
<span mat-line class="demo-secondary-text"> Description </span>
94+
<mat-divider inset *ngIf="!last"></mat-divider>
9495
</a>
9596
</mat-nav-list>
9697
<mat-nav-list dense>

src/lib/divider/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ ng_module(
1616
)
1717

1818

19+
sass_library(
20+
name = "divider_scss_lib",
21+
srcs = ["divider.scss"],
22+
deps = ["//src/lib/core:core_scss_lib"],
23+
)
24+
25+
1926
sass_binary(
2027
name = "divider_scss",
2128
src = "divider.scss",

src/lib/divider/divider.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
$mat-divider-width: 1px;
22
$mat-divider-inset-margin: 80px;
33

4+
// This mixin provides the correct offset for an inset divider based on the
5+
// size of the parent class (e.g. avatar vs icon)
6+
@mixin mat-inset-divider-offset($offset, $padding) {
7+
$mat-inset-divider-offset: #{(2 * $padding) + $offset};
8+
margin-left: $mat-inset-divider-offset;
9+
width: calc(100% - #{$mat-inset-divider-offset});
10+
11+
[dir='rtl'] & {
12+
margin-left: auto;
13+
margin-right: $mat-inset-divider-offset;
14+
}
15+
}
16+
417
.mat-divider {
518
display: block;
619
margin: 0;

src/lib/list/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ng_module(
2323
sass_binary(
2424
name = "list_scss",
2525
src = "list.scss",
26-
deps = ["//src/lib/core:core_scss_lib"],
26+
deps = ["//src/lib/core:core_scss_lib", "//src/lib/divider:divider_scss_lib"],
2727
)
2828

2929
# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.

src/lib/list/list.scss

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
@import '../core/style/variables';
22
@import '../core/style/list-common';
33
@import '../core/style/layout-common';
4+
@import '../divider/divider';
45

56

67
$mat-list-side-padding: 16px;
8+
$mat-list-icon-padding: 4px;
79
$mat-list-avatar-size: 40px;
810

911
// Normal list variables
@@ -129,6 +131,10 @@ $mat-list-item-inset-divider-offset: 72px;
129131
width: $mat-list-avatar-size;
130132
height: $mat-list-avatar-size;
131133
border-radius: 50%;
134+
135+
~ .mat-divider-inset {
136+
@include mat-inset-divider-offset($mat-list-avatar-size, $mat-list-side-padding);
137+
}
132138
}
133139

134140
.mat-list-icon {
@@ -138,29 +144,28 @@ $mat-list-item-inset-divider-offset: 72px;
138144
font-size: $icon-size;
139145
box-sizing: content-box;
140146
border-radius: 50%;
141-
padding: 4px;
147+
padding: $mat-list-icon-padding;
148+
149+
~ .mat-divider-inset {
150+
@include mat-inset-divider-offset($icon-size + (2 * $mat-list-icon-padding),
151+
$mat-list-side-padding);
152+
}
142153
}
143154

144155
.mat-divider {
145156
position: absolute;
146157
bottom: 0;
147158
left: 0;
148159
width: 100%;
160+
margin: 0;
149161

150162
[dir='rtl'] & {
151-
left: auto;
152-
right: 0;
163+
margin-left: auto;
164+
margin-right: 0;
153165
}
154166

155167
&.mat-divider-inset {
156-
left: $mat-list-item-inset-divider-offset;
157-
width: calc(100% - #{$mat-list-item-inset-divider-offset});
158-
margin: 0;
159-
160-
[dir='rtl'] & {
161-
left: auto;
162-
right: $mat-list-item-inset-divider-offset;
163-
}
168+
position: absolute; // necessary to override card styles
164169
}
165170
}
166171
}

0 commit comments

Comments
 (0)