components icon indicating copy to clipboard operation
components copied to clipboard

m2-define-palette function default arguments bug

Open mindarchitect opened this issue 1 year ago • 2 comments
trafficstars

Is this a regression?

  • [X] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

17

Description

Calling m2-define-palette ->_get-color-from-palette($base-palette, $default) results in calling _get-color-from-palette with default hues (500, 100, 700) that do not exist anymore.

@function _get-color-from-palette($palette, $hue) { @if map.has-key($palette, $hue) { @return map.get($palette, $hue); }

@error 'Hue "' + $hue + '" does not exist in palette. Available hues are: ' + map.keys($palette); }

@function define-palette($base-palette, $default: 500, $lighter: 100, $darker: 700, $text: $default) { $result: map.merge($base-palette, ( default: _get-color-from-palette($base-palette, $default), lighter: _get-color-from-palette($base-palette, $lighter), darker: _get-color-from-palette($base-palette, $darker), text: _get-color-from-palette($base-palette, $text), default-contrast: get-contrast-color-from-palette($base-palette, $default), lighter-contrast: get-contrast-color-from-palette($base-palette, $lighter), darker-contrast: get-contrast-color-from-palette($base-palette, $darker) ));

// For each hue in the palette, add a "-contrast" color to the map. @each $hue, $color in $base-palette { $result: map.merge($result, ( '#{$hue}-contrast': get-contrast-color-from-palette($base-palette, $hue) )); }

@return $result; }

Reproduction

StackBlitz link: Steps to reproduce:

  1. Call m2-define-palette with default values

Expected Behavior

Palette defined

Actual Behavior

Compilation error

'Hue "500" does not exist in palette. Available hues are: 0, 10, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 95, 98, 99, 100, secondary, neutral, neutral-variant, error' ╷ 38 │ default: _get-color-from-palette($base-palette, $default), │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ╵ node_modules/@angular/material/core/m2/_theming.scss 38:14 define-palette() src/styles/theme.scss 7:18 @import src/styles.scss 29:9 root stylesheet

Environment

  • Angular: 18
  • CDK/Material: 18
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Ubuntu

mindarchitect avatar May 25 '24 11:05 mindarchitect

Please, fix it ASAP, the project can not be built now!

mindarchitect avatar May 25 '24 11:05 mindarchitect

Which palette are you calling the function with? It seems like it's taking an M3 palette, but m2-define-palette is specific to M2.

crisbeto avatar May 25 '24 13:05 crisbeto

Which palette are you calling the function with? It seems like it's taking an M3 palette, but m2-define-palette is specific to M2.

Thanks a lot. I guess it is my bad. I should have figured out m2 namespace for pallets as well. Fixed. I guess it can be closed.

mindarchitect avatar May 25 '24 16:05 mindarchitect

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.