Skip to content

Commit d5d0cd2

Browse files
committed
feat(material-experimental/theming): add M3 sidenav support
1 parent 38e4ff7 commit d5d0cd2

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
@@ -47,6 +47,7 @@ html {
4747
@include mat.progress-spinner-theme($light-theme);
4848
@include mat.radio-theme($light-theme);
4949
@include mat.ripple-theme($light-theme);
50+
@include mat.sidenav-theme($light-theme);
5051
@include mat.slide-toggle-theme($light-theme);
5152
@include mat.slider-theme($light-theme);
5253
@include mat.snack-bar-theme($light-theme);
@@ -76,6 +77,7 @@ html {
7677
@include mat.progress-spinner-color($dark-theme);
7778
@include mat.radio-color($dark-theme);
7879
@include mat.ripple-color($dark-theme);
80+
@include mat.sidenav-color($dark-theme);
7981
@include mat.slide-toggle-color($dark-theme);
8082
@include mat.slider-color($dark-theme);
8183
@include mat.snack-bar-color($dark-theme);
@@ -103,6 +105,7 @@ html {
103105
@include mat.progress-bar-density($scale-theme);
104106
@include mat.progress-spinner-density($scale-theme);
105107
@include mat.radio-density($scale-theme);
108+
@include mat.sidenav-density($scale-theme);
106109
@include mat.slide-toggle-density($scale-theme);
107110
@include mat.slider-density($scale-theme);
108111
@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
@@ -149,6 +149,23 @@
149149
);
150150
}
151151

152+
/// Generates custom tokens for the mat-sidenav.
153+
/// @param {Map} $systems The MDC system tokens
154+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
155+
/// @return {Map} A set of custom tokens for the mat-sidenav
156+
@function sidenav($systems, $exclude-hardcoded) {
157+
@return (
158+
container-shape: 16px,
159+
container-divider-color: map.get($systems, md-sys-color, outline),
160+
container-background-color: map.get($systems, md-sys-color, surface),
161+
container-text-color: map.get($systems, md-sys-color, on-surface-variant),
162+
content-background-color: _hardcode(inherit, $exclude-hardcoded),
163+
content-text-color: _hardcode(inherit, $exclude-hardcoded),
164+
scrim-color: mat.private-safe-color-change(
165+
map.get($systems, md-ref-palette, neutral-variant20), $alpha: 0.4),
166+
);
167+
}
168+
152169
/// Generates custom tokens for the mat-sort.
153170
/// @param {Map} $systems The MDC system tokens
154171
/// @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
@@ -55,6 +55,7 @@ $_density-tokens: (
5555
(mat, snack-bar): (),
5656
(mat, radio): (),
5757
(mat, ripple): (),
58+
(mat, sidenav): (),
5859
(mat, slide-toggle): (),
5960
(mat, sort): (),
6061
(mat, stepper): (

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@
274274
custom-tokens.icon($systems, $exclude-hardcoded),
275275
$token-slots
276276
),
277+
_namespace-tokens(
278+
(mat, sidenav),
279+
custom-tokens.sidenav($systems, $exclude-hardcoded),
280+
$token-slots
281+
),
277282
_namespace-tokens(
278283
(mat, toolbar),
279284
custom-tokens.toolbar($systems, $exclude-hardcoded),
@@ -357,11 +362,11 @@
357362
$sys-color: if($type == dark,
358363
mdc-tokens.md-sys-color-values-dark($ref),
359364
mdc-tokens.md-sys-color-values-light($ref));
360-
@return _generate-tokens((
365+
@return _generate-tokens(map.merge($ref, (
361366
md-sys-color: $sys-color,
362367
md-sys-elevation: mdc-tokens.md-sys-elevation-values(),
363368
md-sys-state: mdc-tokens.md-sys-state-values(),
364-
));
369+
)));
365370
}
366371

367372
/// 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
@@ -7,6 +7,7 @@
77
@use './mat/icon' as tokens-mat-icon;
88
@use './mat/radio' as tokens-mat-radio;
99
@use './mat/ripple' as tokens-mat-ripple;
10+
@use './mat/sidenav' as tokens-mat-sidenav;
1011
@use './mat/slide-toggle' as tokens-mat-slide-toggle;
1112
@use './mat/slider' as tokens-mat-slider;
1213
@use './mat/snack-bar' as tokens-mat-snack-bar;
@@ -84,6 +85,7 @@
8485
_get-tokens-for-module($theme, tokens-mat-icon),
8586
_get-tokens-for-module($theme, tokens-mat-radio),
8687
_get-tokens-for-module($theme, tokens-mat-ripple),
88+
_get-tokens-for-module($theme, tokens-mat-sidenav),
8789
_get-tokens-for-module($theme, tokens-mat-slide-toggle),
8890
_get-tokens-for-module($theme, tokens-mat-slider),
8991
_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)