Skip to content

Commit 6b57edb

Browse files
authored
feat(material-experimental/theming): add M3 snackbar support (#27824)
1 parent 1930b1d commit 6b57edb

File tree

4 files changed

+72
-21
lines changed

4 files changed

+72
-21
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.snack-bar-theme($light-theme);
4344
}
4445

4546
// Emit dark theme styles.
@@ -52,6 +53,7 @@ html {
5253
@include mat.card-color($dark-theme);
5354
@include mat.tooltip-color($dark-theme);
5455
@include mat.toolbar-color($dark-theme);
56+
@include mat.snack-bar-color($dark-theme);
5557
}
5658

5759
// Emit density styles for each scale.
@@ -63,5 +65,6 @@ html {
6365
@include mat.card-density($scale-theme);
6466
@include mat.tooltip-density($scale-theme);
6567
@include mat.toolbar-density($scale-theme);
68+
@include mat.snack-bar-density($scale-theme);
6669
}
6770
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$result: ();
1212
@each $prop in (font, line-height, size, tracking, weight) {
1313
$result: map.set($result, #{$base-name}-#{$prop},
14-
map.get($systems, md-sys-typescale, #{$typography-level}-#{$prop}));
14+
map.get($systems, md-sys-typescale, #{$typography-level}-#{$prop}));
1515
}
1616
@return $result;
1717
}
@@ -43,3 +43,13 @@
4343
)
4444
);
4545
}
46+
47+
/// Generates custom tokens for the mat-snack-bar.
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-snack-bar
51+
@function snack-bar($systems, $exclude-hardcoded) {
52+
@return (
53+
button-color: map.get($systems, md-sys-color, inverse-primary),
54+
);
55+
}

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

Lines changed: 12 additions & 2 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, snackbar),
193+
mdc-tokens.md-comp-snackbar-values($systems, $exclude-hardcoded),
194+
$token-slots,
195+
),
191196
_namespace-tokens(
192197
(mdc, plain-tooltip),
193198
mdc-tokens.md-comp-plain-tooltip-values($systems, $exclude-hardcoded),
@@ -203,8 +208,13 @@
203208
_namespace-tokens(
204209
(mat, toolbar),
205210
custom-tokens.toolbar($systems, $exclude-hardcoded),
206-
$token-slots,
207-
)
211+
$token-slots,
212+
),
213+
_namespace-tokens(
214+
(mat, snack-bar),
215+
custom-tokens.snack-bar($systems, $exclude-hardcoded),
216+
$token-slots
217+
),
208218
);
209219

210220
// Strip out tokens that are systemized by our made up density system.
Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use 'sass:map';
12
@use '@material/snackbar/snackbar-theme' as mdc-snackbar-theme;
23
@use '../core/theming/theming';
34
@use '../core/theming/inspection';
@@ -8,42 +9,69 @@
89
@use '../core/tokens/m2/mat/snack-bar' as tokens-mat-snack-bar;
910

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

1723
@mixin color($theme) {
18-
@include sass-utils.current-selector-or-root() {
19-
@include mdc-snackbar-theme.theme(tokens-mdc-snack-bar.get-color-tokens($theme));
20-
@include token-utils.create-token-values(
21-
tokens-mat-snack-bar.$prefix,
22-
tokens-mat-snack-bar.get-color-tokens($theme)
23-
);
24+
@if inspection.get-theme-version($theme) == 1 {
25+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
26+
}
27+
@else {
28+
@include sass-utils.current-selector-or-root() {
29+
@include mdc-snackbar-theme.theme(tokens-mdc-snack-bar.get-color-tokens($theme));
30+
@include token-utils.create-token-values(
31+
tokens-mat-snack-bar.$prefix,
32+
tokens-mat-snack-bar.get-color-tokens($theme)
33+
);
34+
}
2435
}
2536
}
2637

2738
@mixin typography($theme) {
28-
@include sass-utils.current-selector-or-root() {
29-
@include mdc-snackbar-theme.theme(tokens-mdc-snack-bar.get-typography-tokens($theme));
39+
@if inspection.get-theme-version($theme) == 1 {
40+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
41+
}
42+
@else {
43+
@include sass-utils.current-selector-or-root() {
44+
@include mdc-snackbar-theme.theme(tokens-mdc-snack-bar.get-typography-tokens($theme));
45+
}
3046
}
3147
}
3248

3349
@mixin density($theme) {}
3450

3551
@mixin theme($theme) {
3652
@include theming.private-check-duplicate-theme-styles($theme, 'mat-snack-bar') {
37-
@include base($theme);
38-
@if inspection.theme-has($theme, color) {
39-
@include color($theme);
40-
}
41-
@if inspection.theme-has($theme, density) {
42-
@include density($theme);
53+
@if inspection.get-theme-version($theme) == 1 {
54+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
4355
}
44-
@if inspection.theme-has($theme, typography) {
45-
@include typography($theme);
56+
@else {
57+
@include base($theme);
58+
@if inspection.theme-has($theme, color) {
59+
@include color($theme);
60+
}
61+
@if inspection.theme-has($theme, density) {
62+
@include density($theme);
63+
}
64+
@if inspection.theme-has($theme, typography) {
65+
@include typography($theme);
66+
}
4667
}
4768
}
4869
}
4970

71+
@mixin _theme-from-tokens($tokens) {
72+
@if ($tokens != ()) {
73+
@include mdc-snackbar-theme.theme(map.get($tokens, tokens-mdc-snack-bar.$prefix));
74+
@include token-utils.create-token-values(
75+
tokens-mat-snack-bar.$prefix, map.get($tokens, tokens-mat-snack-bar.$prefix));
76+
}
77+
}

0 commit comments

Comments
 (0)