Skip to content

Commit 218b879

Browse files
authored
refactor: remove mdc-system terminology and maps (angular#31054)
* refactor: remove hardcode flag from m3 token maps * refactor: directly use palettes instead of a ref * refactor: directly use typography instead of a ref * refactor: remove m3 ref files * refactor: remove unused functions * refactor: lint * refactor: fix tests * refactor: continue using primary as a palette key * refactor: ensure some ref colors are included for select and sidenav
1 parent 8af89be commit 218b879

14 files changed

+370
-913
lines changed

src/material/core/theming/_definition.scss

+21-19
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,22 @@ $theme-version: 1;
5353
$system-variables-prefix: map.get($config, system-variables-prefix) or $system-level-prefix;
5454
sass-utils.$use-system-color-variables: map.get($config, use-system-variables) or false;
5555

56+
$palettes: (
57+
primary: map.remove($primary, neutral, neutral-variant, secondary),
58+
secondary: map.get($primary, secondary),
59+
tertiary: map.remove($tertiary, neutral, neutral-variant, secondary, error),
60+
neutral: map.get($primary, neutral),
61+
neutral-variant: map.get($primary, neutral-variant),
62+
error: map.get($primary, error),
63+
);
64+
5665
@return (
5766
$internals: (
5867
theme-version: $theme-version,
5968
theme-type: $type,
60-
palettes: (
61-
primary: map.remove($primary, neutral, neutral-variant, secondary),
62-
secondary: map.get($primary, secondary),
63-
tertiary: map.remove($tertiary, neutral, neutral-variant, secondary),
64-
neutral: map.get($primary, neutral),
65-
neutral-variant: map.get($primary, neutral-variant),
66-
error: map.get($primary, error),
67-
),
69+
palettes: $palettes,
6870
color-system-variables-prefix: $system-variables-prefix,
69-
color-tokens: m3-tokens.generate-color-tokens(
70-
$type, $primary, $tertiary, map.get($primary, error), $system-variables-prefix)
71+
color-tokens: m3-tokens.generate-color-tokens($type, $palettes, $system-variables-prefix)
7172
)
7273
);
7374
}
@@ -89,19 +90,20 @@ $theme-version: 1;
8990
$system-variables-prefix: map.get($config, system-variables-prefix) or $system-level-prefix;
9091
sass-utils.$use-system-typography-variables: map.get($config, use-system-variables) or false;
9192

93+
$typography: (
94+
plain: $plain,
95+
brand: $brand,
96+
bold: $bold,
97+
medium: $medium,
98+
regular: $regular,
99+
);
100+
92101
@return (
93102
$internals: (
94103
theme-version: $theme-version,
95-
font-definition: (
96-
plain: $plain,
97-
brand: $brand,
98-
bold: $bold,
99-
medium: $medium,
100-
regular: $regular,
101-
),
104+
font-definition: $typography,
102105
typography-system-variables-prefix: $system-variables-prefix,
103-
typography-tokens: m3-tokens.generate-typography-tokens(
104-
$brand, $plain, $bold, $medium, $regular, $system-variables-prefix)
106+
typography-tokens: m3-tokens.generate-typography-tokens($typography, $system-variables-prefix)
105107
)
106108
);
107109
}

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

+26-34
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@use '../style/sass-utils';
2020
@use '../theming/config-validation';
2121
@use '../theming/definition';
22+
@use '../theming/palettes';
2223
@use './m3';
2324
@use './m3-tokens';
2425
@use 'sass:list';
@@ -130,8 +131,14 @@
130131
/// change the primary color to red, use `mat.theme-overrides((primary: red));`
131132
@mixin theme-overrides($overrides, $prefix: definition.$system-fallback-prefix) {
132133
$sys-names: map-merge-all(
133-
m3.md-sys-color-values-light(),
134-
m3.md-sys-typescale-values(),
134+
m3.md-sys-color-values-light(palettes.$blue-palette),
135+
m3.md-sys-typescale-values((
136+
brand: (Roboto),
137+
plain: (Roboto),
138+
bold: 700,
139+
medium: 500,
140+
regular: 400
141+
)),
135142
m3.md-sys-elevation-values(),
136143
m3.md-sys-shape-values(),
137144
m3.md-sys-state-values());
@@ -147,35 +154,20 @@
147154

148155
@mixin system-level-colors($theme, $overrides: (), $prefix: null) {
149156
$palettes: map.get($theme, _mat-theming-internals-do-not-access, palettes);
150-
$base-palettes: (
151-
neutral: map.get($palettes, neutral),
152-
neutral-variant: map.get($palettes, neutral-variant),
153-
secondary: map.get($palettes, secondary),
154-
error: map.get($palettes, error),
155-
);
156-
157157
$type: map.get($theme, _mat-theming-internals-do-not-access, theme-type);
158-
$primary: map.merge(map.get($palettes, primary), $base-palettes);
159-
$tertiary: map.merge(map.get($palettes, tertiary), $base-palettes);
160-
$error: map.get($palettes, error);
161158

162159
@if (not $prefix) {
163160
$prefix: map.get($theme, _mat-theming-internals-do-not-access,
164161
color-system-variables-prefix) or definition.$system-level-prefix;
165162
}
166163

167-
$ref: (
168-
md-ref-palette: m3-tokens.generate-ref-palette-tokens($primary, $tertiary, $error)
169-
);
170164

171-
$sys-colors: _generate-sys-colors($ref, $type);
165+
$sys-colors: _generate-sys-colors($palettes, $type);
172166

173167
// Manually insert a subset of palette values that are used directly by components
174168
// instead of system variables.
175-
$sys-colors: map.set($sys-colors,
176-
'neutral-variant20', map.get($ref, md-ref-palette, neutral-variant20));
177-
$sys-colors: map.set($sys-colors,
178-
'neutral10', map.get($ref, md-ref-palette, neutral10));
169+
$sys-colors: map.set($sys-colors, neutral-variant20, map.get($palettes, neutral-variant, 20));
170+
$sys-colors: map.set($sys-colors, neutral10, map.get($palettes, neutral, 10));
179171

180172
& {
181173
@each $name, $value in $sys-colors {
@@ -184,13 +176,13 @@
184176
}
185177
}
186178

187-
@function _generate-sys-colors($ref, $type) {
188-
$light-sys-colors: m3.md-sys-color-values-light($ref);
179+
@function _generate-sys-colors($palettes, $type) {
180+
$light-sys-colors: m3.md-sys-color-values-light($palettes);
189181
@if ($type == light) {
190182
@return $light-sys-colors;
191183
}
192184

193-
$dark-sys-colors: m3.md-sys-color-values-dark($ref);
185+
$dark-sys-colors: m3.md-sys-color-values-dark($palettes);
194186
@if ($type == dark) {
195187
@return $dark-sys-colors;
196188
}
@@ -210,22 +202,14 @@
210202

211203
@mixin system-level-typography($theme, $overrides: (), $prefix: null) {
212204
$font-definition: map.get($theme, _mat-theming-internals-do-not-access, font-definition);
213-
$brand: map.get($font-definition, brand);
214-
$plain: map.get($font-definition, plain);
215-
$bold: map.get($font-definition, bold);
216-
$medium: map.get($font-definition, medium);
217-
$regular: map.get($font-definition, regular);
218-
$ref: (md-ref-typeface:
219-
m3-tokens.generate-ref-typeface-tokens($brand, $plain, $bold, $medium, $regular)
220-
);
221205

222206
@if (not $prefix) {
223207
$prefix: map.get($theme, _mat-theming-internals-do-not-access,
224208
typography-system-variables-prefix) or definition.$system-level-prefix;
225209
}
226210

227211
& {
228-
@each $name, $value in m3.md-sys-typescale-values($ref) {
212+
@each $name, $value in m3.md-sys-typescale-values($font-definition) {
229213
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
230214
}
231215
}
@@ -275,11 +259,19 @@
275259
// system fallback variables referencing Material's system keys.
276260
// Includes density token fallbacks where density is 0.
277261
@function create-system-fallbacks() {
262+
$palettes: m3.md-sys-color-values-light(palettes.$blue-palette);
263+
$palettes: map.set($palettes, primary, palettes.$blue-palette);
278264
$app-vars: (
279265
'md-sys-color':
280-
_create-system-app-vars-map(m3.md-sys-color-values-light()),
266+
_create-system-app-vars-map(m3.md-sys-color-values-light($palettes)),
281267
'md-sys-typescale':
282-
_create-system-app-vars-map(m3.md-sys-typescale-values()),
268+
_create-system-app-vars-map(m3.md-sys-typescale-values((
269+
brand: (Roboto),
270+
plain: (Roboto),
271+
bold: 700,
272+
medium: 500,
273+
regular: 400
274+
))),
283275
'md-sys-elevation':
284276
_create-system-app-vars-map(m3.md-sys-elevation-values()),
285277
'md-sys-state':

0 commit comments

Comments
 (0)