Skip to content

Commit 5f44f80

Browse files
committed
feat(material-experimental/theming): add M3 sidenav support
1 parent 8768d99 commit 5f44f80

File tree

6 files changed

+79
-18
lines changed

6 files changed

+79
-18
lines changed

src/dev-app/theme-m3.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ html {
4343
@include mat.progress-spinner-theme($light-theme);
4444
@include mat.radio-theme($light-theme);
4545
@include mat.ripple-theme($light-theme);
46+
@include mat.sidenav-theme($light-theme);
4647
@include mat.slide-toggle-theme($light-theme);
4748
@include mat.slider-theme($light-theme);
4849
@include mat.snack-bar-theme($light-theme);
@@ -68,6 +69,7 @@ html {
6869
@include mat.progress-spinner-color($dark-theme);
6970
@include mat.radio-color($dark-theme);
7071
@include mat.ripple-color($dark-theme);
72+
@include mat.sidenav-color($dark-theme);
7173
@include mat.slide-toggle-color($dark-theme);
7274
@include mat.slider-color($dark-theme);
7375
@include mat.snack-bar-color($dark-theme);
@@ -91,6 +93,7 @@ html {
9193
@include mat.progress-bar-density($scale-theme);
9294
@include mat.progress-spinner-density($scale-theme);
9395
@include mat.radio-density($scale-theme);
96+
@include mat.sidenav-density($scale-theme);
9497
@include mat.slide-toggle-density($scale-theme);
9598
@include mat.slider-density($scale-theme);
9699
@include mat.snack-bar-density($scale-theme);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@
9999
);
100100
}
101101

102+
/// Generates custom tokens for the mat-sidenav.
103+
/// @param {Map} $systems The MDC system tokens
104+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
105+
/// @return {Map} A set of custom tokens for the mat-sidenav
106+
@function sidenav($systems, $exclude-hardcoded) {
107+
@return (
108+
container-shape: 16px,
109+
container-divider-color: map.get($systems, md-sys-color, outline),
110+
container-background-color: map.get($systems, md-sys-color, surface),
111+
container-text-color: map.get($systems, md-sys-color, on-surface-variant),
112+
content-background-color: _hardcode(inherit, $exclude-hardcoded),
113+
content-text-color: _hardcode(inherit, $exclude-hardcoded),
114+
scrim-color: mat.private-safe-color-change(
115+
map.get($systems, md-ref-palette, neutral-variant20), $alpha: 0.4),
116+
);
117+
}
118+
102119
/// Generates custom tokens for the mat-sort.
103120
/// @param {Map} $systems The MDC system tokens
104121
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ $_density-tokens: (
5050
(mat, snack-bar): (),
5151
(mat, radio): (),
5252
(mat, ripple): (),
53+
(mat, sidenav): (),
5354
(mat, slide-toggle): (),
5455
(mat, sort): (),
5556
(mat, stepper): (

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@
245245
custom-tokens.card($systems, $exclude-hardcoded),
246246
$token-slots
247247
),
248+
_namespace-tokens(
249+
(mat, sidenav),
250+
custom-tokens.sidenav($systems, $exclude-hardcoded),
251+
$token-slots
252+
),
248253
_namespace-tokens(
249254
(mat, toolbar),
250255
custom-tokens.toolbar($systems, $exclude-hardcoded),
@@ -329,11 +334,11 @@
329334
$sys-color: if($type == dark,
330335
mdc-tokens.md-sys-color-values-dark($ref),
331336
mdc-tokens.md-sys-color-values-light($ref));
332-
@return _generate-tokens((
337+
@return _generate-tokens(map.merge($ref, (
333338
md-sys-color: $sys-color,
334339
md-sys-elevation: mdc-tokens.md-sys-elevation-values(),
335340
md-sys-state: mdc-tokens.md-sys-state-values(),
336-
));
341+
)));
337342
}
338343

339344
/// Generates a set of namespaced color tokens for all components.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@use './mat/card' as tokens-mat-card;
55
@use './mat/radio' as tokens-mat-radio;
66
@use './mat/ripple' as tokens-mat-ripple;
7+
@use './mat/sidenav' as tokens-mat-sidenav;
78
@use './mat/slide-toggle' as tokens-mat-slide-toggle;
89
@use './mat/slider' as tokens-mat-slider;
910
@use './mat/snack-bar' as tokens-mat-snack-bar;
@@ -76,6 +77,7 @@
7677
_get-tokens-for-module($theme, tokens-mat-card),
7778
_get-tokens-for-module($theme, tokens-mat-radio),
7879
_get-tokens-for-module($theme, tokens-mat-ripple),
80+
_get-tokens-for-module($theme, tokens-mat-sidenav),
7981
_get-tokens-for-module($theme, tokens-mat-slide-toggle),
8082
_get-tokens-for-module($theme, tokens-mat-slider),
8183
_get-tokens-for-module($theme, tokens-mat-snack-bar),
Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,71 @@
1+
@use 'sass:map';
12
@use '../core/theming/theming';
23
@use '../core/theming/inspection';
34
@use '../core/tokens/m2/mat/sidenav' as tokens-mat-sidenav;
45
@use '../core/tokens/token-utils';
56
@use '../core/style/sass-utils';
67

78
@mixin base($theme) {
8-
@include sass-utils.current-selector-or-root() {
9-
@include token-utils.create-token-values(
10-
tokens-mat-sidenav.$prefix, tokens-mat-sidenav.get-unthemable-tokens());
9+
@if inspection.get-theme-version($theme) == 1 {
10+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
11+
}
12+
@else {
13+
@include sass-utils.current-selector-or-root() {
14+
@include token-utils.create-token-values(
15+
tokens-mat-sidenav.$prefix, tokens-mat-sidenav.get-unthemable-tokens());
16+
}
1117
}
1218
}
1319

1420
@mixin color($theme) {
15-
@include sass-utils.current-selector-or-root() {
16-
@include token-utils.create-token-values(tokens-mat-sidenav.$prefix,
17-
tokens-mat-sidenav.get-color-tokens($theme));
21+
@if inspection.get-theme-version($theme) == 1 {
22+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
23+
}
24+
@else {
25+
@include sass-utils.current-selector-or-root() {
26+
@include token-utils.create-token-values(tokens-mat-sidenav.$prefix,
27+
tokens-mat-sidenav.get-color-tokens($theme));
28+
}
1829
}
1930
}
2031

21-
@mixin typography($theme) {}
32+
@mixin typography($theme) {
33+
@if inspection.get-theme-version($theme) == 1 {
34+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
35+
}
36+
@else {}
37+
}
2238

23-
@mixin density($theme) {}
39+
@mixin density($theme) {
40+
@if inspection.get-theme-version($theme) == 1 {
41+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
42+
}
43+
@else {}
44+
}
2445

2546
@mixin theme($theme) {
2647
@include theming.private-check-duplicate-theme-styles($theme, 'mat-sidenav') {
27-
@include base($theme);
28-
@if inspection.theme-has($theme, color) {
29-
@include color($theme);
48+
@if inspection.get-theme-version($theme) == 1 {
49+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
3050
}
31-
@if inspection.theme-has($theme, density) {
32-
@include density($theme);
33-
}
34-
@if inspection.theme-has($theme, typography) {
35-
@include typography($theme);
51+
@else {
52+
@include base($theme);
53+
@if inspection.theme-has($theme, color) {
54+
@include color($theme);
55+
}
56+
@if inspection.theme-has($theme, density) {
57+
@include density($theme);
58+
}
59+
@if inspection.theme-has($theme, typography) {
60+
@include typography($theme);
61+
}
3662
}
3763
}
3864
}
65+
66+
@mixin _theme-from-tokens($tokens) {
67+
@if ($tokens != ()) {
68+
@include token-utils.create-token-values(
69+
tokens-mat-sidenav.$prefix, map.get($tokens, tokens-mat-sidenav.$prefix));
70+
}
71+
}

0 commit comments

Comments
 (0)