Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/dev-app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "http_server", "ng_module", "sass_binary")
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "http_server", "ng_module", "sass_binary", "sass_library")
load("//src/components-examples:config.bzl", "ALL_EXAMPLES")
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")

Expand Down Expand Up @@ -105,6 +105,14 @@ devmode_esbuild(
],
)

sass_library(
name = "color-api-back-compat",
srcs = glob(["**/_*.scss"]),
deps = [
"//src/material:sass_lib",
],
)

sass_binary(
name = "theme",
src = "theme.scss",
Expand All @@ -119,6 +127,7 @@ sass_binary(
name = "theme_m3",
src = "theme-m3.scss",
deps = [
":color-api-back-compat",
"//src/material:sass_lib",
"//src/material-experimental:sass_lib",
"//src/material/core:theming_scss_lib",
Expand Down
96 changes: 96 additions & 0 deletions src/dev-app/_color-api-back-compat.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
@use '@angular/material' as mat;

@mixin color-variant-styles($theme, $color-variant) {
@include mat.option-color($theme, $color-variant: $color-variant);
mmalerba marked this conversation as resolved.
Show resolved Hide resolved
@include mat.progress-spinner-color($theme, $color-variant: $color-variant);
@include mat.pseudo-checkbox-color($theme, $color-variant: $color-variant);
@include mat.stepper-color($theme, $color-variant: $color-variant);

&.mat-icon {
@include mat.icon-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-checkbox {
@include mat.checkbox-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-slider {
@include mat.slider-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-tab-group,
&.mat-mdc-tab-nav-bar {
@include mat.tabs-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-slide-toggle {
@include mat.slide-toggle-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-form-field {
@include mat.select-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-radio-button {
@include mat.radio-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-progress-bar {
@include mat.progress-bar-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-form-field {
@include mat.form-field-color($theme, $color-variant: $color-variant);
}

&.mat-datepicker-content {
@include mat.datepicker-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-button-base {
@include mat.button-color($theme, $color-variant: $color-variant);
}

&.mat-mdc-standard-chip {
@include mat.chips-color($theme, $color-variant: $color-variant);
}

.mdc-list-item__start,
.mdc-list-item__end {
@include mat.checkbox-color($theme, $color-variant: $color-variant);
@include mat.radio-color($theme, $color-variant: $color-variant);
}

// M3 dropped support for warn/error color FABs.
@if $color-variant != error {
&.mat-mdc-fab,
&.mat-mdc-mini-fab {
@include mat.fab-color($theme, $color-variant: $color-variant);
}
}
}

// TODO(mmalerba): Consider adding this as a back-compat API for users who want it, rather than just
// a demo thing.
@mixin color-variants-back-compat($theme) {
.mat-primary {
@include color-variant-styles($theme, primary);
}
.mat-badge {
@include mat.badge-color($theme, $color-variant: primary);
}

.mat-accent {
@include color-variant-styles($theme, tertiary);
}
.mat-badge-accent {
@include mat.badge-color($theme, $color-variant: tertiary);
}

.mat-warn {
@include color-variant-styles($theme, error);
}
.mat-badge-warn {
@include mat.badge-color($theme, $color-variant: error);
}
}
8 changes: 8 additions & 0 deletions src/dev-app/dev-app/dev-app-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
<div class="demo-toolbar">
<h1>Angular Material Demos</h1>
<div class="demo-config-buttons">
@if (state.m3Enabled) {
<button
mat-icon-button
(click)="toggleColorApiBackCompat()"
matTooltip="{{state.colorApiBackCompat ? 'Disable' : 'Enable'}} color API back-compat">
<mat-icon>colorize</mat-icon>
</button>
}
<button
mat-icon-button
(click)="toggleFullscreen()"
Expand Down
7 changes: 7 additions & 0 deletions src/dev-app/dev-app/dev-app-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class DevAppLayout {
this.toggleRippleDisabled(this.state.rippleDisabled);
this.toggleDirection(this.state.direction);
this.toggleM3(this.state.m3Enabled);
this.toggleColorApiBackCompat(this.state.colorApiBackCompat);
}

toggleTheme(value = !this.state.darkTheme) {
Expand Down Expand Up @@ -179,6 +180,12 @@ export class DevAppLayout {
setAppState(this.state);
}

toggleColorApiBackCompat(value = !this.state.colorApiBackCompat) {
this.state.colorApiBackCompat = value;
this._document.body.classList.toggle('demo-color-api-back-compat', value);
setAppState(this.state);
}

getDensityClass() {
return `demo-density-${this.state.density}`;
}
Expand Down
2 changes: 2 additions & 0 deletions src/dev-app/dev-app/dev-app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface DevAppState {
strongFocusEnabled: boolean;
m3Enabled: boolean;
direction: Direction;
colorApiBackCompat: boolean;
}

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

saveToStorage(value);
Expand Down
5 changes: 1 addition & 4 deletions src/dev-app/select/select-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[class.demo-drinks-width-large]="drinksWidth === '400px'">
<mat-label>Drink</mat-label>
<mat-select [(ngModel)]="currentDrink" [required]="drinksRequired"
[disabled]="drinksDisabled" #drinkControl="ngModel" [panelClass]="m3ForceSecondary ? 'demo-force-secondary' : ''">
[disabled]="drinksDisabled" #drinkControl="ngModel">
<mat-option [disabled]="drinksOptionsDisabled === 'all'">None</mat-option>
@for (drink of drinks; track drink; let index = $index) {
<mat-option [value]="drink.value"
Expand Down Expand Up @@ -59,9 +59,6 @@
<option value="all">Disable All Options</option>
</select>
</p>
<p>
<mat-checkbox [(ngModel)]="m3ForceSecondary">Force secondary color for options in M3</mat-checkbox>
</p>

<button mat-button (click)="currentDrink='water-2'">SET VALUE</button>
<button mat-button (click)="drinksRequired=!drinksRequired">TOGGLE REQUIRED</button>
Expand Down
1 change: 0 additions & 1 deletion src/dev-app/select/select-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export class SelectDemo {
pokemonTheme: ThemePalette = 'primary';
compareByValue = true;
selectFormControl = new FormControl('', Validators.required);
m3ForceSecondary = true;

sandwichBread = '';
sandwichMeat = '';
Expand Down
Loading
Loading