@@ -62,10 +62,17 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
6262  }
6363}
6464
65- ///  Gets a color from a theme object. This function can take 2 or 3 arguments. If 2 arguments are
66- ///  passed, the second argument is treated as the name of a color role. If 3 arguments are passed,
67- ///  the second argument is treated as the name of a color palette (primary, secondary, etc.) and the
68- ///  third is treated as the palette hue (10, 50, etc.)
65+ ///  Gets a color from a theme object. This function take a different amount of arguments depending
66+ ///  on if it's working with an M2 or M3 theme:
67+ ///  - With an M3 theme it accepts either 2 or 3 arguments. If 2 arguments are passed, the second
68+ ///  argument is treated as the name of a color role. If 3 arguments are passed, the second argument
69+ ///  is treated as the name of a color palette (primary, secondary, etc.) and the third is treated
70+ ///  as the palette hue (10, 50, etc.).
71+ ///  - With an M2 theme theme it accepts between 2 and 4 arguments, or the equivalent of calling
72+ ///  the `m2-get-theme-color` function. The first argument is the theme, the second one is the
73+ ///  palette from which to extract the color, the third one is the hue within the palette and the
74+ ///  fourth is the opacity of the returned color.
75+ ///  the second one is the
6976///  @param  {Map}  $theme  The theme
7077///  @param  {String}  $color-role-or-palette-name  The name of the color role to get, or the name of a
7178///    color palette.
@@ -74,25 +81,29 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
7481///  @return  {Color}  The requested theme color.
7582@function  get-theme-color ($theme , $args ... ) {
7683  $version : get-theme-version ($theme );
77-   $args-count : list .length ($args );
78-   @if  $args-count  !=  1  and  $args-count  !=  2  and  $args-count  !=  3  {
79-     @error  #{' Expected between 2 and 4 arguments. Got:'   $args-count  + 1;
80-   }
84+   $args-count : list .length ($args ) +  1 ;
8185
86+   //  M2 theme
8287  @if  $version  ==  0  {
88+     @if  $args-count  <  2  or  $args-count  >  4  {
89+       @error  ' Expected between 2 and 4 arguments when working with an M2 theme. ' 
90+              ' Got: #{$args-count } ' 
91+     }
8392    @return  m2-inspection .get-theme-color ($theme , $args ... );
8493  }
85-   @else if  $version  ==  1  {
86-     @if  $args-count  ==  1  {
87-       @return  _get-theme-role-color ($theme , $args ... );
88-     }
89-     @else if  $args-count  ==  2  {
90-       @return  _get-theme-palette-color ($theme , $args ... );
94+ 
95+   //  M3 theme
96+   @if  $version  ==  1  {
97+     @if  $args-count  <  2  or  $args-count  >  3  {
98+       @error  ' Expected either 2 or 3 arguments when working with an M3 theme. Got: #{$args-count } ' 
9199    }
100+     @return  if ($args-count  ==  2 ,
101+       _get-theme-role-color ($theme , $args ... ),
102+       _get-theme-palette-color ($theme , $args ... )
103+     );
92104  }
93-   @else  {
94-     @error  #{' Unrecognized theme version:'   $version ;
95-   }
105+ 
106+   @error  ' Unrecognized theme version: #{$version } ' 
96107}
97108
98109///  Gets a role color from a theme object.
0 commit comments