@@ -97,13 +97,29 @@ $mat-typography-mdc-level-mappings: (
97
97
);
98
98
}
99
99
100
+ // MDC logs a warning if the `contrast-tone` function is called with a CSS variable.
101
+ // This function falls back to determining the tone based on whether the theme is light or dark.
102
+ @function _variable-safe-contrast-tone ($value , $is-dark ) {
103
+ @if ($value == ' dark' or $value == ' light' or type-of ($value ) == ' color' ) {
104
+ @return mdc-theme-color .contrast-tone ($value );
105
+ }
106
+
107
+ @return if ($is-dark , ' light' , ' dark' );
108
+ }
109
+
110
+ @function _variable-safe-ink-color-for-fill ($text-style , $fill-color , $is-dark ) {
111
+ $contrast-tone : _variable-safe-contrast-tone ($fill-color , $is-dark );
112
+ @return map .get (map .get (mdc-theme-color .$text-colors , $contrast-tone ), $text-style );
113
+ }
114
+
100
115
// Configures MDC's global variables to reflect the given theme, applies the given styles,
101
116
// then resets the global variables to prevent unintended side effects.
102
117
@mixin using-mdc-theme ($config ) {
103
118
$primary : theming .get-color-from-palette (map .get ($config , primary ));
104
119
$accent : theming .get-color-from-palette (map .get ($config , accent ));
105
120
$warn : theming .get-color-from-palette (map .get ($config , warn ));
106
121
$background-palette : map .get ($config , background );
122
+ $is-dark : map .get ($config , is-dark );
107
123
108
124
// Save the original values.
109
125
$orig-primary : mdc-theme-color .$primary ;
@@ -120,17 +136,17 @@ $mat-typography-mdc-level-mappings: (
120
136
// Set new values based on the given Angular Material theme.
121
137
mdc-theme-color .$primary : $primary ;
122
138
mdc-theme-color .$on-primary :
123
- if (mdc-theme-color . contrast-tone (mdc-theme-color .$primary ) == ' dark' , #000 , #fff );
139
+ if (_variable-safe- contrast-tone (mdc-theme-color .$primary , $is-dark ) == ' dark' , #000 , #fff );
124
140
mdc-theme-color .$secondary : $accent ;
125
141
mdc-theme-color .$on-secondary :
126
- if (mdc-theme-color . contrast-tone (mdc-theme-color .$secondary ) == ' dark' , #000 , #fff );
142
+ if (_variable-safe- contrast-tone (mdc-theme-color .$secondary , $is-dark ) == ' dark' , #000 , #fff );
127
143
mdc-theme-color .$background : theming .get-color-from-palette ($background-palette , background );
128
144
mdc-theme-color .$surface : theming .get-color-from-palette ($background-palette , card );
129
145
mdc-theme-color .$on-surface :
130
- if (mdc-theme-color . contrast-tone (mdc-theme-color .$surface ) == ' dark' , #000 , #fff );
146
+ if (_variable-safe- contrast-tone (mdc-theme-color .$surface , $is-dark ) == ' dark' , #000 , #fff );
131
147
mdc-theme-color .$error : $warn ;
132
148
mdc-theme-color .$on-error :
133
- if (mdc-theme-color . contrast-tone (mdc-theme-color .$error ) == ' dark' , #000 , #fff );
149
+ if (_variable-safe- contrast-tone (mdc-theme-color .$error , $is-dark ) == ' dark' , #000 , #fff );
134
150
mdc-theme-color .$property-values : (
135
151
// Primary
136
152
primary: mdc-theme-color .$primary ,
@@ -148,27 +164,27 @@ $mat-typography-mdc-level-mappings: (
148
164
on- error: mdc-theme-color .$on-error ,
149
165
// Text-primary on "background" background
150
166
text- primary- on- background:
151
- mdc-theme-color . ink-color-for-fill_ (primary , mdc-theme-color .$background ),
167
+ _variable-safe- ink-color-for-fill (primary , mdc-theme-color .$background , $is-dark ),
152
168
text- secondary- on- background:
153
- mdc-theme-color . ink-color-for-fill_ (secondary , mdc-theme-color .$background ),
169
+ _variable-safe- ink-color-for-fill (secondary , mdc-theme-color .$background , $is-dark ),
154
170
text- hint- on- background:
155
- mdc-theme-color . ink-color-for-fill_ (hint , mdc-theme-color .$background ),
171
+ _variable-safe- ink-color-for-fill (hint , mdc-theme-color .$background , $is-dark ),
156
172
text- disabled- on- background:
157
- mdc-theme-color . ink-color-for-fill_ (disabled , mdc-theme-color .$background ),
173
+ _variable-safe- ink-color-for-fill (disabled , mdc-theme-color .$background , $is-dark ),
158
174
text- icon- on- background:
159
- mdc-theme-color . ink-color-for-fill_ (icon , mdc-theme-color .$background ),
175
+ _variable-safe- ink-color-for-fill (icon , mdc-theme-color .$background , $is-dark ),
160
176
// Text-primary on "light" background
161
- text- primary- on- light: mdc-theme-color . ink-color-for-fill_ (primary , light ),
162
- text- secondary- on- light: mdc-theme-color . ink-color-for-fill_ (secondary , light ),
163
- text- hint- on- light: mdc-theme-color . ink-color-for-fill_ (hint , light ),
164
- text- disabled- on- light: mdc-theme-color . ink-color-for-fill_ (disabled , light ),
165
- text- icon- on- light: mdc-theme-color . ink-color-for-fill_ (icon , light ),
177
+ text- primary- on- light: _variable-safe- ink-color-for-fill (primary , light , $is-dark ),
178
+ text- secondary- on- light: _variable-safe- ink-color-for-fill (secondary , light , $is-dark ),
179
+ text- hint- on- light: _variable-safe- ink-color-for-fill (hint , light , $is-dark ),
180
+ text- disabled- on- light: _variable-safe- ink-color-for-fill (disabled , light , $is-dark ),
181
+ text- icon- on- light: _variable-safe- ink-color-for-fill (icon , light , $is-dark ),
166
182
// Text-primary on "dark" background
167
- text- primary- on- dark: mdc-theme-color . ink-color-for-fill_ (primary , dark ),
168
- text- secondary- on- dark: mdc-theme-color . ink-color-for-fill_ (secondary , dark ),
169
- text- hint- on- dark: mdc-theme-color . ink-color-for-fill_ (hint , dark ),
170
- text- disabled- on- dark: mdc-theme-color . ink-color-for-fill_ (disabled , dark ),
171
- text- icon- on- dark: mdc-theme-color . ink-color-for-fill_ (icon , dark )
183
+ text- primary- on- dark: _variable-safe- ink-color-for-fill (primary , dark , $is- dark ),
184
+ text- secondary- on- dark: _variable-safe- ink-color-for-fill (secondary , dark , $is- dark ),
185
+ text- hint- on- dark: _variable-safe- ink-color-for-fill (hint , dark , $is- dark ),
186
+ text- disabled- on- dark: _variable-safe- ink-color-for-fill (disabled , dark , $is- dark ),
187
+ text- icon- on- dark: _variable-safe- ink-color-for-fill (icon , dark , $is- dark )
172
188
);
173
189
174
190
// Apply given rules.
0 commit comments