Skip to content

Commit 42887c3

Browse files
committed
feat(material-experimental/theming): add M3 datepicker support
1 parent 2963b7a commit 42887c3

File tree

6 files changed

+152
-39
lines changed

6 files changed

+152
-39
lines changed

src/dev-app/theme-m3.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ dev-app {
2424
// Base theme configuration for our M3 theme.
2525
$m3-base-config: (
2626
color: (
27-
primary: matx.$m3-green-palette
27+
primary: matx.$m3-green-palette,
28+
secondary: matx.$m3-blue-palette,
29+
tertiary: matx.$m3-yellow-palette,
2830
),
2931
);
3032

@@ -38,6 +40,7 @@ $dark-theme: matx.define-theme(map.set($m3-base-config, color, theme-type, dark)
3840
html {
3941
@include mat.card-theme($light-theme);
4042
@include mat.checkbox-theme($light-theme);
43+
@include mat.datepicker-theme($light-theme);
4144
@include mat.divider-theme($light-theme);
4245
@include mat.fab-theme($light-theme);
4346
@include mat.form-field-theme($light-theme);
@@ -75,6 +78,7 @@ html {
7578

7679
@include mat.card-color($dark-theme);
7780
@include mat.checkbox-color($dark-theme);
81+
@include mat.datepicker-color($dark-theme);
7882
@include mat.divider-color($dark-theme);
7983
@include mat.fab-color($dark-theme);
8084
@include mat.form-field-color($dark-theme);
@@ -111,6 +115,7 @@ html {
111115
.demo-density-#{$scale} {
112116
@include mat.card-density($scale-theme);
113117
@include mat.checkbox-density($scale-theme);
118+
@include mat.datepicker-density($scale-theme);
114119
@include mat.divider-density($scale-theme);
115120
@include mat.fab-density($scale-theme);
116121
@include mat.form-field-density($scale-theme);

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,76 @@
3535
);
3636
}
3737

38+
/// Generates custom tokens for the mat-datepicker.
39+
/// @param {Map} $systems The MDC system tokens
40+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
41+
/// @return {Map} A set of custom tokens for the mat-datepicker
42+
@function datepicker($systems, $exclude-hardcoded) {
43+
@return (
44+
calendar-date-in-range-state-background-color:
45+
map.get($systems, md-sys-color, primary-container),
46+
calendar-date-in-comparison-range-state-background-color:
47+
map.get($systems, md-sys-color, secondary-container),
48+
calendar-date-in-overlap-range-state-background-color:
49+
map.get($systems, md-sys-color, tertiary-container),
50+
calendar-date-in-overlap-range-selected-state-background-color:
51+
map.get($systems, md-sys-color, tertiary),
52+
calendar-date-selected-state-text-color: map.get($systems, md-sys-color, on-primary),
53+
calendar-date-selected-state-background-color: map.get($systems, md-sys-color, primary),
54+
calendar-date-selected-disabled-state-background-color: mat.private-safe-color-change(
55+
map.get($systems, md-sys-color, on-surface),
56+
$alpha: 0.38
57+
),
58+
calendar-date-today-selected-state-outline-color: map.get($systems, md-sys-color, primary),
59+
calendar-date-focus-state-background-color: mat.private-safe-color-change(
60+
map.get($systems, md-sys-color, on-surface),
61+
$alpha: map.get($systems, md-sys-state, focus-state-layer-opacity)
62+
),
63+
calendar-date-hover-state-background-color: mat.private-safe-color-change(
64+
map.get($systems, md-sys-color, on-surface),
65+
$alpha: map.get($systems, md-sys-state, hover-state-layer-opacity)
66+
),
67+
toggle-active-state-icon-color: map.get($systems, md-sys-color, on-surface-variant),
68+
toggle-icon-color: map.get($systems, md-sys-color, on-surface-variant),
69+
calendar-body-label-text-color: map.get($systems, md-sys-color, on-surface),
70+
calendar-period-button-icon-color: map.get($systems, md-sys-color, on-surface-variant),
71+
calendar-navigation-button-icon-color: map.get($systems, md-sys-color, on-surface-variant),
72+
calendar-header-divider-color: map.get($systems, md-sys-color, outline-variant),
73+
calendar-header-text-color: map.get($systems, md-sys-color, on-surface-variant),
74+
calendar-date-today-outline-color: map.get($systems, md-sys-color, primary),
75+
calendar-date-today-disabled-state-outline-color: mat.private-safe-color-change(
76+
map.get($systems, md-sys-color, on-surface),
77+
$alpha: 0.38
78+
),
79+
calendar-date-text-color: map.get($systems, md-sys-color, on-surface),
80+
calendar-date-outline-color: _hardcode(transparent, $exclude-hardcoded),
81+
calendar-date-disabled-state-text-color: mat.private-safe-color-change(
82+
map.get($systems, md-sys-color, on-surface),
83+
$alpha: 0.38
84+
),
85+
calendar-date-preview-state-outline-color: map.get($systems, md-sys-color, primary),
86+
range-input-separator-color: map.get($systems, md-sys-color, on-surface),
87+
range-input-disabled-state-separator-color: mat.private-safe-color-change(
88+
map.get($systems, md-sys-color, on-surface),
89+
$alpha: 0.38
90+
),
91+
range-input-disabled-state-text-color: mat.private-safe-color-change(
92+
map.get($systems, md-sys-color, on-surface),
93+
$alpha: 0.38
94+
),
95+
calendar-container-background-color: map.get($systems, md-sys-color, surface-container-high),
96+
calendar-container-text-color: map.get($systems, md-sys-color, on-surface),
97+
calendar-text-font: map.get($systems, md-sys-typescale, body-large-font),
98+
calendar-text-size: map.get($systems, md-sys-typescale, body-large-size),
99+
calendar-body-label-text-size: map.get($systems, md-sys-typescale, title-small-size),
100+
calendar-body-label-text-weight: map.get($systems, md-sys-typescale, title-small-weight),
101+
calendar-period-button-text-size: map.get($systems, md-sys-typescale, title-small-size),
102+
calendar-period-button-text-weight: map.get($systems, md-sys-typescale, title-small-weight),
103+
calendar-header-text-size: map.get($systems, md-sys-typescale, title-small-size),
104+
calendar-header-text-weight: map.get($systems, md-sys-typescale, title-small-weight),
105+
);
106+
}
107+
38108
/// Generates custom tokens for the mat-divider.
39109
/// @param {Map} $systems The MDC system tokens
40110
/// @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
@@ -49,6 +49,7 @@ $_density-tokens: (
4949

5050
// Custom Angular Material tokens
5151
(mat, card): (),
52+
(mat, datepicker): (),
5253
(mat, divider): (),
5354
(mat, fab): (),
5455
(mat, form-fild): (),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@
270270
custom-tokens.card($systems, $exclude-hardcoded),
271271
$token-slots
272272
),
273+
_namespace-tokens(
274+
(mat, datepicker),
275+
custom-tokens.datepicker($systems, $exclude-hardcoded),
276+
$token-slots
277+
),
273278
_namespace-tokens(
274279
(mat, divider),
275280
custom-tokens.divider($systems, $exclude-hardcoded),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@use 'sass:meta';
33
@use '../../style/sass-utils';
44
@use './mat/card' as tokens-mat-card;
5+
@use './mat/datepicker' as tokens-mat-datepicker;
56
@use './mat/divider' as tokens-mat-divider;
67
@use './mat/fab' as tokens-mat-fab;
78
@use './mat/form-field' as tokens-mat-form-field;
@@ -89,6 +90,7 @@
8990
@function m2-tokens-from-theme($theme) {
9091
@return sass-utils.deep-merge-all(
9192
_get-tokens-for-module($theme, tokens-mat-card),
93+
_get-tokens-for-module($theme, tokens-mat-datepicker),
9294
_get-tokens-for-module($theme, tokens-mat-divider),
9395
_get-tokens-for-module($theme, tokens-mat-fab),
9496
_get-tokens-for-module($theme, tokens-mat-form-field),

src/material/datepicker/_datepicker-theme.scss

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,56 @@ $calendar-weekday-table-font-size: 11px !default;
2727
map.merge($calendar-tokens, $range-tokens));
2828
}
2929

30-
@mixin base($theme) {}
30+
@mixin base($theme) {
31+
@if inspection.get-theme-version($theme) == 1 {
32+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
33+
}
34+
@else {}
35+
}
3136

3237
@mixin color($theme) {
33-
@include sass-utils.current-selector-or-root() {
34-
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
35-
tokens-mat-datepicker.get-color-tokens($theme));
38+
@if inspection.get-theme-version($theme) == 1 {
39+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
3640
}
37-
38-
.mat-datepicker-content {
39-
&.mat-accent {
40-
@include _calendar-color($theme, accent);
41+
@else {
42+
@include sass-utils.current-selector-or-root() {
43+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
44+
tokens-mat-datepicker.get-color-tokens($theme));
4145
}
4246

43-
&.mat-warn {
44-
@include _calendar-color($theme, warn);
45-
}
46-
}
47+
.mat-datepicker-content {
48+
&.mat-accent {
49+
@include _calendar-color($theme, accent);
50+
}
4751

48-
.mat-datepicker-toggle-active {
49-
&.mat-accent {
50-
$accent-tokens:
51-
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, accent);
52-
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $accent-tokens);
52+
&.mat-warn {
53+
@include _calendar-color($theme, warn);
54+
}
5355
}
5456

55-
&.mat-warn {
56-
$warn-tokens:
57-
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, warn);
58-
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $warn-tokens);
57+
.mat-datepicker-toggle-active {
58+
&.mat-accent {
59+
$accent-tokens: tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, accent);
60+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $accent-tokens);
61+
}
62+
63+
&.mat-warn {
64+
$warn-tokens: tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, warn);
65+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $warn-tokens);
66+
}
5967
}
6068
}
6169
}
6270

6371
@mixin typography($theme) {
64-
@include sass-utils.current-selector-or-root() {
65-
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
66-
tokens-mat-datepicker.get-typography-tokens($theme));
72+
@if inspection.get-theme-version($theme) == 1 {
73+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
74+
}
75+
@else {
76+
@include sass-utils.current-selector-or-root() {
77+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
78+
tokens-mat-datepicker.get-typography-tokens($theme));
79+
}
6780
}
6881
}
6982

@@ -86,27 +99,44 @@ $calendar-weekday-table-font-size: 11px !default;
8699
}
87100

88101
@mixin density($theme) {
89-
// TODO(crisbeto): move this into the structural styles
90-
// once the icon button density is switched to tokens.
102+
@if inspection.get-theme-version($theme) == 1 {
103+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
104+
}
105+
@else {
106+
// TODO(crisbeto): move this into the structural styles
107+
// once the icon button density is switched to tokens.
91108

92-
// Regardless of the user-passed density, we want the calendar
93-
// previous/next buttons to remain at density -2
94-
.mat-calendar-controls {
95-
@include icon-button-theme.density(-2);
109+
// Regardless of the user-passed density, we want the calendar
110+
// previous/next buttons to remain at density -2
111+
.mat-calendar-controls {
112+
@include icon-button-theme.density(-2);
113+
}
96114
}
97115
}
98116

99117
@mixin theme($theme) {
100118
@include theming.private-check-duplicate-theme-styles($theme, 'mat-datepicker') {
101-
@include base($theme);
102-
@if inspection.theme-has($theme, color) {
103-
@include color($theme);
119+
@if inspection.get-theme-version($theme) == 1 {
120+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
104121
}
105-
@if inspection.theme-has($theme, density) {
106-
@include density($theme);
107-
}
108-
@if inspection.theme-has($theme, typography) {
109-
@include typography($theme);
122+
@else {
123+
@include base($theme);
124+
@if inspection.theme-has($theme, color) {
125+
@include color($theme);
126+
}
127+
@if inspection.theme-has($theme, density) {
128+
@include density($theme);
129+
}
130+
@if inspection.theme-has($theme, typography) {
131+
@include typography($theme);
132+
}
110133
}
111134
}
112135
}
136+
137+
@mixin _theme-from-tokens($tokens) {
138+
@if ($tokens != ()) {
139+
@include token-utils.create-token-values(
140+
tokens-mat-datepicker.$prefix, map.get($tokens, tokens-mat-datepicker.$prefix));
141+
}
142+
}

0 commit comments

Comments
 (0)