Skip to content

Commit 75029c2

Browse files
authored
feat(material-experimental/theming): add M3 progress-spinner support (#27868)
* build: rename the m3 theme file Rename the m3 theme file to make its purpose more clear. Also change some related text in the dev-app. * feat(material-experimental/theming): add M3 progress-spinner support
1 parent 47ac55f commit 75029c2

File tree

9 files changed

+59
-32
lines changed

9 files changed

+59
-32
lines changed

src/dev-app/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ sass_binary(
116116
)
117117

118118
sass_binary(
119-
name = "theme_token_api",
120-
src = "theme-token-api.scss",
119+
name = "theme_m3",
120+
src = "theme-m3.scss",
121121
deps = [
122122
"//src/material:sass_lib",
123123
"//src/material-experimental:sass_lib",
@@ -142,7 +142,7 @@ filegroup(
142142
"favicon.ico",
143143
"index.html",
144144
":theme",
145-
":theme_token_api",
145+
":theme_m3",
146146
":variables",
147147
"//src/dev-app/icon:icon_demo_assets",
148148
"@npm//:node_modules/moment/min/moment-with-locales.min.js",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ <h1>Angular Material Demos</h1>
5353
</button>
5454
<button
5555
mat-icon-button
56-
(click)="toggleTokens()"
57-
[matTooltip]="state.tokensEnabled ? 'Disable tokens' : 'Enable tokens'">
56+
(click)="toggleM3()"
57+
[matTooltip]="state.m3Enabled ? 'Use M2 theme' : 'Use M3 theme'">
5858
<mat-icon>brush</mat-icon>
5959
</button>
6060
<button

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ export class DevAppLayout {
162162
}
163163
}
164164

165-
toggleTokens(value = !this.state.tokensEnabled) {
165+
toggleM3(value = !this.state.m3Enabled) {
166166
// We need to diff this one since it's a bit more expensive to toggle.
167-
if (value !== this.state.tokensEnabled) {
167+
if (value !== this.state.m3Enabled) {
168168
(document.getElementById('theme-styles') as HTMLLinkElement).href = value
169-
? 'theme-token-api.css'
169+
? 'theme-m3.css'
170170
: 'theme.css';
171-
this.state.tokensEnabled = value;
171+
this.state.m3Enabled = value;
172172
setAppState(this.state);
173173
}
174174
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface DevAppState {
1717
darkTheme: boolean;
1818
rippleDisabled: boolean;
1919
strongFocusEnabled: boolean;
20-
tokensEnabled: boolean;
20+
m3Enabled: boolean;
2121
direction: Direction;
2222
}
2323

@@ -41,7 +41,7 @@ export function getAppState(): DevAppState {
4141
darkTheme: false,
4242
rippleDisabled: false,
4343
strongFocusEnabled: false,
44-
tokensEnabled: false,
44+
m3Enabled: false,
4545
direction: 'ltr',
4646
};
4747

src/dev-app/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {getAppState} from './dev-app/dev-app-state';
2929
// It uses a different file, instead of toggling a class, to avoid other styles from bleeding in.
3030
const cachedAppState = getAppState();
3131
const theme = document.createElement('link');
32-
theme.href = cachedAppState.tokensEnabled ? 'theme-token-api.css' : 'theme.css';
32+
theme.href = cachedAppState.m3Enabled ? 'theme-m3.css' : 'theme.css';
3333
theme.id = 'theme-styles';
3434
theme.rel = 'stylesheet';
3535
document.head.appendChild(theme);

src/dev-app/theme-token-api.scss renamed to src/dev-app/theme-m3.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
@use '@angular/material' as mat;
33
@use '@angular/material-experimental' as matx;
44

5-
// Add an indicator to make it clear that the app is styled with the experimental theming API.
5+
// Add an indicator to make it clear that the app is styled with the experimental M3 theme.
66
dev-app {
77
&::before {
8-
content: 'Using experimental theming API';
8+
content: 'Using experimental M3 theme, only components that support M3 will work';
99
display: inline-block;
1010
position: fixed;
1111
z-index: 100;
@@ -42,6 +42,7 @@ html {
4242
@include mat.toolbar-theme($light-theme);
4343
@include mat.slider-theme($light-theme);
4444
@include mat.snack-bar-theme($light-theme);
45+
@include mat.progress-spinner-theme($light-theme);
4546
}
4647

4748
// Emit dark theme styles.
@@ -56,6 +57,7 @@ html {
5657
@include mat.toolbar-color($dark-theme);
5758
@include mat.slider-color($dark-theme);
5859
@include mat.snack-bar-color($dark-theme);
60+
@include mat.progress-spinner-color($dark-theme);
5961
}
6062

6163
// Emit density styles for each scale.
@@ -69,5 +71,6 @@ html {
6971
@include mat.toolbar-density($scale-theme);
7072
@include mat.slider-density($scale-theme);
7173
@include mat.snack-bar-density($scale-theme);
74+
@include mat.progress-spinner-density($scale-theme);
7275
}
7376
}

src/material-experimental/theming-next/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ $m2-tokens: mat.m2-tokens-from-theme($my-theme);
5555
need to appear differently, say within `.dark-sidebar`, set the token overrides on the
5656
`.dark-sidebar` element and they will be inherited down to the checkboxes within, instead of the
5757
values from the root element.
58-
- 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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@
203203
mdc-tokens.md-comp-plain-tooltip-values($systems, $exclude-hardcoded),
204204
$token-slots
205205
),
206+
_namespace-tokens(
207+
(mdc, circular-progress),
208+
mdc-tokens.md-comp-circular-progress-indicator-values($systems, $exclude-hardcoded),
209+
$token-slots
210+
),
206211
// Choose values for our made up tokens based on MDC system tokens or sensible hardcoded
207212
// values.
208213
_namespace-tokens(
Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
1+
@use 'sass:map';
12
@use '../core/style/sass-utils';
23
@use '../core/theming/theming';
34
@use '../core/theming/inspection';
45
@use '../core/tokens/m2/mdc/circular-progress' as tokens-mdc-circular-progress;
56
@use '@material/circular-progress/circular-progress-theme' as mdc-circular-progress-theme;
67

78
@mixin base($theme) {
8-
// Add default values for tokens not related to color, typography, or density.
9-
@include sass-utils.current-selector-or-root() {
10-
@include mdc-circular-progress-theme.theme(
11-
tokens-mdc-circular-progress.get-unthemable-tokens()
12-
);
9+
@if inspection.get-theme-version($theme) == 1 {
10+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
11+
}
12+
@else {
13+
// Add default values for tokens not related to color, typography, or density.
14+
@include sass-utils.current-selector-or-root() {
15+
@include mdc-circular-progress-theme.theme(
16+
tokens-mdc-circular-progress.get-unthemable-tokens()
17+
);
18+
}
1319
}
1420
}
1521

1622
@mixin color($theme) {
17-
$mdc-circular-progress-color-tokens: tokens-mdc-circular-progress.get-color-tokens($theme);
23+
@if inspection.get-theme-version($theme) == 1 {
24+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
25+
}
26+
@else {
27+
$mdc-circular-progress-color-tokens: tokens-mdc-circular-progress.get-color-tokens($theme);
1828

19-
@include sass-utils.current-selector-or-root() {
20-
@include mdc-circular-progress-theme.theme($mdc-circular-progress-color-tokens);
29+
@include sass-utils.current-selector-or-root() {
30+
@include mdc-circular-progress-theme.theme($mdc-circular-progress-color-tokens);
2131

22-
.mat-accent {
23-
$color: inspection.get-theme-color($theme, accent);
24-
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
25-
}
32+
.mat-accent {
33+
$color: inspection.get-theme-color($theme, accent);
34+
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
35+
}
2636

27-
.mat-warn {
28-
$color: inspection.get-theme-color($theme, warn);
29-
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
37+
.mat-warn {
38+
$color: inspection.get-theme-color($theme, warn);
39+
@include mdc-circular-progress-theme.theme((active-indicator-color: $color));
40+
}
3041
}
3142
}
3243
}
3344

34-
@mixin typography($theme) {}
45+
@mixin typography($theme) {
46+
}
3547

36-
@mixin density($theme) {}
48+
@mixin density($theme) {
49+
}
3750

3851
@mixin theme($theme) {
3952
@include theming.private-check-duplicate-theme-styles($theme, 'mat-progress-spinner') {
@@ -49,3 +62,10 @@
4962
}
5063
}
5164
}
65+
66+
@mixin _theme-from-tokens($tokens) {
67+
@if ($tokens != ()) {
68+
@include mdc-circular-progress-theme.theme(
69+
map.get($tokens, tokens-mdc-circular-progress.$prefix));
70+
}
71+
}

0 commit comments

Comments
 (0)