Skip to content

Commit 49e0738

Browse files
committed
feat(material/core): default to color-scheme theme type
1 parent 5ad133d commit 49e0738

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

src/dev-app/theme-m3.scss

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ $dark-theme: create-theme($type: dark);
3737

3838
// Include the default theme styles.
3939
html {
40+
color-scheme: light;
4041
body:not(.demo-experimental-theme) {
4142
@include mat.all-component-themes($light-theme);
4243
@include mat.system-level-colors($light-theme);
@@ -49,7 +50,6 @@ html {
4950
body.demo-experimental-theme {
5051
@include mat.theme((
5152
color: (
52-
theme-type: light,
5353
primary: $primary,
5454
tertiary: $tertiary,
5555
),
@@ -73,6 +73,7 @@ html {
7373
// `.demo-unicorn-dark-theme` will be affected by this alternate dark theme instead of the
7474
// default theme.
7575
body.demo-unicorn-dark-theme {
76+
color-scheme: dark;
7677
&:not(.demo-experimental-theme) {
7778
// Include the dark theme color styles.
7879
@include mat.all-component-colors($dark-theme);
@@ -82,16 +83,6 @@ body.demo-unicorn-dark-theme {
8283
// @include matx.popover-edit-color($dark-theme);
8384
}
8485

85-
&.demo-experimental-theme {
86-
@include mat.theme((
87-
color: (
88-
theme-type: dark,
89-
primary: $primary,
90-
tertiary: $tertiary,
91-
),
92-
));
93-
}
94-
9586
// Include the dark theme colors for focus indicators.
9687
&.demo-strong-focus {
9788
@include mat.strong-focus-indicators-color($dark-theme);

src/material/core/theming/_config-validation.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@
100100
);
101101
}
102102
@if $config and map.has-key($config, theme-type) and
103-
not list.index((light, dark), map.get($config, theme-type)) {
103+
not list.index((light, dark, color-scheme), map.get($config, theme-type)) {
104104
@return (
105-
#{'Expected $config.theme-type to be one of: light, dark. Got:'}
105+
#{'Expected $config.theme-type to be one of: light, dark, color-scheme. Got:'}
106106
map.get($config, theme-type)
107107
);
108108
}

src/material/core/tokens/_m3-system.scss

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ $_system-level-prefix: sys;
1818
/// config map. The config map can have values color, typography, and/or density.
1919
///
2020
/// If the config map's color value is an Angular Material color palette, it will be used as the
21-
/// primary and tertiary colors with a light theme type. Otherwise if the color value is a map,
22-
/// it must have a `primary` value containing an Angular Material color palette, and optionally
23-
/// a different `tertiary` palette (defaults to primary palette) and `theme-type` that is either
24-
/// `light` or `dark` (defaults to light). Color variable definitions will not be emitted if there
25-
/// are no color values in the config.
21+
/// primary and tertiary colors with a `color-scheme` theme type. Otherwise if the color value is a
22+
/// map, it must have a `primary` value containing an Angular Material color palette, and
23+
/// optionally a different `tertiary` palette (defaults to primary palette) and `theme-type` that
24+
/// is either `light`, `dark`, or 'color-scheme` (defaults to `color-scheme`). Color variable
25+
/// definitions will not be emitted if there are no color values in the config.
2626
///
2727
/// If the config map's typography value is a font family string, it will be used as the
2828
/// plain and brand font family with default bold, medium, and regular weights of 700, 500, and 400,
@@ -44,9 +44,14 @@ $_system-level-prefix: sys;
4444
$color: map.get($config, color);
4545
$color-config: null;
4646
@if ($color) {
47+
// Default to "color-scheme" theme type if the config's color does not provide one.
48+
@if (meta.type-of($color) == 'map' and not map.has-key($color, theme-type)) {
49+
$color: map.set($color, theme-type, color-scheme);
50+
}
51+
4752
$color-config: if(meta.type-of($color) == 'map',
4853
definition.define-colors($color),
49-
definition.define-colors((primary: $color)));
54+
definition.define-colors((primary: $color, theme-type: color-scheme)));
5055
@include system-level-colors($color-config, $overrides, $_system-fallback-prefix);
5156
@include system-level-elevation($color-config, $overrides, $_system-fallback-prefix);
5257
}
@@ -126,9 +131,7 @@ $_system-level-prefix: sys;
126131
md-ref-palette: m3-tokens.generate-ref-palette-tokens($primary, $tertiary, $error)
127132
);
128133

129-
$sys-colors: if($type == dark,
130-
definitions.md-sys-color-values-dark($ref),
131-
definitions.md-sys-color-values-light($ref));
134+
$sys-colors: _generate-sys-colors($ref, $type);
132135

133136
// Manually insert a subset of palette values that are used directly by components
134137
// instead of system variables.
@@ -144,6 +147,30 @@ $_system-level-prefix: sys;
144147
}
145148
}
146149

150+
@function _generate-sys-colors($ref, $type) {
151+
$light-sys-colors: definitions.md-sys-color-values-light($ref);
152+
@if ($type == light) {
153+
@return $light-sys-colors;
154+
}
155+
156+
$dark-sys-colors: definitions.md-sys-color-values-dark($ref);
157+
@if ($type == dark) {
158+
@return $dark-sys-colors;
159+
}
160+
161+
@if ($type == color-scheme) {
162+
$light-dark-sys-colors: ();
163+
@each $name, $light-value in $light-sys-colors {
164+
$dark-value: map.get($dark-sys-colors, $name);
165+
$light-dark-sys-colors:
166+
map.set($light-dark-sys-colors, $name, light-dark($light-value, $dark-value));
167+
}
168+
@return $light-dark-sys-colors;
169+
}
170+
171+
@error 'Unknown theme-type provided: #{$type}';
172+
}
173+
147174
@mixin system-level-typography($theme, $overrides: (), $prefix: null) {
148175
$font-definition: map.get($theme, _mat-theming-internals-do-not-access, font-definition);
149176
$brand: map.get($font-definition, brand);

0 commit comments

Comments
 (0)