Skip to content

Commit e5da5f5

Browse files
committed
fix(card): fixed card color when dark theme elevation is enabled
Ref #1075
1 parent 52c752d commit e5da5f5

File tree

3 files changed

+58
-28
lines changed

3 files changed

+58
-28
lines changed

packages/card/src/_mixins.scss

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,17 @@
7373
);
7474
}
7575
}
76-
@include rmd-theme(background-color, surface);
77-
@include rmd-theme(color, text-primary-on-background);
76+
@include rmd-card-theme(background-color);
77+
@include rmd-card-theme(color);
7878

7979
border-radius: $rmd-card-border-radius;
8080
display: inline-block;
8181

8282
&--shadowed {
8383
@include rmd-elevation($rmd-card-elevation);
84-
@include rmd-theme-dark-elevation($rmd-card-elevation);
8584
}
8685

8786
&--bordered {
88-
@include rmd-theme-dark-elevation-styles {
89-
@include rmd-theme-update-var(
90-
surface,
91-
$rmd-card-dark-elevation-bordered-background-color
92-
);
93-
}
94-
9587
border: $rmd-card-border-width solid $rmd-card-border-color;
9688
}
9789

packages/card/src/_variables.scss

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,52 @@
66
@import '~@react-md/divider/dist/variables';
77
@import '~@react-md/theme/dist/functions';
88

9+
/// The elevation to use for cards that are not raisable.
10+
/// @type Number
11+
$rmd-card-elevation: 2 !default;
12+
13+
/// The background color for a card in light themes.
14+
///
15+
/// @type Color
16+
/// @since 2.7.0
17+
$rmd-card-light-background-color: rmd-theme-var(surface) !default;
18+
19+
/// The background color for a card in dark themes when the
20+
/// `$rmd-theme-dark-elevation` feature flag is also enabled.
21+
///
22+
/// @see $rmd-theme-dark-elevation
23+
/// @require $rmd-theme-dark-elevation-colors
24+
/// @type Color
25+
/// @since 2.7.0
26+
$rmd-card-dark-elevation-background-color: map-get(
27+
$rmd-theme-dark-elevation-colors,
28+
$rmd-card-elevation
29+
);
30+
31+
/// @type Color
32+
/// @since 2.5.4
33+
/// @deprecated Use `$rmd-card-dark-elevation-color` instead starting with `v2.7.0`
34+
$rmd-card-dark-elevation-bordered-background-color: $rmd-card-dark-elevation-background-color;
35+
36+
/// The background color for a card in dark themes.
37+
///
38+
/// @type Color
39+
/// @since 2.7.0
40+
$rmd-card-dark-background-color: if(
41+
$rmd-theme-dark-elevation and $rmd-card-dark-elevation-background-color,
42+
$rmd-card-dark-elevation-background-color,
43+
rmd-theme-var(surface)
44+
) !default;
45+
946
/// The base background color to apply to cards.
1047
///
1148
/// @require rmd-theme-var
1249
/// @type Color
13-
$rmd-card-background-color: rmd-theme-var(surface) !default;
50+
$rmd-card-background-color: if(
51+
$rmd-theme-light,
52+
$rmd-card-light-background-color,
53+
$rmd-card-dark-background-color
54+
) !default;
1455

1556
/// The base primary text color to apply to cards.
1657
///
@@ -32,10 +73,6 @@ $rmd-card-secondary-color: if(
3273
rmd-theme-var(text-primary-on-dark)
3374
) !default;
3475

35-
/// The elevation to use for cards that are not raisable.
36-
/// @type Number
37-
$rmd-card-elevation: 2 !default;
38-
3976
/// The starting elevation for a raisable card.
4077
/// @type Number
4178
$rmd-card-base-elevation: 1 !default;
@@ -90,19 +127,6 @@ $rmd-card-border-color: rmd-divider-theme-var(background-color) !default;
90127
/// @type Number
91128
$rmd-card-border-width: $rmd-divider-size !default;
92129

93-
/// The background color to use for bordered cards when the
94-
/// `$rmd-theme-dark-elevation` variable is set to `true`. This basically
95-
/// overrides the `surface` color to be this value.
96-
///
97-
/// @see $rmd-theme-dark-elevation
98-
/// @require $rmd-theme-dark-elevation-colors
99-
/// @type Color
100-
/// @since 2.5.4
101-
$rmd-card-dark-elevation-bordered-background-color: map-get(
102-
$rmd-theme-dark-elevation-colors,
103-
$rmd-card-elevation
104-
);
105-
106130
/// A Map of all the "themeable" parts of the card package. Every key in this
107131
/// map will be used to create a css variable to dynamically update the values
108132
/// of the icon as needed.

packages/theme/src/_mixins.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@
169169
secondary-color,
170170
$rmd-theme-secondary-text-on-light-color
171171
);
172+
173+
@if $rmd-card-light-background-color != $rmd-card-dark-background-color {
174+
@include rmd-card-theme-update-var(
175+
background-color,
176+
$rmd-card-light-background-color
177+
);
178+
}
172179
}
173180

174181
@if mixin-exists(rmd-chip-theme-update-var) {
@@ -339,6 +346,13 @@
339346
secondary-color,
340347
$rmd-theme-secondary-text-on-dark-color
341348
);
349+
350+
@if $rmd-card-light-background-color != $rmd-card-dark-background-color {
351+
@include rmd-card-theme-update-var(
352+
background-color,
353+
$rmd-card-dark-background-color
354+
);
355+
}
342356
}
343357

344358
@if mixin-exists(rmd-chip-theme-update-var) {

0 commit comments

Comments
 (0)