Skip to content

Commit

Permalink
fix(material/core): correctly identify color input (#29909)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewseguin authored Oct 23, 2024
1 parent 0064b42 commit a8e40ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/material/core/theming/_config-validation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// Validates that the given object is an M3 palette.
/// @param {*} $palette The object to test
/// @return {Boolean|null} null if it is a valid M3 palette, else true.
@function _validate-palette($palette) {
@function validate-palette($palette) {
@if not meta.type-of($palette) == 'map' {
@return true;
}
Expand Down Expand Up @@ -108,7 +108,7 @@
}
@each $palette in (primary, secondary, tertiary) {
@if $config and map.has-key($config, $palette) {
$err: _validate-palette(map.get($config, $palette));
$err: validate-palette(map.get($config, $palette));
@if $err {
@return (
#{'Expected $config.#{$palette} to be a valid M3 palette. Got:'}
Expand Down
12 changes: 8 additions & 4 deletions src/material/core/tokens/_m3-system.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use '../style/elevation';
@use '../style/sass-utils';
@use '../theming/config-validation';
@use '../theming/definition';
@use './m3/definitions';
@use 'sass:map';
Expand Down Expand Up @@ -44,14 +45,17 @@ $_system-level-prefix: sys;
$color: map.get($config, color);
$color-config: null;
@if ($color) {
// validate-palette returns null if it is a valid M3 palette
$is-palette: config-validation.validate-palette($color) == null;

// Default to "color-scheme" theme type if the config's color does not provide one.
@if (meta.type-of($color) == 'map' and not map.has-key($color, theme-type)) {
@if (not $is-palette and not map.has-key($color, theme-type)) {
$color: map.set($color, theme-type, color-scheme);
}

$color-config: if(meta.type-of($color) == 'map',
definition.define-colors($color),
definition.define-colors((primary: $color, theme-type: color-scheme)));
$color-config: if($is-palette,
definition.define-colors((primary: $color, theme-type: color-scheme)),
definition.define-colors($color));
@include system-level-colors($color-config, $overrides, $_system-fallback-prefix);
@include system-level-elevation($color-config, $overrides, $_system-fallback-prefix);
}
Expand Down

0 comments on commit a8e40ec

Please sign in to comment.