Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(material-experimental/theming): add M3 datepicker support #28166

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/dev-app/theme-m3.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ dev-app {
// Base theme configuration for our M3 theme.
$m3-base-config: (
color: (
primary: matx.$m3-green-palette
primary: matx.$m3-green-palette,
secondary: matx.$m3-blue-palette,
tertiary: matx.$m3-yellow-palette,
),
);

Expand All @@ -38,6 +40,7 @@ $dark-theme: matx.define-theme(map.set($m3-base-config, color, theme-type, dark)
html {
@include mat.card-theme($light-theme);
@include mat.checkbox-theme($light-theme);
@include mat.datepicker-theme($light-theme);
@include mat.dialog-theme($light-theme);
@include mat.divider-theme($light-theme);
@include mat.expansion-theme($light-theme);
Expand Down Expand Up @@ -78,6 +81,7 @@ html {

@include mat.card-color($dark-theme);
@include mat.checkbox-color($dark-theme);
@include mat.datepicker-color($dark-theme);
@include mat.dialog-color($dark-theme);
@include mat.divider-color($dark-theme);
@include mat.expansion-color($dark-theme);
Expand Down Expand Up @@ -117,6 +121,7 @@ html {
.demo-density-#{$scale} {
@include mat.card-density($scale-theme);
@include mat.checkbox-density($scale-theme);
@include mat.datepicker-density($scale-theme);
@include mat.dialog-density($scale-theme);
@include mat.divider-density($scale-theme);
@include mat.expansion-density($scale-theme);
Expand Down
70 changes: 70 additions & 0 deletions src/material-experimental/theming/_custom-tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,76 @@
);
}

/// Generates custom tokens for the mat-datepicker.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
/// @return {Map} A set of custom tokens for the mat-datepicker
@function datepicker($systems, $exclude-hardcoded) {
@return (
calendar-date-in-range-state-background-color:
map.get($systems, md-sys-color, primary-container),
calendar-date-in-comparison-range-state-background-color:
map.get($systems, md-sys-color, secondary-container),
calendar-date-in-overlap-range-state-background-color:
map.get($systems, md-sys-color, tertiary-container),
calendar-date-in-overlap-range-selected-state-background-color:
map.get($systems, md-sys-color, tertiary),
calendar-date-selected-state-text-color: map.get($systems, md-sys-color, on-primary),
calendar-date-selected-state-background-color: map.get($systems, md-sys-color, primary),
calendar-date-selected-disabled-state-background-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface),
$alpha: 0.38
),
calendar-date-today-selected-state-outline-color: map.get($systems, md-sys-color, primary),
calendar-date-focus-state-background-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface),
$alpha: map.get($systems, md-sys-state, focus-state-layer-opacity)
),
calendar-date-hover-state-background-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface),
$alpha: map.get($systems, md-sys-state, hover-state-layer-opacity)
),
toggle-active-state-icon-color: map.get($systems, md-sys-color, on-surface-variant),
toggle-icon-color: map.get($systems, md-sys-color, on-surface-variant),
calendar-body-label-text-color: map.get($systems, md-sys-color, on-surface),
calendar-period-button-icon-color: map.get($systems, md-sys-color, on-surface-variant),
calendar-navigation-button-icon-color: map.get($systems, md-sys-color, on-surface-variant),
calendar-header-divider-color: map.get($systems, md-sys-color, outline-variant),
calendar-header-text-color: map.get($systems, md-sys-color, on-surface-variant),
calendar-date-today-outline-color: map.get($systems, md-sys-color, primary),
calendar-date-today-disabled-state-outline-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface),
$alpha: 0.38
),
calendar-date-text-color: map.get($systems, md-sys-color, on-surface),
calendar-date-outline-color: _hardcode(transparent, $exclude-hardcoded),
calendar-date-disabled-state-text-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface),
$alpha: 0.38
),
calendar-date-preview-state-outline-color: map.get($systems, md-sys-color, primary),
range-input-separator-color: map.get($systems, md-sys-color, on-surface),
range-input-disabled-state-separator-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface),
$alpha: 0.38
),
range-input-disabled-state-text-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface),
$alpha: 0.38
),
calendar-container-background-color: map.get($systems, md-sys-color, surface-container-high),
calendar-container-text-color: map.get($systems, md-sys-color, on-surface),
calendar-text-font: map.get($systems, md-sys-typescale, body-large-font),
calendar-text-size: map.get($systems, md-sys-typescale, body-large-size),
calendar-body-label-text-size: map.get($systems, md-sys-typescale, title-small-size),
calendar-body-label-text-weight: map.get($systems, md-sys-typescale, title-small-weight),
calendar-period-button-text-size: map.get($systems, md-sys-typescale, title-small-size),
calendar-period-button-text-weight: map.get($systems, md-sys-typescale, title-small-weight),
calendar-header-text-size: map.get($systems, md-sys-typescale, title-small-size),
calendar-header-text-weight: map.get($systems, md-sys-typescale, title-small-weight),
);
}

/// Generates custom tokens for the mat-divider.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
Expand Down
1 change: 1 addition & 0 deletions src/material-experimental/theming/_m3-density.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ $_density-tokens: (

// Custom Angular Material tokens
(mat, card): (),
(mat, datepicker): (),
(mat, divider): (),
(mat, expansion): (
header-collapsed-state-height: (48px, 44px, 40px, 36px),
Expand Down
5 changes: 5 additions & 0 deletions src/material-experimental/theming/_m3-tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@
custom-tokens.card($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, datepicker),
custom-tokens.datepicker($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, divider),
custom-tokens.divider($systems, $exclude-hardcoded),
Expand Down
2 changes: 2 additions & 0 deletions src/material/core/tokens/m2/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@use 'sass:meta';
@use '../../style/sass-utils';
@use './mat/card' as tokens-mat-card;
@use './mat/datepicker' as tokens-mat-datepicker;
@use './mat/divider' as tokens-mat-divider;
@use './mat/expansion' as tokens-mat-expansion;
@use './mat/fab' as tokens-mat-fab;
Expand Down Expand Up @@ -91,6 +92,7 @@
@function m2-tokens-from-theme($theme) {
@return sass-utils.deep-merge-all(
_get-tokens-for-module($theme, tokens-mat-card),
_get-tokens-for-module($theme, tokens-mat-datepicker),
_get-tokens-for-module($theme, tokens-mat-divider),
_get-tokens-for-module($theme, tokens-mat-expansion),
_get-tokens-for-module($theme, tokens-mat-fab),
Expand Down
108 changes: 70 additions & 38 deletions src/material/datepicker/_datepicker-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,58 @@ $calendar-weekday-table-font-size: 11px !default;
map.merge($calendar-tokens, $range-tokens));
}

@mixin base($theme) {}
@mixin base($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
}
@else {}
}

@mixin color($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
tokens-mat-datepicker.get-color-tokens($theme));
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
}

.mat-datepicker-content {
&.mat-accent {
@include _calendar-color($theme, accent);
@else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
tokens-mat-datepicker.get-color-tokens($theme));
}

&.mat-warn {
@include _calendar-color($theme, warn);
}
}
.mat-datepicker-content {
&.mat-accent {
@include _calendar-color($theme, accent);
}

.mat-datepicker-toggle-active {
&.mat-accent {
$accent-tokens:
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, accent);
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $accent-tokens);
&.mat-warn {
@include _calendar-color($theme, warn);
}
}

&.mat-warn {
$warn-tokens:
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, warn);
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $warn-tokens);
.mat-datepicker-toggle-active {
&.mat-accent {
$accent-tokens:
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, accent);
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $accent-tokens);
}

&.mat-warn {
$warn-tokens:
tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens($theme, warn);
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $warn-tokens);
}
}
}
}

@mixin typography($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
tokens-mat-datepicker.get-typography-tokens($theme));
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
}
@else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-datepicker.$prefix,
tokens-mat-datepicker.get-typography-tokens($theme));
}
}
}

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

@mixin density($theme) {
// TODO(crisbeto): move this into the structural styles
// once the icon button density is switched to tokens.
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
}
@else {
// TODO(crisbeto): move this into the structural styles
// once the icon button density is switched to tokens.

// Regardless of the user-passed density, we want the calendar
// previous/next buttons to remain at density -2
.mat-calendar-controls {
@include icon-button-theme.density(-2);
// Regardless of the user-passed density, we want the calendar
// previous/next buttons to remain at density -2
.mat-calendar-controls {
@include icon-button-theme.density(-2);
}
}
}

@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-datepicker') {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
}
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if inspection.theme-has($theme, typography) {
@include typography($theme);
@else {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if inspection.theme-has($theme, typography) {
@include typography($theme);
}
}
}
}

@mixin _theme-from-tokens($tokens) {
@if ($tokens != ()) {
@include token-utils.create-token-values(
tokens-mat-datepicker.$prefix, map.get($tokens, tokens-mat-datepicker.$prefix));
}
}
Loading