Skip to content

Commit 4b5a487

Browse files
committed
feat(material-experimental/theming): add M3 datepicker support
1 parent 2cb7ada commit 4b5a487

File tree

6 files changed

+154
-39
lines changed

6 files changed

+154
-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.dialog-theme($light-theme);
4245
@include mat.divider-theme($light-theme);
4346
@include mat.expansion-theme($light-theme);
@@ -78,6 +81,7 @@ html {
7881

7982
@include mat.card-color($dark-theme);
8083
@include mat.checkbox-color($dark-theme);
84+
@include mat.datepicker-color($dark-theme);
8185
@include mat.dialog-color($dark-theme);
8286
@include mat.divider-color($dark-theme);
8387
@include mat.expansion-color($dark-theme);
@@ -117,6 +121,7 @@ html {
117121
.demo-density-#{$scale} {
118122
@include mat.card-density($scale-theme);
119123
@include mat.checkbox-density($scale-theme);
124+
@include mat.datepicker-density($scale-theme);
120125
@include mat.dialog-density($scale-theme);
121126
@include mat.divider-density($scale-theme);
122127
@include mat.expansion-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
@@ -50,6 +50,7 @@ $_density-tokens: (
5050

5151
// Custom Angular Material tokens
5252
(mat, card): (),
53+
(mat, datepicker): (),
5354
(mat, divider): (),
5455
(mat, expansion): (
5556
header-collapsed-state-height: (48px, 44px, 40px, 36px),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@
275275
custom-tokens.card($systems, $exclude-hardcoded),
276276
$token-slots
277277
),
278+
_namespace-tokens(
279+
(mat, datepicker),
280+
custom-tokens.datepicker($systems, $exclude-hardcoded),
281+
$token-slots
282+
),
278283
_namespace-tokens(
279284
(mat, divider),
280285
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/expansion' as tokens-mat-expansion;
78
@use './mat/fab' as tokens-mat-fab;
@@ -91,6 +92,7 @@
9192
@function m2-tokens-from-theme($theme) {
9293
@return sass-utils.deep-merge-all(
9394
_get-tokens-for-module($theme, tokens-mat-card),
95+
_get-tokens-for-module($theme, tokens-mat-datepicker),
9496
_get-tokens-for-module($theme, tokens-mat-divider),
9597
_get-tokens-for-module($theme, tokens-mat-expansion),
9698
_get-tokens-for-module($theme, tokens-mat-fab),

src/material/datepicker/_datepicker-theme.scss

Lines changed: 70 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,58 @@ $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:
60+
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, accent);
61+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $accent-tokens);
62+
}
63+
64+
&.mat-warn {
65+
$warn-tokens:
66+
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, warn);
67+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $warn-tokens);
68+
}
5969
}
6070
}
6171
}
6272

6373
@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));
74+
@if inspection.get-theme-version($theme) == 1 {
75+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
76+
}
77+
@else {
78+
@include sass-utils.current-selector-or-root() {
79+
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
80+
tokens-mat-datepicker.get-typography-tokens($theme));
81+
}
6782
}
6883
}
6984

@@ -86,27 +101,44 @@ $calendar-weekday-table-font-size: 11px !default;
86101
}
87102

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

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);
111+
// Regardless of the user-passed density, we want the calendar
112+
// previous/next buttons to remain at density -2
113+
.mat-calendar-controls {
114+
@include icon-button-theme.density(-2);
115+
}
96116
}
97117
}
98118

99119
@mixin theme($theme) {
100120
@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);
121+
@if inspection.get-theme-version($theme) == 1 {
122+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
104123
}
105-
@if inspection.theme-has($theme, density) {
106-
@include density($theme);
107-
}
108-
@if inspection.theme-has($theme, typography) {
109-
@include typography($theme);
124+
@else {
125+
@include base($theme);
126+
@if inspection.theme-has($theme, color) {
127+
@include color($theme);
128+
}
129+
@if inspection.theme-has($theme, density) {
130+
@include density($theme);
131+
}
132+
@if inspection.theme-has($theme, typography) {
133+
@include typography($theme);
134+
}
110135
}
111136
}
112137
}
138+
139+
@mixin _theme-from-tokens($tokens) {
140+
@if ($tokens != ()) {
141+
@include token-utils.create-token-values(
142+
tokens-mat-datepicker.$prefix, map.get($tokens, tokens-mat-datepicker.$prefix));
143+
}
144+
}

0 commit comments

Comments
 (0)