1
1
@use ' ../style/elevation' ;
2
2
@use ' ../style/sass-utils' ;
3
- @use ' ./m3-tokens ' ;
3
+ @use ' ../theming/definition ' ;
4
4
@use ' ./m3/definitions' ;
5
5
@use ' sass:map' ;
6
+ @use ' sass:meta' ;
7
+ @use ' sass:list' ;
8
+ @use ' ./m3-tokens' ;
6
9
7
10
// Prefix used for component token fallback variables, e.g.
8
11
// `color: var(--mdc-text-button-label-text-color, var(--mat-app-primary));`
@@ -11,16 +14,74 @@ $_system-fallback-prefix: mat-app;
11
14
// Default system level prefix to use when directly calling the `system-level-*` mixins
12
15
$_system-level-prefix : sys;
13
16
14
- // Emits CSS variables for Material's system level values. Uses the
15
- // namespace prefix in $_system-fallback-prefix.
16
- // e.g. --mat-app-surface: #E5E5E5
17
- @mixin theme ($theme , $overrides : ()) {
18
- @include system-level-colors ($theme , $overrides , $_system-fallback-prefix );
19
- @include system-level-typography ($theme , $overrides , $_system-fallback-prefix );
20
- @include system-level-elevation ($theme , $overrides , $_system-fallback-prefix );
21
- @include system-level-shape ($theme , $overrides , $_system-fallback-prefix );
22
- @include system-level-motion ($theme , $overrides , $_system-fallback-prefix );
23
- @include system-level-state ($theme , $overrides , $_system-fallback-prefix );
17
+ /// Emits necessary CSS variables for Material's system level values for the values defined in the
18
+ /// config map. The config map can have values color, typography, and/or density.
19
+ ///
20
+ /// If the config map's color value is an Angular Material color palette, it will be used as the
21
+ /// primary and tertiary colors with a light theme type. Otherwise if the color value is a map,
22
+ /// it must have a `primary` value containing an Angular Material color palette, and optionally
23
+ /// a different `tertiary` palette (defaults to primary palette) and `theme-type` that is either
24
+ /// `light` or `dark` (defaults to light). Color variable definitions will not be emitted if there
25
+ /// are no color values in the config.
26
+ ///
27
+ /// If the config map's typography value is a font family string, it will be used as the
28
+ /// plain and brand font family with default bold, medium, and regular weights of 700, 500, and 400,
29
+ /// respectfully. Otherwise if the typography value is a map, it must have a `plain-family` font
30
+ /// family value, and optionally a different `brand-family` font family (defaults to the plain
31
+ /// value) and weights for `bold-weight` (default: 700), `bold-weight` (default: 500), and
32
+ /// `bold-weight` (default: 400). Typography variable definitions will not be emitted if there are
33
+ /// no typography values in the config.
34
+ ///
35
+ /// If the config map's density value is a number, it will be used as the density scale. Otherwise
36
+ /// if the density value is a map, it must have a `scale` value. Density variable definitions will
37
+ /// not be emitted if there are no density values in the config.
38
+ ///
39
+ /// The application variables emitted use the namespace prefix "--mat-app".
40
+ /// e.g. --mat-app-surface: #E5E5E5
41
+ ///
42
+ /// @param {Map} $config The color configuration with optional keys color, typography, or density.
43
+ @mixin theme ($config , $overrides : ()) {
44
+ $color : map .get ($config , color );
45
+ $color-config : null;
46
+ @if ($color ) {
47
+ $color-config : if (meta .type-of ($color ) == ' map' ,
48
+ definition .define-colors ($color ),
49
+ definition .define-colors ((primary: $color )));
50
+ @include system-level-colors ($color-config , $overrides , $_system-fallback-prefix );
51
+ @include system-level-elevation ($color-config , $overrides , $_system-fallback-prefix );
52
+ }
53
+
54
+ $typography : map .get ($config , typography );
55
+ $typography-config : null;
56
+ @if ($typography ) {
57
+ $typography-config : if (meta .type-of ($typography ) == ' map' ,
58
+ definition .define-typography ($typography ),
59
+ definition .define-typography ((plain- family: $typography )));
60
+ @include system-level-typography ($typography-config , $overrides , $_system-fallback-prefix );
61
+ }
62
+
63
+ $density : map .get ($config , density );
64
+ $density-config : null;
65
+ @if ($density ) {
66
+ $density-config : if (meta .type-of ($density ) == ' map' ,
67
+ definition .define-density ($density ),
68
+ definition .define-density ((scale : $density )));
69
+ $scale : map .get ($density-config , _mat-theming-internals-do-not-access , density-scale );
70
+ @if ($scale != 0 ) {
71
+ $all-tokens : m3-tokens .generate-density-tokens ($scale );
72
+ @each $component-tokens in $all-tokens {
73
+ $namespace : list .nth ($component-tokens , 1 );
74
+ @each $tokens in list .nth ($component-tokens , 2 ) {
75
+ -- #{list .nth ($namespace , 1 )} - #{list .nth ($namespace , 2 )} - #{
76
+ list .nth ($tokens , 1 )} : #{list .nth ($tokens , 2 )} ;
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ @include system-level-shape ($overrides : $overrides , $prefix : $_system-fallback-prefix );
83
+ @include system-level-motion ($overrides :$overrides , $prefix : $_system-fallback-prefix );
84
+ @include system-level-state ($overrides : $overrides , $prefix : $_system-fallback-prefix );
24
85
}
25
86
26
87
@mixin system-level-colors ($theme , $overrides : (), $prefix : null) {
@@ -50,6 +111,13 @@ $_system-level-prefix: sys;
50
111
definitions .md-sys-color-values-dark ($ref ),
51
112
definitions .md-sys-color-values-light ($ref ));
52
113
114
+ // Manually insert a subset of palette values that are used directly by components
115
+ // instead of system variables.
116
+ $sys-colors : map .set ($sys-colors ,
117
+ ' neutral-variant20' , map .get ($ref , md-ref-palette , neutral-variant20 ));
118
+ $sys-colors : map .set ($sys-colors ,
119
+ ' neutral10' , map .get ($ref , md-ref-palette , neutral10 ));
120
+
53
121
& {
54
122
@each $name , $value in $sys-colors {
55
123
-- #{$prefix } - #{$name } : #{map .get ($overrides , $name ) or $value } ;
@@ -84,35 +152,32 @@ $_system-level-prefix: sys;
84
152
$shadow-color : map .get (
85
153
$theme , _mat-theming-internals-do-not-access , color-tokens , (mdc, theme), shadow );
86
154
87
- @for $level from 0 through 24 {
88
- $value : elevation .get-box-shadow ($level , $shadow-color );
89
- -- #{$prefix } -elevation-shadow-level- #{$level } : #{$value } ;
90
- }
91
-
92
155
@each $name , $value in definitions .md-sys-elevation-values () {
93
156
$level : map .get ($overrides , $name ) or $value ;
94
157
$value : elevation .get-box-shadow ($level , $shadow-color );
95
- -- #{$prefix } - #{$name } : #{$value } ;
158
+ & {
159
+ -- #{$prefix } - #{$name } : #{$value } ;
160
+ }
96
161
}
97
162
}
98
163
99
- @mixin system-level-shape ($theme , $overrides : (), $prefix : $_system-level-prefix ) {
164
+ @mixin system-level-shape ($theme : () , $overrides : (), $prefix : $_system-level-prefix ) {
100
165
& {
101
166
@each $name , $value in definitions .md-sys-shape-values () {
102
167
-- #{$prefix } - #{$name } : #{map .get ($overrides , $name ) or $value } ;
103
168
}
104
169
}
105
170
}
106
171
107
- @mixin system-level-state ($theme , $overrides : (), $prefix : $_system-level-prefix ) {
172
+ @mixin system-level-state ($theme : () , $overrides : (), $prefix : $_system-level-prefix ) {
108
173
& {
109
174
@each $name , $value in definitions .md-sys-state-values () {
110
175
-- #{$prefix } - #{$name } : #{map .get ($overrides , $name ) or $value } ;
111
176
}
112
177
}
113
178
}
114
179
115
- @mixin system-level-motion ($theme , $overrides : (), $prefix : $_system-level-prefix ) {
180
+ @mixin system-level-motion ($theme : () , $overrides : (), $prefix : $_system-level-prefix ) {
116
181
& {
117
182
@each $name , $value in definitions .md-sys-motion-values () {
118
183
-- #{$prefix } - #{$name } : #{map .get ($overrides , $name ) or $value } ;
@@ -146,6 +211,14 @@ $_system-level-prefix: sys;
146
211
_create-system-app-vars-map (definitions .md-sys-state-values ()),
147
212
' md-sys-shape' :
148
213
_create-system-app-vars-map (definitions .md-sys-shape-values ()),
214
+ // Add a subset of palette-specific colors used by components instead of system values
215
+ ' md-ref-palette' :
216
+ _create-system-app-vars-map (
217
+ (
218
+ neutral10: ' ' , // Form field native select option text color
219
+ neutral- variant20: ' ' , // Sidenav scrim (container background shadow when opened),
220
+ )
221
+ ),
149
222
);
150
223
151
224
@return sass-utils .deep-merge-all (
0 commit comments