Skip to content

Commit 658b8fb

Browse files
committed
refactor(material/progress-spinner): change mat-progress-spinner to use MDC's token API
1 parent 5ae7d68 commit 658b8fb

File tree

3 files changed

+86
-33
lines changed

3 files changed

+86
-33
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@use 'sass:map';
2+
@use '../../../theming/theming';
3+
@use '../../token-utils';
4+
5+
// The prefix used to generate the fully qualified name for tokens in this file.
6+
$prefix: (mdc, progress-spinner);
7+
8+
// Tokens that can't be configured through Angular Material's current theming API,
9+
// but may be in a future version of the theming API.
10+
//
11+
// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`.
12+
// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in
13+
// our CSS.
14+
@function get-unthemable-tokens() {
15+
@return (
16+
active-indicator-width: 4px,
17+
size: 48px,
18+
// =============================================================================================
19+
// = TOKENS NOT USED IN ANGULAR MATERIAL =
20+
// =============================================================================================
21+
four-color-active-indicator-one-color: null,
22+
four-color-active-indicator-two-color: null,
23+
four-color-active-indicator-three-color: null,
24+
four-color-active-indicator-four-color: null
25+
);
26+
}
27+
28+
// Tokens that can be configured through Angular Material's color theming API.
29+
@function get-color-tokens($config) {
30+
@return (active-indicator-color: theming.get-color-from-palette(map.get($config, primary)));
31+
}
32+
33+
// Tokens that can be configured through Angular Material's typography theming API.
34+
@function get-typography-tokens($config) {
35+
@return ();
36+
}
37+
38+
// Tokens that can be configured through Angular Material's density theming API.
39+
@function get-density-tokens($config) {
40+
@return ();
41+
}
42+
43+
// Combines the tokens generated by the above functions into a single map with placeholder values.
44+
// This is used to create token slots.
45+
@function get-token-slots() {
46+
@return map.merge(
47+
get-unthemable-tokens(),
48+
map.merge(
49+
get-color-tokens(token-utils.$placeholder-color-config),
50+
map.merge(
51+
get-typography-tokens(token-utils.$placeholder-typography-config),
52+
get-density-tokens(token-utils.$placeholder-density-config)
53+
)
54+
)
55+
);
56+
}
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
@use 'sass:list';
22
@use 'sass:map';
33
@use '@material/theme/validate' as mdc-validate;
4+
5+
@use '@material/circular-progress/circular-progress-theme' as mdc-circular-progress-theme;
46
@use '@material/list/list-theme' as mdc-list-theme;
7+
58
@use '../m2/mdc/list' as tokens-mdc-list;
9+
@use '../m2/mdc/progress-spinner' as tokens-mdc-progress-spinner;
610

7-
@mixin validate-slots(
8-
$component,
9-
$slots,
10-
$reference
11-
) {
11+
@mixin validate-slots($component, $slots, $reference) {
1212
@debug 'Validating #{$component}...';
1313
// We don't care what the values are, just that every valid token is present in the slots map.
1414
// Specifically its ok if the token is explicitly mapped to `null`. We therefore replace all the
@@ -21,7 +21,13 @@
2121
}
2222

2323
@include validate-slots(
24-
$component: 'm2.mdc.list',
25-
$slots: tokens-mdc-list.get-token-slots(),
26-
$reference: mdc-list-theme.$light-theme
24+
$component: 'm2.mdc.list',
25+
$slots: tokens-mdc-list.get-token-slots(),
26+
$reference: mdc-list-theme.$light-theme
27+
);
28+
29+
@include validate-slots(
30+
$component: 'm2.mdc.progress-spinner',
31+
$slots: tokens-mdc-progress-spinner.get-token-slots(),
32+
$reference: mdc-circular-progress-theme.$light-theme
2733
);

src/material/progress-spinner/progress-spinner.scss

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
1-
@use 'sass:map';
2-
@use '../core/mdc-helpers/mdc-helpers';
31
@use '@angular/cdk';
42
@use '@material/circular-progress/circular-progress' as mdc-circular-progress;
53
@use '@material/circular-progress/circular-progress-theme' as mdc-circular-progress-theme;
4+
@use '@material/theme/custom-properties' as mdc-custom-properties;
5+
@use '../core/tokens/m2/mdc/progress-spinner' as m2-mdc-progress-spinner;
66

7+
// The slots for tokens that will be configured in the theme can be emitted with no fallback.
8+
@include mdc-custom-properties.configure($emit-fallback-values: false, $emit-fallback-vars: false) {
9+
$mdc-circular-progress-token-slots: m2-mdc-progress-spinner.get-token-slots();
710

8-
@include mdc-helpers.disable-mdc-fallback-declarations {
9-
@include mdc-circular-progress.static-styles($query: mdc-helpers.$mdc-base-styles-query);
10-
}
11-
12-
.mat-mdc-progress-spinner {
13-
@include mdc-helpers.disable-mdc-fallback-declarations {
14-
@include mdc-circular-progress-theme.theme-styles(map.merge(
15-
mdc-circular-progress-theme.$light-theme,
16-
(
17-
active-indicator-color: transparent,
11+
// Add the MDC progress spinner static styles.
12+
@include mdc-circular-progress.static-styles();
1813

19-
// We don't support the multi color variant so we exclude these variables.
20-
four-color-active-indicator-four-color: null,
21-
four-color-active-indicator-one-color: null,
22-
four-color-active-indicator-three-color: null,
23-
four-color-active-indicator-two-color: null,
14+
// Add the official slots for the MDC circular progress.
15+
@include mdc-circular-progress-theme.theme-styles($mdc-circular-progress-token-slots);
2416

25-
// We currently size the element ourselves so we can exclude these styles as well.
26-
// TODO(crisbeto): look into reusing MDC's styles by binding to a CSS variable
27-
// in our own template.
28-
active-indicator-width: null,
29-
size: null,
30-
)
31-
));
17+
// Add default values for tokens that aren't outputted by the theming API.
18+
.mat-mdc-progress-spinner {
19+
@include mdc-circular-progress-theme.theme(m2-mdc-progress-spinner.get-unthemable-tokens());
3220
}
21+
}
3322

23+
.mat-mdc-progress-spinner {
3424
// Explicitly set to `block` since the browser defaults custom elements to `inline`.
3525
display: block;
3626

@@ -43,7 +33,8 @@
4333
line-height: 0;
4434

4535
&._mat-animation-noopable {
46-
&, .mdc-circular-progress__determinate-circle {
36+
&,
37+
.mdc-circular-progress__determinate-circle {
4738
// The spinner itself has a transition on `opacity`.
4839
transition: none;
4940
}

0 commit comments

Comments
 (0)