Skip to content

Commit 69f8c3c

Browse files
authored
Revert "refactor(material/progress-bar): change mat-progress-bar to use MDC's token API (#26643)" (#26829)
This reverts commit 04deba8.
1 parent 04deba8 commit 69f8c3c

File tree

4 files changed

+31
-107
lines changed

4 files changed

+31
-107
lines changed

src/material/core/tokens/m2/mdc/_linear-progress.scss

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/material/core/tokens/tests/test-validate-tokens.scss

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
@use 'sass:list';
22
@use 'sass:map';
3-
43
@use '@material/card/elevated-card-theme' as mdc-elevated-card-theme;
54
@use '@material/card/outlined-card-theme' as mdc-outlined-card-theme;
65
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
76
@use '@material/circular-progress/circular-progress-theme' as mdc-circular-progress-theme;
8-
@use '@material/linear-progress/linear-progress-theme' as mdc-linear-progress-theme;
97
@use '@material/list/list-theme' as mdc-list-theme;
108
@use '@material/theme/validate' as mdc-validate;
11-
129
@use '../m2/mdc/circular-progress' as tokens-mdc-circular-progress;
1310
@use '../m2/mdc/elevated-card' as tokens-mdc-elevated-card;
1411
@use '../m2/mdc/checkbox' as tokens-mdc-checkbox;
15-
@use '../m2/mdc/linear-progress' as tokens-mdc-linear-progress;
1612
@use '../m2/mdc/list' as tokens-mdc-list;
1713
@use '../m2/mdc/outlined-card' as tokens-mdc-outlined-card;
1814

@@ -33,6 +29,7 @@
3329
$slots: tokens-mdc-list.get-token-slots(),
3430
$reference: mdc-list-theme.$light-theme
3531
);
32+
3633
@include validate-slots(
3734
$component: 'm2.mdc.circular-progress',
3835
$slots: tokens-mdc-circular-progress.get-token-slots(),
@@ -53,8 +50,3 @@
5350
$slots: tokens-mdc-checkbox.get-token-slots(),
5451
$reference: mdc-checkbox-theme.$light-theme
5552
);
56-
@include validate-slots(
57-
$component: 'm2.mdc.linear-progress',
58-
$slots: tokens-mdc-linear-progress.get-token-slots(),
59-
$reference: mdc-linear-progress-theme.$light-theme
60-
);

src/material/progress-bar/_progress-bar-theme.scss

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
1+
@use '../core/mdc-helpers/mdc-helpers';
12
@use '../core/theming/theming';
2-
@use '../core/tokens/m2/mdc/linear-progress' as tokens-mdc-linear-progress;
3+
@use '@material/theme/theme-color' as mdc-theme-color;
34
@use '@material/linear-progress/linear-progress-theme' as mdc-linear-progress-theme;
4-
@use 'sass:map';
5+
@use 'sass:color';
6+
@use 'sass:meta';
57

6-
@mixin _palette-styles($config, $palette-name) {
7-
$palette-config: map.merge($config, (primary: map.get($config, $palette-name)));
8-
$color-tokens: tokens-mdc-linear-progress.get-color-tokens($palette-config);
8+
9+
@mixin _palette-styles($color) {
10+
$color-value: mdc-theme-color.prop-value($color);
911

1012
// We can't set the `track-color` using `theme`, because it isn't possible for it to use a CSS
1113
// variable since MDC's buffer animation works by constructing an SVG string from this color.
12-
// We also can't set the `track-color` by creating our own token slot because the track-color
13-
// is set in the SVG string in `theme-styles`.
1414
@include mdc-linear-progress-theme.theme-styles((
1515
// TODO(crisbeto): the buffer color should come from somewhere in MDC, however at the time of
1616
// writing, their buffer color is hardcoded to #e6e6e6 which both doesn't account for theming
1717
// and doesn't match the Material design spec. For now we approximate the buffer background by
1818
// applying an opacity to the color of the bar.
19-
track-color: map.get($color-tokens, track-color),
19+
track-color: if(
20+
meta.type-of($color-value) == color,
21+
color.adjust($color-value, $alpha: -0.75),
22+
$color-value
23+
),
2024
));
2125

22-
@include mdc-linear-progress-theme.theme($color-tokens);
26+
@include mdc-linear-progress-theme.theme((
27+
active-indicator-color: $color-value,
28+
));
2329
}
2430

2531
@mixin color($config-or-theme) {
2632
$config: theming.get-color-config($config-or-theme);
33+
@include mdc-helpers.using-mdc-theme($config) {
34+
.mat-mdc-progress-bar {
35+
@include _palette-styles(primary);
2736

28-
.mat-mdc-progress-bar {
29-
@include _palette-styles($config, primary);
30-
31-
&.mat-accent {
32-
@include _palette-styles($config, accent);
33-
}
37+
&.mat-accent {
38+
@include _palette-styles(secondary);
39+
}
3440

35-
&.mat-warn {
36-
@include _palette-styles($config, warn);
41+
&.mat-warn {
42+
@include _palette-styles(error);
43+
}
3744
}
3845
}
3946
}

src/material/progress-bar/progress-bar.scss

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
@use 'sass:map';
2-
@use '@material/theme/custom-properties' as mdc-custom-properties;
1+
@use '../core/mdc-helpers/mdc-helpers';
32
@use '@material/linear-progress/linear-progress' as mdc-linear-progress;
43
@use '@material/linear-progress/linear-progress-theme' as mdc-linear-progress-theme;
5-
@use '../core/tokens/m2/mdc/linear-progress' as m2-mdc-linear-progress;
64

7-
@include mdc-custom-properties.configure($emit-fallback-values: false, $emit-fallback-vars: false) {
8-
$mdc-progress-bar-token-slots: m2-mdc-linear-progress.get-token-slots();
5+
@include mdc-helpers.disable-mdc-fallback-declarations {
6+
@include mdc-linear-progress.static-styles($query: mdc-helpers.$mdc-base-styles-query);
97

10-
// Add the MDC progress-bar static styles.
11-
@include mdc-linear-progress.static-styles();
12-
13-
// Add the official slots for the MDC progress-bar.
14-
@include mdc-linear-progress-theme.theme-styles(
15-
map.merge($mdc-progress-bar-token-slots, (
16-
// Excluded because it is meant to be set by theme (b/273562256).
17-
track-color: null,
18-
))
19-
);
20-
21-
// Add default values for tokens that aren't outputted by the theming API.
22-
.mat-mdc-progress-bar {
23-
// Add default values for tokens that aren't outputted by the theming API.
24-
@include mdc-linear-progress-theme.theme(m2-mdc-linear-progress.get-unthemable-tokens());
25-
}
8+
// TODO(crisbeto): we should be able to save some bytes here by setting the `track-color`
9+
// to null, but MDC's styles assume that a string is always going to be passed in.
10+
@include mdc-linear-progress-theme.theme-styles($theme: mdc-linear-progress-theme.$light-theme);
2611
}
2712

2813
.mat-mdc-progress-bar {

0 commit comments

Comments
 (0)