1
1
// TODO(mmalerba): this file should be split into separate cohesive partials for things like
2
2
// "theming", "typography", "core".
3
- @use ' ../theming/inspection' ;
4
3
@use ' ../typography/typography' ;
5
4
@use ' @material/feature-targeting' as mdc-feature-targeting ;
6
5
@use ' @material/typography' as mdc-typography ;
7
6
@use ' @material/theme/theme-color' as mdc-theme-color ;
8
7
@use ' @material/theme/css' as mdc-theme-css ;
9
- @use ' sass:map' ;
10
8
@use ' sass:meta' ;
11
9
12
10
// A set of standard queries to use with MDC's queryable mixins.
@@ -16,71 +14,6 @@ $mdc-base-styles-without-animation-query:
16
14
$mdc-theme-styles-query : color ;
17
15
$mdc-typography-styles-query : typography;
18
16
19
- // Mappings from Angular Material's typography levels to MDC's typography levels.
20
- $mat-typography-mdc-level-mappings : (
21
- headline-1 : headline1,
22
- headline-2 : headline2,
23
- headline-3 : headline3,
24
- headline-4 : headline4,
25
- headline-5 : headline5,
26
- headline-6 : headline6,
27
- subtitle-1 : subtitle1,
28
- subtitle-2 : subtitle2,
29
- body-1 : body1,
30
- body-2 : body2,
31
- caption : caption ,
32
- button : button,
33
- overline : overline
34
- );
35
-
36
- // Converts an Angular Material typography level config to an MDC one.
37
- @function typography-level-config-to-mdc ($theme , $mat-level ) {
38
- $mdc-level : map .get ($mat-typography-mdc-level-mappings , $mat-level );
39
-
40
- $result-with-nulls : map .merge (
41
- if ($mdc-level ,
42
- map .get (mdc-typography .$styles , $mdc-level ),
43
- (
44
- text-decoration : none ,
45
- -moz-osx-font-smoothing : grayscale ,
46
- -webkit-font-smoothing : antialiased
47
- )),
48
- if ($mat-level ,
49
- (
50
- font-size : inspection .get-theme-typography ($theme , $mat-level , font-size ),
51
- line-height : inspection .get-theme-typography ($theme , $mat-level , line-height ),
52
- font-weight : inspection .get-theme-typography ($theme , $mat-level , font-weight ),
53
- letter-spacing : inspection .get-theme-typography ($theme , $mat-level , letter-spacing ),
54
- font-family : inspection .get-theme-typography ($theme , $mat-level , font-family ),
55
- // Angular Material doesn't use text-transform, so disable it.
56
- text-transform : none ,
57
- ),
58
- ()));
59
-
60
- // We need to strip out any keys with a null value. Leaving them in will cause MDC to emit CSS
61
- // variables with no fallback value, which breaks some builds.
62
- $result : ();
63
- @each $property , $value in $result-with-nulls {
64
- @if $value != null {
65
- $result : map .merge ($result , ($property : $value ));
66
- }
67
- }
68
- @return $result ;
69
- }
70
-
71
- // Converts an Angular Material typography config to an MDC one.
72
- @function typography-config-to-mdc ($theme ) {
73
- $mdc-config : ();
74
-
75
- @each $mat-level , $mdc-level in $mat-typography-mdc-level-mappings {
76
- $mdc-config : map .merge (
77
- $mdc-config ,
78
- ($mdc-level : typography-level-config-to-mdc ($theme , $mat-level )));
79
- }
80
-
81
- @return $mdc-config ;
82
- }
83
-
84
17
// MDC logs a warning if the `contrast-tone` function is called with a CSS variable.
85
18
// This function falls back to determining the tone based on whether the theme is light or dark.
86
19
@function variable-safe-contrast-tone ($value , $is-dark ) {
@@ -91,123 +24,6 @@ $mat-typography-mdc-level-mappings: (
91
24
@return if ($is-dark , ' light' , ' dark' );
92
25
}
93
26
94
- @function _variable-safe-ink-color-for-fill ($text-style , $fill-color , $is-dark ) {
95
- $contrast-tone : variable-safe-contrast-tone ($fill-color , $is-dark );
96
- @return map .get (map .get (mdc-theme-color .$text-colors , $contrast-tone ), $text-style );
97
- }
98
-
99
- // Configures MDC's global variables to reflect the given theme, applies the given styles,
100
- // then resets the global variables to prevent unintended side effects.
101
- @mixin using-mdc-theme ($theme ) {
102
- $primary : inspection .get-theme-color ($theme , primary );
103
- $accent : inspection .get-theme-color ($theme , accent );
104
- $warn : inspection .get-theme-color ($theme , warn );
105
- $is-dark : inspection .get-theme-type ($theme ) == dark ;
106
-
107
- // Save the original values.
108
- $orig-primary : mdc-theme-color .$primary ;
109
- $orig-on-primary : mdc-theme-color .$on-primary ;
110
- $orig-secondary : mdc-theme-color .$secondary ;
111
- $orig-on-secondary : mdc-theme-color .$on-secondary ;
112
- $orig-background : mdc-theme-color .$background ;
113
- $orig-surface : mdc-theme-color .$surface ;
114
- $orig-on-surface : mdc-theme-color .$on-surface ;
115
- $orig-error : mdc-theme-color .$error ;
116
- $orig-on-error : mdc-theme-color .$on-error ;
117
- $orig-property-values : mdc-theme-color .$property-values ;
118
-
119
- // Set new values based on the given Angular Material theme.
120
- mdc-theme-color .$primary : $primary ;
121
- mdc-theme-color .$on-primary :
122
- if (variable-safe-contrast-tone (mdc-theme-color .$primary , $is-dark ) == ' dark' , #000 , #fff );
123
- mdc-theme-color .$secondary : $accent ;
124
- mdc-theme-color .$on-secondary :
125
- if (variable-safe-contrast-tone (mdc-theme-color .$secondary , $is-dark ) == ' dark' , #000 , #fff );
126
- mdc-theme-color .$background : inspection .get-theme-color ($theme , background , background );
127
- mdc-theme-color .$surface : inspection .get-theme-color ($theme , background , card );
128
- mdc-theme-color .$on-surface :
129
- if (variable-safe-contrast-tone (mdc-theme-color .$surface , $is-dark ) == ' dark' , #000 , #fff );
130
- mdc-theme-color .$error : $warn ;
131
- mdc-theme-color .$on-error :
132
- if (variable-safe-contrast-tone (mdc-theme-color .$error , $is-dark ) == ' dark' , #000 , #fff );
133
- mdc-theme-color .$property-values : (
134
- // Primary
135
- primary: mdc-theme-color .$primary ,
136
- // Secondary
137
- secondary: mdc-theme-color .$secondary ,
138
- // Background
139
- background : mdc-theme-color .$background ,
140
- // Surface
141
- surface: mdc-theme-color .$surface ,
142
- // Error
143
- error: mdc-theme-color .$error ,
144
- on- primary: mdc-theme-color .$on-primary ,
145
- on- secondary: mdc-theme-color .$on-secondary ,
146
- on- surface: mdc-theme-color .$on-surface ,
147
- on- error: mdc-theme-color .$on-error ,
148
- // Text-primary on "background" background
149
- text- primary- on- background:
150
- _variable-safe-ink-color-for-fill (primary , mdc-theme-color .$background , $is-dark ),
151
- text- secondary- on- background:
152
- _variable-safe-ink-color-for-fill (secondary , mdc-theme-color .$background , $is-dark ),
153
- text- hint- on- background:
154
- _variable-safe-ink-color-for-fill (hint , mdc-theme-color .$background , $is-dark ),
155
- text- disabled- on- background:
156
- _variable-safe-ink-color-for-fill (disabled , mdc-theme-color .$background , $is-dark ),
157
- text- icon- on- background:
158
- _variable-safe-ink-color-for-fill (icon , mdc-theme-color .$background , $is-dark ),
159
- // Text-primary on "light" background
160
- text- primary- on- light: _variable-safe-ink-color-for-fill (primary , light , $is-dark ),
161
- text- secondary- on- light: _variable-safe-ink-color-for-fill (secondary , light , $is-dark ),
162
- text- hint- on- light: _variable-safe-ink-color-for-fill (hint , light , $is-dark ),
163
- text- disabled- on- light: _variable-safe-ink-color-for-fill (disabled , light , $is-dark ),
164
- text- icon- on- light: _variable-safe-ink-color-for-fill (icon , light , $is-dark ),
165
- // Text-primary on "dark" background
166
- text- primary- on- dark: _variable-safe-ink-color-for-fill (primary , dark , $is-dark ),
167
- text- secondary- on- dark: _variable-safe-ink-color-for-fill (secondary , dark , $is-dark ),
168
- text- hint- on- dark: _variable-safe-ink-color-for-fill (hint , dark , $is-dark ),
169
- text- disabled- on- dark: _variable-safe-ink-color-for-fill (disabled , dark , $is-dark ),
170
- text- icon- on- dark: _variable-safe-ink-color-for-fill (icon , dark , $is-dark )
171
- );
172
-
173
- // Apply given rules.
174
- @include disable-mdc-fallback-declarations {
175
- @content ;
176
- }
177
-
178
- // Reset the original values.
179
- mdc-theme-color .$primary : $orig-primary ;
180
- mdc-theme-color .$on-primary : $orig-on-primary ;
181
- mdc-theme-color .$secondary : $orig-secondary ;
182
- mdc-theme-color .$on-secondary : $orig-on-secondary ;
183
- mdc-theme-color .$background : $orig-background ;
184
- mdc-theme-color .$surface : $orig-surface ;
185
- mdc-theme-color .$on-surface : $orig-on-surface ;
186
- mdc-theme-color .$error : $orig-error ;
187
- mdc-theme-color .$on-error : $orig-on-error ;
188
- mdc-theme-color .$property-values : $orig-property-values ;
189
- }
190
-
191
- // Configures MDC's global variables to reflect the given typography config,
192
- // applies the given styles, then resets the global variables to prevent unintended side effects.
193
- @mixin using-mdc-typography ($theme ) {
194
- // Save the original values.
195
- $orig-mdc-typography-styles : mdc-typography .$styles ;
196
-
197
- // Set new values based on the given Angular Material typography configuration.
198
- @if inspection .theme-has ($theme , typography ) {
199
- mdc-typography .$styles : typography-config-to-mdc ($theme );
200
- }
201
-
202
- // Apply given rules.
203
- @include disable-mdc-fallback-declarations {
204
- @content ;
205
- }
206
-
207
- // Reset the original values.
208
- mdc-typography .$styles : $orig-mdc-typography-styles ;
209
- }
210
-
211
27
// Function to create an Angular Material typography config from MDC's predefined typography levels.
212
28
// This is used for components where we accidentally ended up supporting null typography configs
213
29
// that were silently falling back to MDC's typography. At the moment of writing this includes
0 commit comments