Skip to content

Commit fbc7bdd

Browse files
authored
feat(material-experimental/theming): add M3 slider support (#27826)
1 parent 6b57edb commit fbc7bdd

File tree

6 files changed

+107
-44
lines changed

6 files changed

+107
-44
lines changed

src/dev-app/theme-token-api.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ html {
4040
@include mat.card-theme($light-theme);
4141
@include mat.tooltip-theme($light-theme);
4242
@include mat.toolbar-theme($light-theme);
43+
@include mat.slider-theme($light-theme);
4344
@include mat.snack-bar-theme($light-theme);
4445
}
4546

@@ -53,6 +54,7 @@ html {
5354
@include mat.card-color($dark-theme);
5455
@include mat.tooltip-color($dark-theme);
5556
@include mat.toolbar-color($dark-theme);
57+
@include mat.slider-color($dark-theme);
5658
@include mat.snack-bar-color($dark-theme);
5759
}
5860

@@ -65,6 +67,7 @@ html {
6567
@include mat.card-density($scale-theme);
6668
@include mat.tooltip-density($scale-theme);
6769
@include mat.toolbar-density($scale-theme);
70+
@include mat.slider-density($scale-theme);
6871
@include mat.snack-bar-density($scale-theme);
6972
}
7073
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
);
4545
}
4646

47+
/// Generates custom tokens for the mat-slider.
48+
/// @param {Map} $systems The MDC system tokens
49+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
50+
/// @return {Map} A set of custom tokens for the mat-slider
51+
@function slider($systems, $exclude-hardcoded) {
52+
@return (
53+
value-indicator-opacity: 1,
54+
);
55+
}
56+
4757
/// Generates custom tokens for the mat-snack-bar.
4858
/// @param {Map} $systems The MDC system tokens
4959
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ $_density-tokens: (
2020
),
2121
(mdc, elevated-card): (),
2222
(mdc, outlined-card): (),
23+
(mdc, slider): (),
2324
(mat, card): (),
2425
(mdc, plain-tooltip): (),
2526
(mat, toolbar): (
2627
standard-height: (64px, 60px, 56px, 52px),
2728
mobile-height: (56px, 52px, 48px, 44px),
28-
)
29+
),
30+
(mat, slider): (),
2931
);
3032

3133
/// Gets the value for the given density scale from the given set of density values.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@
188188
mdc-tokens.md-comp-outlined-card-values($systems, $exclude-hardcoded),
189189
$token-slots
190190
),
191+
_namespace-tokens(
192+
(mdc, slider),
193+
mdc-tokens.md-comp-slider-values($systems, $exclude-hardcoded),
194+
$token-slots
195+
),
191196
_namespace-tokens(
192197
(mdc, snackbar),
193198
mdc-tokens.md-comp-snackbar-values($systems, $exclude-hardcoded),
@@ -210,6 +215,11 @@
210215
custom-tokens.toolbar($systems, $exclude-hardcoded),
211216
$token-slots,
212217
),
218+
_namespace-tokens(
219+
(mat, slider),
220+
custom-tokens.slider($systems, $exclude-hardcoded),
221+
$token-slots
222+
),
213223
_namespace-tokens(
214224
(mat, snack-bar),
215225
custom-tokens.snack-bar($systems, $exclude-hardcoded),

src/material/core/tokens/m2/_index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@use './mat/snack-bar' as tokens-mat-snack-bar;
99
@use './mat/tab-header' as tokens-mat-tab-header;
1010
@use './mat/tab-header-with-background' as tokens-mat-tab-header-with-background;
11+
@use './mat/slider' as tokens-mat-slider;
1112
@use './mdc/checkbox' as tokens-mdc-checkbox;
1213
@use './mdc/circular-progress' as tokens-mdc-circular-progress;
1314
@use './mdc/dialog' as tokens-mdc-dialog;
@@ -20,6 +21,7 @@
2021
@use './mdc/snack-bar' as tokens-mdc-snack-bar;
2122
@use './mdc/tab' as tokens-mdc-tab;
2223
@use './mdc/tab-indicator' as tokens-mdc-tab-indicator;
24+
@use './mdc/slider' as tokens-mdc-slider;
2325
@use './mdc/plain-tooltip' as tokens-mdc-plain-tooltip;
2426

2527
/// Gets the tokens for the given theme, m2 tokens module, and theming system.
@@ -71,6 +73,7 @@
7173
_get-tokens-for-module($theme, tokens-mat-tab-header),
7274
_get-tokens-for-module($theme, tokens-mat-tab-header-with-background),
7375
_get-tokens-for-module($theme, tokens-mat-toolbar),
76+
_get-tokens-for-module($theme, tokens-mat-slider),
7477
_get-tokens-for-module($theme, tokens-mdc-checkbox),
7578
_get-tokens-for-module($theme, tokens-mdc-circular-progress),
7679
_get-tokens-for-module($theme, tokens-mdc-dialog),
@@ -83,6 +86,7 @@
8386
_get-tokens-for-module($theme, tokens-mdc-snack-bar),
8487
_get-tokens-for-module($theme, tokens-mdc-tab),
8588
_get-tokens-for-module($theme, tokens-mdc-tab-indicator),
89+
_get-tokens-for-module($theme, tokens-mdc-slider),
8690
_get-tokens-for-module($theme, tokens-mdc-plain-tooltip),
8791
);
8892
}
Lines changed: 77 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,104 @@
1+
@use 'sass:map';
12
@use '@material/slider/slider-theme' as mdc-slider-theme;
23
@use '../core/theming/theming';
34
@use '../core/theming/inspection';
45
@use '../core/typography/typography';
56
@use '../core/style/sass-utils';
67
@use '../core/tokens/token-utils';
7-
@use '../core/tokens/m2/mat/slider' as m2-mat-slider;
8-
@use '../core/tokens/m2/mdc/slider' as m2-mdc-slider;
8+
@use '../core/tokens/m2/mat/slider' as tokens-mat-slider;
9+
@use '../core/tokens/m2/mdc/slider' as tokens-mdc-slider;
910

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

1723
@mixin color($theme) {
18-
$is-dark: inspection.get-theme-type($theme) == dark;
24+
@if inspection.get-theme-version($theme) == 1 {
25+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
26+
}
27+
@else {
28+
$is-dark: inspection.get-theme-type($theme) == dark;
1929

20-
$mdc-color-tokens: token-utils.resolve-elevation(
21-
m2-mdc-slider.get-color-tokens($theme),
22-
handle-elevation,
23-
handle-shadow-color
24-
);
30+
$mdc-color-tokens: token-utils.resolve-elevation(
31+
tokens-mdc-slider.get-color-tokens($theme),
32+
handle-elevation,
33+
handle-shadow-color
34+
);
2535

26-
$mat-slider-color-tokens: m2-mat-slider.get-color-tokens($theme);
36+
$mat-slider-color-tokens: tokens-mat-slider.get-color-tokens($theme);
2737

28-
// Add values for MDC slider tokens.
29-
.mat-mdc-slider {
30-
@include mdc-slider-theme.theme($mdc-color-tokens);
31-
@include _slider-ripple-color($theme, primary);
32-
@include token-utils.create-token-values(
33-
m2-mat-slider.$prefix,
34-
$mat-slider-color-tokens
35-
);
38+
// Add values for MDC slider tokens.
39+
.mat-mdc-slider {
40+
@include mdc-slider-theme.theme($mdc-color-tokens);
41+
@include _slider-ripple-color($theme, primary);
42+
@include token-utils.create-token-values(
43+
tokens-mat-slider.$prefix,
44+
$mat-slider-color-tokens
45+
);
3646

37-
&.mat-accent {
38-
@include mdc-slider-theme.theme(
39-
m2-mdc-slider.private-get-color-palette-color-tokens($theme, accent));
40-
@include _slider-ripple-color($theme, accent);
41-
}
47+
&.mat-accent {
48+
@include mdc-slider-theme.theme(
49+
tokens-mdc-slider.private-get-color-palette-color-tokens($theme, accent));
50+
@include _slider-ripple-color($theme, accent);
51+
}
4252

43-
&.mat-warn {
44-
@include mdc-slider-theme.theme(
45-
m2-mdc-slider.private-get-color-palette-color-tokens($theme, warn));
46-
@include _slider-ripple-color($theme, warn);
53+
&.mat-warn {
54+
@include mdc-slider-theme.theme(
55+
tokens-mdc-slider.private-get-color-palette-color-tokens($theme, warn));
56+
@include _slider-ripple-color($theme, warn);
57+
}
4758
}
4859
}
4960
}
5061

5162
@mixin typography($theme) {
52-
// Add values for MDC slider tokens.
53-
.mat-mdc-slider {
54-
@include mdc-slider-theme.theme(m2-mdc-slider.get-typography-tokens($theme));
63+
@if inspection.get-theme-version($theme) == 1 {
64+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
65+
}
66+
@else {
67+
// Add values for MDC slider tokens.
68+
.mat-mdc-slider {
69+
@include mdc-slider-theme.theme(tokens-mdc-slider.get-typography-tokens($theme));
70+
}
5571
}
5672
}
5773

5874
@mixin density($theme) {
59-
// Add values for MDC slider tokens.
60-
.mat-mdc-slider {
61-
@include mdc-slider-theme.theme(m2-mdc-slider.get-density-tokens($theme));
75+
@if inspection.get-theme-version($theme) == 1 {
76+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
77+
}
78+
@else {
79+
// Add values for MDC slider tokens.
80+
.mat-mdc-slider {
81+
@include mdc-slider-theme.theme(tokens-mdc-slider.get-density-tokens($theme));
82+
}
6283
}
6384
}
6485

6586
@mixin theme($theme) {
6687
@include theming.private-check-duplicate-theme-styles($theme, 'mat-slider') {
67-
@include base($theme);
68-
@if inspection.theme-has($theme, color) {
69-
@include color($theme);
70-
}
71-
@if inspection.theme-has($theme, density) {
72-
@include density($theme);
88+
@if inspection.get-theme-version($theme) == 1 {
89+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
7390
}
74-
@if inspection.theme-has($theme, typography) {
75-
@include typography($theme);
91+
@else {
92+
@include base($theme);
93+
@if inspection.theme-has($theme, color) {
94+
@include color($theme);
95+
}
96+
@if inspection.theme-has($theme, density) {
97+
@include density($theme);
98+
}
99+
@if inspection.theme-has($theme, typography) {
100+
@include typography($theme);
101+
}
76102
}
77103
}
78104
}
@@ -85,3 +111,11 @@
85111
--mat-mdc-slider-hover-ripple-color: #{rgba($color, 0.05)};
86112
--mat-mdc-slider-focus-ripple-color: #{rgba($color, 0.2)};
87113
}
114+
115+
@mixin _theme-from-tokens($tokens) {
116+
@if ($tokens != ()) {
117+
@include mdc-slider-theme.theme(map.get($tokens, tokens-mdc-slider.$prefix));
118+
@include token-utils.create-token-values(
119+
tokens-mat-slider.$prefix, map.get($tokens, tokens-mat-slider.$prefix));
120+
}
121+
}

0 commit comments

Comments
 (0)