Skip to content

Commit d8f9b5d

Browse files
committed
refactor(material/progress-bar): change mat-progress-bar to use MDC's token API
1 parent 796638b commit d8f9b5d

File tree

3 files changed

+82
-12
lines changed

3 files changed

+82
-12
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+
@use 'sass:color';
5+
@use 'sass:meta';
6+
7+
// The prefix used to generate the fully qualified name for tokens in this file.
8+
$prefix: (mdc, progress-bar);
9+
10+
// Tokens that can't be configured through Angular Material's current theming API,
11+
// but may be in a future version of the theming API.
12+
//
13+
// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`.
14+
// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in
15+
// our CSS.
16+
@function get-unthemable-tokens() {
17+
@return (track-height: 4px);
18+
}
19+
20+
// Tokens that can be configured through Angular Material's color theming API.
21+
@function get-color-tokens($config) {
22+
$primary: theming.get-color-from-palette(map.get($config, primary));
23+
@debug ($primary);
24+
@warn (hello);
25+
@return (
26+
active-indicator-color: $primary,
27+
track-color: $primary,
28+
// track-color:
29+
// if(meta.type-of($primary) == color, color.adjust($primary, $alpha: -0.75), $primary)
30+
);
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+
45
@use '@material/list/list-theme' as mdc-list-theme;
56
@use '../m2/mdc/list' as tokens-mdc-list;
67

7-
@mixin validate-slots(
8-
$component,
9-
$slots,
10-
$reference
11-
) {
8+
@use '@material/linear-progress/linear-progress-theme' as mdc-linear-progress-theme;
9+
@use '../m2/mdc/progress-bar' as tokens-mdc-progress-bar;
10+
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-bar',
31+
$slots: tokens-mdc-progress-bar.get-token-slots(),
32+
$reference: mdc-linear-progress-theme.$light-theme
2733
);

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
@use '../core/mdc-helpers/mdc-helpers';
22
@use '@material/linear-progress/linear-progress' as mdc-linear-progress;
33
@use '@material/linear-progress/linear-progress-theme' as mdc-linear-progress-theme;
4+
@use '../core/tokens/m2/mdc/progress-bar' as m2-mdc-progress-bar;
45

56
@include mdc-helpers.disable-mdc-fallback-declarations {
6-
@include mdc-linear-progress.static-styles($query: mdc-helpers.$mdc-base-styles-query);
7+
$mdc-progress-bar-token-slots: m2-mdc-progress-bar.get-token-slots();
78

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);
9+
// Add the MDC progress-bar static styles.
10+
@include mdc-linear-progress.static-styles();
11+
12+
// Add the official slots for the MDC progress-bar.
13+
@include mdc-linear-progress-theme.theme-styles($mdc-progress-bar-token-slots);
14+
15+
// Add default values for tokens that aren't outputted by the theming API.
16+
.mat-mdc-progress-bar {
17+
@include mdc-linear-progress-theme.theme(m2-mdc-progress-bar.get-unthemable-tokens());
18+
}
1119
}
1220

1321
.mat-mdc-progress-bar {

0 commit comments

Comments
 (0)