Skip to content

Commit 0a9c169

Browse files
committed
feat(list): support subheaders in lists
1 parent 25077be commit 0a9c169

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

src/components/list/list.scss

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "variables";
2+
@import "default-theme";
23

34
$md-list-side-padding: 16px;
45
$md-list-avatar-size: 40px;
@@ -25,7 +26,7 @@ $md-dense-three-line-height: 76px;
2526

2627
/*
2728
This mixin provides all list-item styles, changing font size and height
28-
based on whether the list is in "dense" mode.
29+
based on whether the list is in dense mode.
2930
*/
3031
@mixin md-list-item-base($font-size, $base-height, $avatar-height,
3132
$two-line-height, $three-line-height) {
@@ -86,7 +87,7 @@ based on whether the list is in "dense" mode.
8687

8788
/*
8889
This mixin provides all md-line styles, changing secondary font size
89-
based on whether the list is in "dense" mode.
90+
based on whether the list is in dense mode.
9091
*/
9192
@mixin md-line-base($secondary-font-size) {
9293

@@ -104,10 +105,39 @@ based on whether the list is in "dense" mode.
104105
}
105106
}
106107

108+
/*
109+
This mixin provides all subheader styles, adjusting heights and padding
110+
based on whether the list is in dense mode.
111+
*/
112+
@mixin md-subheader-base($top-padding, $secondary-size, $base-height) {
113+
display: block;
114+
box-sizing: border-box;
115+
height: $base-height;
116+
padding: $md-list-side-padding;
117+
margin: 0;
118+
119+
font-size: $secondary-size;
120+
font-weight: 500;
121+
color: md-color($md-foreground, secondary-text);
122+
123+
&:first-child {
124+
margin-top: -$top-padding;
125+
}
126+
}
127+
107128
md-list {
108129
padding-top: $md-list-top-padding;
109130
display: block;
110131

132+
[md-subheader] {
133+
@include md-subheader-base(
134+
$md-list-top-padding,
135+
$md-list-secondary-font,
136+
$md-list-base-height
137+
);
138+
}
139+
140+
111141
md-list-item {
112142
@include md-list-item-base(
113143
$md-list-font-size,
@@ -126,6 +156,13 @@ md-list[dense] {
126156
padding-top: $md-dense-top-padding;
127157
display: block;
128158

159+
[md-subheader] {
160+
@include md-subheader-base(
161+
$md-dense-top-padding,
162+
$md-dense-font-size,
163+
$md-dense-base-height
164+
);
165+
}
129166

130167
md-list-item {
131168
@include md-list-item-base(

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ <h1>md-list demo</h1>
88
<h2>Normal lists</h2>
99

1010
<md-list>
11+
<h3 md-subheader>Items</h3>
1112
<md-list-item *ngFor="#item of items">
1213
{{item}}
1314
</md-list-item>
@@ -22,19 +23,20 @@ <h3 md-line>{{contact.name}}</h3>
2223
</md-list>
2324

2425
<md-list>
26+
<h3 md-subheader>Today</h3>
2527
<md-list-item *ngFor="#message of messages">
2628
<img md-list-avatar [src]="message.image" alt="Image of {{message.from}}">
27-
<h3 md-line>{{message.from}}</h3>
29+
<h4 md-line>{{message.from}}</h4>
2830
<p md-line>
2931
<span>{{message.subject}} -- </span>
3032
<span class="demo-secondary-text">{{message.message}}</span>
3133
</p>
3234
</md-list-item>
3335
</md-list>
34-
36+
3537
<md-list>
3638
<md-list-item *ngFor="#message of messages">
37-
<h3 md-line>{{message.from}}</h3>
39+
<h4 md-line>{{message.from}}</h4>
3840
<p md-line> {{message.subject}} </p>
3941
<p md-line class="demo-secondary-text">{{message.message}} </p>
4042
</md-list-item>
@@ -44,6 +46,7 @@ <h3 md-line>{{message.from}}</h3>
4446
<div>
4547
<h2>Dense lists</h2>
4648
<md-list dense>
49+
<h3 md-subheader>Items</h3>
4750
<md-list-item *ngFor="#item of items">
4851
{{item}}
4952
</md-list-item>
@@ -57,9 +60,10 @@ <h3 md-line>{{contact.name}}</h3>
5760
</md-list>
5861

5962
<md-list dense>
63+
<h3 md-subheader>Today</h3>
6064
<md-list-item *ngFor="#message of messages">
6165
<img md-list-avatar [src]="message.image" alt="Image of {{message.from}}">
62-
<h3 md-line>{{message.from}}</h3>
66+
<h4 md-line>{{message.from}}</h4>
6367
<p md-line> {{message.subject}} </p>
6468
<p md-line class="demo-secondary-text">{{message.message}} </p>
6569
</md-list-item>

src/demo-app/list/list-demo.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
display: flex;
55

66
md-list {
7-
border: 1px dotted gray;
7+
border: 1px solid rgba(0,0,0,0.12);
88
width: 350px;
9-
margin: 0 20px;
9+
margin: 20px;
1010

1111
}
1212
h2 {

0 commit comments

Comments
 (0)