Skip to content

feat(material-experimental/theming): add M3 progress-spinner support #27868

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

Merged
merged 2 commits into from
Oct 3, 2023
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
6 changes: 3 additions & 3 deletions src/dev-app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ sass_binary(
)

sass_binary(
name = "theme_token_api",
src = "theme-token-api.scss",
name = "theme_m3",
src = "theme-m3.scss",
deps = [
"//src/material:sass_lib",
"//src/material-experimental:sass_lib",
Expand All @@ -142,7 +142,7 @@ filegroup(
"favicon.ico",
"index.html",
":theme",
":theme_token_api",
":theme_m3",
":variables",
"//src/dev-app/icon:icon_demo_assets",
"@npm//:node_modules/moment/min/moment-with-locales.min.js",
Expand Down
4 changes: 2 additions & 2 deletions src/dev-app/dev-app/dev-app-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ <h1>Angular Material Demos</h1>
</button>
<button
mat-icon-button
(click)="toggleTokens()"
[matTooltip]="state.tokensEnabled ? 'Disable tokens' : 'Enable tokens'">
(click)="toggleM3()"
[matTooltip]="state.m3Enabled ? 'Use M2 theme' : 'Use M3 theme'">
<mat-icon>brush</mat-icon>
</button>
<button
Expand Down
8 changes: 4 additions & 4 deletions src/dev-app/dev-app/dev-app-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ export class DevAppLayout {
}
}

toggleTokens(value = !this.state.tokensEnabled) {
toggleM3(value = !this.state.m3Enabled) {
// We need to diff this one since it's a bit more expensive to toggle.
if (value !== this.state.tokensEnabled) {
if (value !== this.state.m3Enabled) {
(document.getElementById('theme-styles') as HTMLLinkElement).href = value
? 'theme-token-api.css'
? 'theme-m3.css'
: 'theme.css';
this.state.tokensEnabled = value;
this.state.m3Enabled = value;
setAppState(this.state);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/dev-app/dev-app/dev-app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface DevAppState {
darkTheme: boolean;
rippleDisabled: boolean;
strongFocusEnabled: boolean;
tokensEnabled: boolean;
m3Enabled: boolean;
direction: Direction;
}

Expand All @@ -41,7 +41,7 @@ export function getAppState(): DevAppState {
darkTheme: false,
rippleDisabled: false,
strongFocusEnabled: false,
tokensEnabled: false,
m3Enabled: false,
direction: 'ltr',
};

Expand Down
2 changes: 1 addition & 1 deletion src/dev-app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {getAppState} from './dev-app/dev-app-state';
// It uses a different file, instead of toggling a class, to avoid other styles from bleeding in.
const cachedAppState = getAppState();
const theme = document.createElement('link');
theme.href = cachedAppState.tokensEnabled ? 'theme-token-api.css' : 'theme.css';
theme.href = cachedAppState.m3Enabled ? 'theme-m3.css' : 'theme.css';
theme.id = 'theme-styles';
theme.rel = 'stylesheet';
document.head.appendChild(theme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

// Add an indicator to make it clear that the app is styled with the experimental theming API.
// Add an indicator to make it clear that the app is styled with the experimental M3 theme.
dev-app {
&::before {
content: 'Using experimental theming API';
content: 'Using experimental M3 theme, only components that support M3 will work';
display: inline-block;
position: fixed;
z-index: 100;
Expand Down Expand Up @@ -42,6 +42,7 @@ html {
@include mat.toolbar-theme($light-theme);
@include mat.slider-theme($light-theme);
@include mat.snack-bar-theme($light-theme);
@include mat.progress-spinner-theme($light-theme);
}

// Emit dark theme styles.
Expand All @@ -56,6 +57,7 @@ html {
@include mat.toolbar-color($dark-theme);
@include mat.slider-color($dark-theme);
@include mat.snack-bar-color($dark-theme);
@include mat.progress-spinner-color($dark-theme);
}

// Emit density styles for each scale.
Expand All @@ -69,5 +71,6 @@ html {
@include mat.toolbar-density($scale-theme);
@include mat.slider-density($scale-theme);
@include mat.snack-bar-density($scale-theme);
@include mat.progress-spinner-density($scale-theme);
}
}
1 change: 0 additions & 1 deletion src/material-experimental/theming-next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ $m2-tokens: mat.m2-tokens-from-theme($my-theme);
need to appear differently, say within `.dark-sidebar`, set the token overrides on the
`.dark-sidebar` element and they will be inherited down to the checkboxes within, instead of the
values from the root element.
- For a small example, see this [alternate partial theme](https://github.com/angular/components/blob/main/src/dev-app/theme-token-api.scss) for the dev-app
5 changes: 5 additions & 0 deletions src/material-experimental/theming/_m3-tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
mdc-tokens.md-comp-plain-tooltip-values($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mdc, circular-progress),
mdc-tokens.md-comp-circular-progress-indicator-values($systems, $exclude-hardcoded),
$token-slots
),
// Choose values for our made up tokens based on MDC system tokens or sensible hardcoded
// values.
_namespace-tokens(
Expand Down
54 changes: 37 additions & 17 deletions src/material/progress-spinner/_progress-spinner-theme.scss
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
@use 'sass:map';
@use '../core/style/sass-utils';
@use '../core/theming/theming';
@use '../core/theming/inspection';
@use '../core/tokens/m2/mdc/circular-progress' as tokens-mdc-circular-progress;
@use '@material/circular-progress/circular-progress-theme' as mdc-circular-progress-theme;

@mixin base($theme) {
// Add default values for tokens not related to color, typography, or density.
@include sass-utils.current-selector-or-root() {
@include mdc-circular-progress-theme.theme(
tokens-mdc-circular-progress.get-unthemable-tokens()
);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
}
@else {
// Add default values for tokens not related to color, typography, or density.
@include sass-utils.current-selector-or-root() {
@include mdc-circular-progress-theme.theme(
tokens-mdc-circular-progress.get-unthemable-tokens()
);
}
}
}

@mixin color($theme) {
$mdc-circular-progress-color-tokens: tokens-mdc-circular-progress.get-color-tokens($theme);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
}
@else {
$mdc-circular-progress-color-tokens: tokens-mdc-circular-progress.get-color-tokens($theme);

@include sass-utils.current-selector-or-root() {
@include mdc-circular-progress-theme.theme($mdc-circular-progress-color-tokens);
@include sass-utils.current-selector-or-root() {
@include mdc-circular-progress-theme.theme($mdc-circular-progress-color-tokens);

.mat-accent {
$color: inspection.get-theme-color($theme, accent);
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
}
.mat-accent {
$color: inspection.get-theme-color($theme, accent);
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
}

.mat-warn {
$color: inspection.get-theme-color($theme, warn);
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
.mat-warn {
$color: inspection.get-theme-color($theme, warn);
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
}
}
}
}

@mixin typography($theme) {}
@mixin typography($theme) {
}

@mixin density($theme) {}
@mixin density($theme) {
}

@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-progress-spinner') {
Expand All @@ -49,3 +62,10 @@
}
}
}

@mixin _theme-from-tokens($tokens) {
@if ($tokens != ()) {
@include mdc-circular-progress-theme.theme(
map.get($tokens, tokens-mdc-circular-progress.$prefix));
}
}