Skip to content

Commit a703251

Browse files
committed
feat(material-experimental/theming): add M3 sidenav support
1 parent d77781a commit a703251

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
@@ -45,6 +45,7 @@ html {
4545
@include mat.progress-spinner-theme($light-theme);
4646
@include mat.radio-theme($light-theme);
4747
@include mat.ripple-theme($light-theme);
48+
@include mat.sidenav-theme($light-theme);
4849
@include mat.slide-toggle-theme($light-theme);
4950
@include mat.slider-theme($light-theme);
5051
@include mat.snack-bar-theme($light-theme);
@@ -72,6 +73,7 @@ html {
7273
@include mat.progress-spinner-color($dark-theme);
7374
@include mat.radio-color($dark-theme);
7475
@include mat.ripple-color($dark-theme);
76+
@include mat.sidenav-color($dark-theme);
7577
@include mat.slide-toggle-color($dark-theme);
7678
@include mat.slider-color($dark-theme);
7779
@include mat.snack-bar-color($dark-theme);
@@ -97,6 +99,7 @@ html {
9799
@include mat.progress-bar-density($scale-theme);
98100
@include mat.progress-spinner-density($scale-theme);
99101
@include mat.radio-density($scale-theme);
102+
@include mat.sidenav-density($scale-theme);
100103
@include mat.slide-toggle-density($scale-theme);
101104
@include mat.slider-density($scale-theme);
102105
@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
@@ -126,6 +126,23 @@
126126
);
127127
}
128128

129+
/// Generates custom tokens for the mat-sidenav.
130+
/// @param {Map} $systems The MDC system tokens
131+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
132+
/// @return {Map} A set of custom tokens for the mat-sidenav
133+
@function sidenav($systems, $exclude-hardcoded) {
134+
@return (
135+
container-shape: 16px,
136+
container-divider-color: map.get($systems, md-sys-color, outline),
137+
container-background-color: map.get($systems, md-sys-color, surface),
138+
container-text-color: map.get($systems, md-sys-color, on-surface-variant),
139+
content-background-color: _hardcode(inherit, $exclude-hardcoded),
140+
content-text-color: _hardcode(inherit, $exclude-hardcoded),
141+
scrim-color: mat.private-safe-color-change(
142+
map.get($systems, md-ref-palette, neutral-variant20), $alpha: 0.4),
143+
);
144+
}
145+
129146
/// Generates custom tokens for the mat-sort.
130147
/// @param {Map} $systems The MDC system tokens
131148
/// @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
@@ -53,6 +53,7 @@ $_density-tokens: (
5353
(mat, snack-bar): (),
5454
(mat, radio): (),
5555
(mat, ripple): (),
56+
(mat, sidenav): (),
5657
(mat, slide-toggle): (),
5758
(mat, sort): (),
5859
(mat, stepper): (

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@
264264
custom-tokens.form-field($systems, $exclude-hardcoded),
265265
$token-slots
266266
),
267+
_namespace-tokens(
268+
(mat, sidenav),
269+
custom-tokens.sidenav($systems, $exclude-hardcoded),
270+
$token-slots
271+
),
267272
_namespace-tokens(
268273
(mat, toolbar),
269274
custom-tokens.toolbar($systems, $exclude-hardcoded),
@@ -347,11 +352,11 @@
347352
$sys-color: if($type == dark,
348353
mdc-tokens.md-sys-color-values-dark($ref),
349354
mdc-tokens.md-sys-color-values-light($ref));
350-
@return _generate-tokens((
355+
@return _generate-tokens(map.merge($ref, (
351356
md-sys-color: $sys-color,
352357
md-sys-elevation: mdc-tokens.md-sys-elevation-values(),
353358
md-sys-state: mdc-tokens.md-sys-state-values(),
354-
));
359+
)));
355360
}
356361

357362
/// 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
@@ -5,6 +5,7 @@
55
@use './mat/form-field' as tokens-mat-form-field;
66
@use './mat/radio' as tokens-mat-radio;
77
@use './mat/ripple' as tokens-mat-ripple;
8+
@use './mat/sidenav' as tokens-mat-sidenav;
89
@use './mat/slide-toggle' as tokens-mat-slide-toggle;
910
@use './mat/slider' as tokens-mat-slider;
1011
@use './mat/snack-bar' as tokens-mat-snack-bar;
@@ -80,6 +81,7 @@
8081
_get-tokens-for-module($theme, tokens-mat-form-field),
8182
_get-tokens-for-module($theme, tokens-mat-radio),
8283
_get-tokens-for-module($theme, tokens-mat-ripple),
84+
_get-tokens-for-module($theme, tokens-mat-sidenav),
8385
_get-tokens-for-module($theme, tokens-mat-slide-toggle),
8486
_get-tokens-for-module($theme, tokens-mat-slider),
8587
_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)