Skip to content

Commit 0da585f

Browse files
authored
fix(material-experimental/theming): Update color palettes (#28472)
Changes the way M3 color palettes a bit to make the color choices more in line with what the spec expects. In particular, select the secondary palette automatically based on the primary palette (secondary is intended to be a more muted version of primary). We still allow the user to select what tertiary color to pair with their primary, since the spec doesn't make the same sort of assumptions about the tertiary color. Note: because our demo targets styles at the .mat-primary, .mat-accent, .mat-error classes, it winds up overriding the default color combo that users would see out of the box for the mat-select (a primary form-field with a secondary selected option). This is one example where the M2 color="primary/accent/warn" API doesn't quite align with how colors work in M3. We do not expect users to apply colors in this way, and we probably shouldn't do it in our demo either. For now I've added an extra checkbox to the select demo that lets us observe the form-field/select combo users would see out of the box without our overrides.
1 parent a6e95f1 commit 0da585f

File tree

10 files changed

+649
-180
lines changed

10 files changed

+649
-180
lines changed

src/dev-app/select/select-demo.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[class.demo-drinks-width-large]="drinksWidth === '400px'">
1212
<mat-label>Drink</mat-label>
1313
<mat-select [(ngModel)]="currentDrink" [required]="drinksRequired"
14-
[disabled]="drinksDisabled" #drinkControl="ngModel">
14+
[disabled]="drinksDisabled" #drinkControl="ngModel" [panelClass]="m3ForceSecondary ? 'demo-force-secondary' : ''">
1515
<mat-option [disabled]="drinksOptionsDisabled === 'all'">None</mat-option>
1616
@for (drink of drinks; track drink; let index = $index) {
1717
<mat-option [value]="drink.value"
@@ -59,6 +59,9 @@
5959
<option value="all">Disable All Options</option>
6060
</select>
6161
</p>
62+
<p>
63+
<mat-checkbox [(ngModel)]="m3ForceSecondary">Force secondary color for options in M3</mat-checkbox>
64+
</p>
6265

6366
<button mat-button (click)="currentDrink='water-2'">SET VALUE</button>
6467
<button mat-button (click)="drinksRequired=!drinksRequired">TOGGLE REQUIRED</button>

src/dev-app/select/select-demo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class SelectDemo {
7171
pokemonTheme: ThemePalette = 'primary';
7272
compareByValue = true;
7373
selectFormControl = new FormControl('', Validators.required);
74+
m3ForceSecondary = true;
7475

7576
sandwichBread = '';
7677
sandwichMeat = '';

src/dev-app/theme-m3.scss

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@
8383
}
8484

8585
.mat-accent {
86-
@include color-variant-styles($theme, secondary);
86+
@include color-variant-styles($theme, tertiary);
8787
}
8888
.mat-badge-accent {
89-
@include mat.badge-color($theme, $color-variant: secondary);
89+
@include mat.badge-color($theme, $color-variant: tertiary);
9090
}
9191

9292
.mat-warn {
@@ -120,8 +120,7 @@ dev-app {
120120
$m3-base-config: (
121121
color: (
122122
primary: matx.$m3-green-palette,
123-
secondary: matx.$m3-blue-palette,
124-
tertiary: matx.$m3-yellow-palette,
123+
tertiary: matx.$m3-violet-palette,
125124
),
126125
);
127126

@@ -174,6 +173,10 @@ html {
174173

175174
@include color-variants-back-compat($light-theme);
176175

176+
.demo-force-secondary {
177+
@include mat.option-color($light-theme, $color-variant: secondary);
178+
}
179+
177180
// Emit dark theme styles.
178181
.demo-unicorn-dark-theme {
179182
// TODO(mmalerba): choose colors from the theming API.
@@ -219,6 +222,10 @@ html {
219222
@include mat.tree-color($dark-theme);
220223

221224
@include color-variants-back-compat($dark-theme);
225+
226+
.demo-force-secondary {
227+
@include mat.option-color($dark-theme, $color-variant: secondary);
228+
}
222229
}
223230

224231
// Emit density styles for each scale.

src/material-experimental/_index.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
// Token-based theming API
88
@forward './theming/definition' show define-theme, define-colors, define-typography, define-density;
9-
@forward './theming/m3-palettes' as m3-* show $m3-red-palette, $m3-orange-palette,
10-
$m3-yellow-palette, $m3-green-palette, $m3-blue-palette, $m3-indigo-palette, $m3-violet-palette;
9+
@forward './theming/m3-palettes' as m3-* show $m3-red-palette, $m3-green-palette, $m3-blue-palette,
10+
$m3-yellow-palette, $m3-cyan-palette, $m3-magenta-palette, $m3-orange-palette,
11+
$m3-chartreuse-palette, $m3-azure-palette, $m3-violet-palette, $m3-rose-palette;
1112

1213
// Additional public APIs for individual components

src/material-experimental/theming/_config-validation.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
@if $err {
9090
@return (#{'$config should be a color configuration object. Got:'} $config);
9191
}
92-
$allowed: (theme-type, primary, secondary, tertiary);
92+
$allowed: (theme-type, primary, tertiary);
9393
$err: mat.private-validate-allowed-values(map.keys($config or ()), $allowed...);
9494
@if $err {
9595
@return (

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@
10581058
focus-state-layer-color: mat.private-safe-color-change(
10591059
map.get($systems, md-sys-color, secondary), $alpha: 0.2),
10601060
),
1061-
teriatiary: (
1061+
tertiary: (
10621062
ripple-color: map.get($systems, md-sys-color, tertiary),
10631063
hover-state-layer-color: mat.private-safe-color-change(
10641064
map.get($systems, md-sys-color, tertiary), $alpha: 0.05),

src/material-experimental/theming/_definition.scss

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,23 @@ $theme-version: 1;
3838
}
3939

4040
$type: map.get($config, theme-type) or light;
41-
$primary: map.get($config, primary) or m3-palettes.$purple-palette;
42-
$secondary: map.get($config, secondary) or $primary;
43-
$tertiary: map.get($config, tertiary) or $secondary;
41+
$primary: map.get($config, primary) or m3-palettes.$violet-palette;
42+
$tertiary: map.get($config, tertiary) or $primary;
4443

4544
@return (
4645
$internals: (
4746
theme-version: $theme-version,
4847
theme-type: $type,
4948
palettes: (
50-
primary: map.remove($primary, neutral, neutral-variant),
51-
secondary: map.remove($secondary, neutral, neutral-variant),
52-
tertiary: map.remove($tertiary, neutral, neutral-variant),
49+
primary: map.remove($primary, neutral, neutral-variant, secondary),
50+
secondary: map.get($primary, secondary),
51+
tertiary: map.remove($tertiary, neutral, neutral-variant, secondary),
5352
neutral: map.get($primary, neutral),
5453
neutral-variant: map.get($primary, neutral-variant),
55-
error: map.remove(m3-palettes.$red-palette, neutral, neutral-variant),
54+
error: m3-palettes.$private-error-palette,
5655
),
5756
color-tokens: m3-tokens.generate-color-tokens(
58-
$type, $primary, $secondary, $tertiary, m3-palettes.$red-palette)
57+
$type, $primary, $tertiary, m3-palettes.$private-error-palette)
5958
)
6059
);
6160
}

0 commit comments

Comments
 (0)