Skip to content

Commit fcb76d3

Browse files
authoredAug 23, 2024··
fix(material/core): add missing system variables (#29624)
1 parent 2f1fe03 commit fcb76d3

File tree

2 files changed

+93
-21
lines changed

2 files changed

+93
-21
lines changed
 

‎src/material/core/tokens/_m3-system.scss

+93-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
@use '../style/elevation';
22
@use '../style/sass-utils';
3-
@use './m3-tokens';
3+
@use '../theming/definition';
44
@use './m3/definitions';
55
@use 'sass:map';
6+
@use 'sass:meta';
7+
@use 'sass:list';
8+
@use './m3-tokens';
69

710
// Prefix used for component token fallback variables, e.g.
811
// `color: var(--mdc-text-button-label-text-color, var(--mat-app-primary));`
@@ -11,16 +14,74 @@ $_system-fallback-prefix: mat-app;
1114
// Default system level prefix to use when directly calling the `system-level-*` mixins
1215
$_system-level-prefix: sys;
1316

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);
2485
}
2586

2687
@mixin system-level-colors($theme, $overrides: (), $prefix: null) {
@@ -50,6 +111,13 @@ $_system-level-prefix: sys;
50111
definitions.md-sys-color-values-dark($ref),
51112
definitions.md-sys-color-values-light($ref));
52113

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+
53121
& {
54122
@each $name, $value in $sys-colors {
55123
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
@@ -84,35 +152,32 @@ $_system-level-prefix: sys;
84152
$shadow-color: map.get(
85153
$theme, _mat-theming-internals-do-not-access, color-tokens, (mdc, theme), shadow);
86154

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-
92155
@each $name, $value in definitions.md-sys-elevation-values() {
93156
$level: map.get($overrides, $name) or $value;
94157
$value: elevation.get-box-shadow($level, $shadow-color);
95-
--#{$prefix}-#{$name}: #{$value};
158+
& {
159+
--#{$prefix}-#{$name}: #{$value};
160+
}
96161
}
97162
}
98163

99-
@mixin system-level-shape($theme, $overrides: (), $prefix: $_system-level-prefix) {
164+
@mixin system-level-shape($theme: (), $overrides: (), $prefix: $_system-level-prefix) {
100165
& {
101166
@each $name, $value in definitions.md-sys-shape-values() {
102167
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
103168
}
104169
}
105170
}
106171

107-
@mixin system-level-state($theme, $overrides: (), $prefix: $_system-level-prefix) {
172+
@mixin system-level-state($theme: (), $overrides: (), $prefix: $_system-level-prefix) {
108173
& {
109174
@each $name, $value in definitions.md-sys-state-values() {
110175
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
111176
}
112177
}
113178
}
114179

115-
@mixin system-level-motion($theme, $overrides: (), $prefix: $_system-level-prefix) {
180+
@mixin system-level-motion($theme: (), $overrides: (), $prefix: $_system-level-prefix) {
116181
& {
117182
@each $name, $value in definitions.md-sys-motion-values() {
118183
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
@@ -146,6 +211,14 @@ $_system-level-prefix: sys;
146211
_create-system-app-vars-map(definitions.md-sys-state-values()),
147212
'md-sys-shape':
148213
_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+
),
149222
);
150223

151224
@return sass-utils.deep-merge-all(

‎src/material/core/tokens/m3/mat/_sidenav.scss

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ $prefix: (mat, sidenav);
2020
container-text-color: map.get($systems, md-sys-color, on-surface-variant),
2121
content-background-color: map.get($systems, md-sys-color, background),
2222
content-text-color: map.get($systems, md-sys-color, on-background),
23-
// TODO: This should be `md-sys-color` `scrim` but causes changes in clients.
2423
scrim-color: sass-utils.safe-color-change(
2524
map.get($systems, md-ref-palette, neutral-variant20), $alpha: 0.4),
2625
);

0 commit comments

Comments
 (0)
Please sign in to comment.