Skip to content

Commit f1c0c09

Browse files
crisbetojelbourn
authored andcommitted
fix(material-experimental/mdc-card): not handling dark themes (#18938)
Fixes some variables for the MDC-based card not being set up to handle the theme colors properly. Also makes it easier to test outlined cards in the dev app. (cherry picked from commit 1c8a2c9)
1 parent e7a197a commit f1c0c09

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

src/dev-app/mdc-card/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ng_module(
1212
deps = [
1313
"//src/material-experimental/mdc-button",
1414
"//src/material-experimental/mdc-card",
15+
"//src/material-experimental/mdc-checkbox",
1516
"@npm//@angular/router",
1617
],
1718
)

src/dev-app/mdc-card/mdc-card-demo-module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
*/
88

99
import {NgModule} from '@angular/core';
10+
import {FormsModule} from '@angular/forms';
1011
import {MatCardModule} from '@angular/material-experimental/mdc-card';
1112
import {MatButtonModule} from '@angular/material-experimental/mdc-button';
13+
import {MatCheckboxModule} from '@angular/material-experimental/mdc-checkbox';
1214
import {RouterModule} from '@angular/router';
1315
import {MdcCardDemo} from './mdc-card-demo';
1416

1517
@NgModule({
1618
imports: [
1719
MatCardModule,
1820
MatButtonModule,
21+
MatCheckboxModule,
22+
FormsModule,
1923
RouterModule.forChild([{path: '', component: MdcCardDemo}]),
2024
],
2125
declarations: [MdcCardDemo],

src/dev-app/mdc-card/mdc-card-demo.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<div class="demo-card-container">
2+
<mat-checkbox [(ngModel)]="outlined">Use outlined cards</mat-checkbox>
23

34
<!-- TODO(jelbourn): re-add dividers and footers with progress bars once the MDC versions exist -->
4-
5-
<mat-card>
5+
<mat-card [class.mdc-card--outlined]="outlined">
66
Card with only text content
77
</mat-card>
88

9-
<mat-card>
9+
<mat-card [class.mdc-card--outlined]="outlined">
1010
<mat-card-content>
1111
Card with only <code>&lt;mat-card-content&gt;</code> and text content.
1212
</mat-card-content>
1313
</mat-card>
1414

15-
<mat-card>
15+
<mat-card [class.mdc-card--outlined]="outlined">
1616
<mat-card-subtitle>Subtitle</mat-card-subtitle>
1717
<mat-card-title>Card with title and footer</mat-card-title>
1818
<mat-card-content>
@@ -25,7 +25,7 @@
2525
</mat-card-actions>
2626
</mat-card>
2727

28-
<mat-card>
28+
<mat-card [class.mdc-card--outlined]="outlined">
2929
<mat-card-subtitle>Subtitle</mat-card-subtitle>
3030
<mat-card-title>Card with title, footer, and inset-divider</mat-card-title>
3131
<mat-card-content>
@@ -39,7 +39,7 @@
3939

4040
</mat-card>
4141

42-
<mat-card>
42+
<mat-card [class.mdc-card--outlined]="outlined">
4343
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
4444
<mat-card-title>Content Title</mat-card-title>
4545
<mat-card-content>
@@ -51,7 +51,7 @@
5151
</mat-card-actions>
5252
</mat-card>
5353

54-
<mat-card>
54+
<mat-card [class.mdc-card--outlined]="outlined">
5555
<mat-card-header>
5656
<img mat-card-avatar>
5757
<mat-card-title>Header title</mat-card-title>
@@ -63,7 +63,7 @@
6363
</mat-card-content>
6464
</mat-card>
6565

66-
<mat-card class="demo-card-blue mat-card-flat">
66+
<mat-card class="demo-card-blue mat-card-flat" [class.mdc-card--outlined]="outlined">
6767
<mat-card-title>Easily customizable</mat-card-title>
6868
<mat-card-actions>
6969
<button mat-button>First</button>
@@ -74,7 +74,7 @@
7474
<hr>
7575
<h2>Cards with media area</h2>
7676

77-
<mat-card>
77+
<mat-card [class.mdc-card--outlined]="outlined">
7878
<mat-card-title-group>
7979
<mat-card-title>Card</mat-card-title>
8080
<mat-card-subtitle>Small</mat-card-subtitle>
@@ -85,7 +85,7 @@ <h2>Cards with media area</h2>
8585
</mat-card-content>
8686
</mat-card>
8787

88-
<mat-card>
88+
<mat-card [class.mdc-card--outlined]="outlined">
8989
<mat-card-title-group>
9090
<mat-card-title>Card</mat-card-title>
9191
<mat-card-subtitle>Medium</mat-card-subtitle>
@@ -96,7 +96,7 @@ <h2>Cards with media area</h2>
9696
</mat-card-content>
9797
</mat-card>
9898

99-
<mat-card>
99+
<mat-card [class.mdc-card--outlined]="outlined">
100100
<mat-card-title-group>
101101
<mat-card-title>Card</mat-card-title>
102102
<mat-card-subtitle>Large</mat-card-subtitle>
@@ -107,7 +107,7 @@ <h2>Cards with media area</h2>
107107
</mat-card-content>
108108
</mat-card>
109109

110-
<mat-card>
110+
<mat-card [class.mdc-card--outlined]="outlined">
111111
<mat-card-title-group>
112112
<mat-card-title>Card</mat-card-title>
113113
<mat-card-subtitle>Extra large</mat-card-subtitle>

src/dev-app/mdc-card/mdc-card-demo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Component, ViewEncapsulation} from '@angular/core';
1515
encapsulation: ViewEncapsulation.None,
1616
})
1717
export class MdcCardDemo {
18+
outlined = false;
1819
longText = `Once upon a midnight dreary, while I pondered, weak and weary,
1920
Over many a quaint and curious volume of forgotten lore—
2021
While I nodded, nearly napping, suddenly there came a tapping,

src/material-experimental/mdc-card/_card-theme.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
@import '@material/card/mixins.import';
2+
@import '@material/theme/functions.import';
3+
@import '@material/card/variables.import';
24
@import '@material/typography/mixins.import';
35
@import '../mdc-helpers/mdc-helpers';
46

57
@mixin mat-mdc-card-theme($theme) {
68
$foreground: map-get($theme, foreground);
79
$is-dark-theme: map-get($theme, is-dark);
810

11+
$orig-mdc-card-action-icon-color: $mdc-card-action-icon-color;
12+
$orig-mdc-card-outline-color: $mdc-card-outline-color;
13+
914
@include mat-using-mdc-theme($theme) {
15+
$mdc-card-action-icon-color:
16+
rgba(mdc-theme-prop-value(on-surface), mdc-theme-text-emphasis(medium)) !global;
17+
$mdc-card-outline-color:
18+
mix(mdc-theme-prop-value(on-surface), mdc-theme-prop-value(surface), 12%) !global;
19+
1020
@include mdc-card-without-ripple($query: $mat-theme-styles-query);
1121

1222
// Card subtitles are an Angular Material construct (not MDC), so we explicitly set their
@@ -15,6 +25,9 @@
1525
color: mat-color($foreground, secondary-text);
1626
}
1727
}
28+
29+
$mdc-card-action-icon-color: $orig-mdc-card-action-icon-color !global;
30+
$mdc-card-outline-color: $orig-mdc-card-outline-color !global;
1831
}
1932

2033
@mixin mat-mdc-card-typography($config) {

0 commit comments

Comments
 (0)