Skip to content

Commit 127597f

Browse files
authored
Fix a few gaps in our support for M3 configs and more closely align our M3 dev-app styles with our M2 dev-app styles (#28516)
* fix(material/theming): Fix M3 theme reliance on legacy theme inspection API * test: Align M3 demo styles more closely with M2 demo styles In particular, call the `all-component` mixins rather than individual mixins. * test: Allow toggling color API back compat CSS in the demo app
1 parent d799c04 commit 127597f

File tree

11 files changed

+199
-269
lines changed

11 files changed

+199
-269
lines changed

src/dev-app/BUILD.bazel

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
2-
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "http_server", "ng_module", "sass_binary")
2+
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "http_server", "ng_module", "sass_binary", "sass_library")
33
load("//src/components-examples:config.bzl", "ALL_EXAMPLES")
44
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
55

@@ -105,6 +105,14 @@ devmode_esbuild(
105105
],
106106
)
107107

108+
sass_library(
109+
name = "color-api-back-compat",
110+
srcs = glob(["**/_*.scss"]),
111+
deps = [
112+
"//src/material:sass_lib",
113+
],
114+
)
115+
108116
sass_binary(
109117
name = "theme",
110118
src = "theme.scss",
@@ -119,6 +127,7 @@ sass_binary(
119127
name = "theme_m3",
120128
src = "theme-m3.scss",
121129
deps = [
130+
":color-api-back-compat",
122131
"//src/material:sass_lib",
123132
"//src/material-experimental:sass_lib",
124133
"//src/material/core:theming_scss_lib",
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
@use '@angular/material' as mat;
2+
3+
@mixin color-variant-styles($theme, $color-variant) {
4+
@include mat.option-color($theme, $color-variant: $color-variant);
5+
@include mat.progress-spinner-color($theme, $color-variant: $color-variant);
6+
@include mat.pseudo-checkbox-color($theme, $color-variant: $color-variant);
7+
@include mat.stepper-color($theme, $color-variant: $color-variant);
8+
9+
&.mat-icon {
10+
@include mat.icon-color($theme, $color-variant: $color-variant);
11+
}
12+
13+
&.mat-mdc-checkbox {
14+
@include mat.checkbox-color($theme, $color-variant: $color-variant);
15+
}
16+
17+
&.mat-mdc-slider {
18+
@include mat.slider-color($theme, $color-variant: $color-variant);
19+
}
20+
21+
&.mat-mdc-tab-group,
22+
&.mat-mdc-tab-nav-bar {
23+
@include mat.tabs-color($theme, $color-variant: $color-variant);
24+
}
25+
26+
&.mat-mdc-slide-toggle {
27+
@include mat.slide-toggle-color($theme, $color-variant: $color-variant);
28+
}
29+
30+
&.mat-mdc-form-field {
31+
@include mat.select-color($theme, $color-variant: $color-variant);
32+
}
33+
34+
&.mat-mdc-radio-button {
35+
@include mat.radio-color($theme, $color-variant: $color-variant);
36+
}
37+
38+
&.mat-mdc-progress-bar {
39+
@include mat.progress-bar-color($theme, $color-variant: $color-variant);
40+
}
41+
42+
&.mat-mdc-form-field {
43+
@include mat.form-field-color($theme, $color-variant: $color-variant);
44+
}
45+
46+
&.mat-datepicker-content {
47+
@include mat.datepicker-color($theme, $color-variant: $color-variant);
48+
}
49+
50+
&.mat-mdc-button-base {
51+
@include mat.button-color($theme, $color-variant: $color-variant);
52+
}
53+
54+
&.mat-mdc-standard-chip {
55+
@include mat.chips-color($theme, $color-variant: $color-variant);
56+
}
57+
58+
.mdc-list-item__start,
59+
.mdc-list-item__end {
60+
@include mat.checkbox-color($theme, $color-variant: $color-variant);
61+
@include mat.radio-color($theme, $color-variant: $color-variant);
62+
}
63+
64+
// M3 dropped support for warn/error color FABs.
65+
@if $color-variant != error {
66+
&.mat-mdc-fab,
67+
&.mat-mdc-mini-fab {
68+
@include mat.fab-color($theme, $color-variant: $color-variant);
69+
}
70+
}
71+
}
72+
73+
// TODO(mmalerba): Consider adding this as a back-compat API for users who want it, rather than just
74+
// a demo thing.
75+
@mixin color-variants-back-compat($theme) {
76+
.mat-primary {
77+
@include color-variant-styles($theme, primary);
78+
}
79+
.mat-badge {
80+
@include mat.badge-color($theme, $color-variant: primary);
81+
}
82+
83+
.mat-accent {
84+
@include color-variant-styles($theme, tertiary);
85+
}
86+
.mat-badge-accent {
87+
@include mat.badge-color($theme, $color-variant: tertiary);
88+
}
89+
90+
.mat-warn {
91+
@include color-variant-styles($theme, error);
92+
}
93+
.mat-badge-warn {
94+
@include mat.badge-color($theme, $color-variant: error);
95+
}
96+
}

src/dev-app/dev-app/dev-app-layout.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
<div class="demo-toolbar">
4646
<h1>Angular Material Demos</h1>
4747
<div class="demo-config-buttons">
48+
@if (state.m3Enabled) {
49+
<button
50+
mat-icon-button
51+
(click)="toggleColorApiBackCompat()"
52+
matTooltip="{{state.colorApiBackCompat ? 'Disable' : 'Enable'}} color API back-compat">
53+
<mat-icon>colorize</mat-icon>
54+
</button>
55+
}
4856
<button
4957
mat-icon-button
5058
(click)="toggleFullscreen()"

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export class DevAppLayout {
118118
this.toggleRippleDisabled(this.state.rippleDisabled);
119119
this.toggleDirection(this.state.direction);
120120
this.toggleM3(this.state.m3Enabled);
121+
this.toggleColorApiBackCompat(this.state.colorApiBackCompat);
121122
}
122123

123124
toggleTheme(value = !this.state.darkTheme) {
@@ -179,6 +180,12 @@ export class DevAppLayout {
179180
setAppState(this.state);
180181
}
181182

183+
toggleColorApiBackCompat(value = !this.state.colorApiBackCompat) {
184+
this.state.colorApiBackCompat = value;
185+
this._document.body.classList.toggle('demo-color-api-back-compat', value);
186+
setAppState(this.state);
187+
}
188+
182189
getDensityClass() {
183190
return `demo-density-${this.state.density}`;
184191
}

src/dev-app/dev-app/dev-app-state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface DevAppState {
1919
strongFocusEnabled: boolean;
2020
m3Enabled: boolean;
2121
direction: Direction;
22+
colorApiBackCompat: boolean;
2223
}
2324

2425
/** Gets the current appearance state of the dev app. */
@@ -43,6 +44,7 @@ export function getAppState(): DevAppState {
4344
strongFocusEnabled: false,
4445
m3Enabled: false,
4546
direction: 'ltr',
47+
colorApiBackCompat: true,
4648
};
4749

4850
saveToStorage(value);

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

Lines changed: 1 addition & 4 deletions
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" [panelClass]="m3ForceSecondary ? 'demo-force-secondary' : ''">
14+
[disabled]="drinksDisabled" #drinkControl="ngModel">
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,9 +59,6 @@
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>
6562

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

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

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

7675
sandwichBread = '';
7776
sandwichMeat = '';

0 commit comments

Comments
 (0)