@@ -62,10 +62,17 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
62
62
}
63
63
}
64
64
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
69
76
/// @param {Map} $theme The theme
70
77
/// @param {String} $color-role-or-palette-name The name of the color role to get, or the name of a
71
78
/// color palette.
@@ -74,25 +81,29 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
74
81
/// @return {Color} The requested theme color.
75
82
@function get-theme-color ($theme , $args ... ) {
76
83
$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 ;
81
85
86
+ // M2 theme
82
87
@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
+ }
83
92
@return m2-inspection .get-theme-color ($theme , $args ... );
84
93
}
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 } ' ;
91
99
}
100
+ @return if ($args-count == 2 ,
101
+ _get-theme-role-color ($theme , $args ... ),
102
+ _get-theme-palette-color ($theme , $args ... )
103
+ );
92
104
}
93
- @else {
94
- @error #{' Unrecognized theme version:' } $version ;
95
- }
105
+
106
+ @error ' Unrecognized theme version: #{$version } ' ;
96
107
}
97
108
98
109
/// Gets a role color from a theme object.
0 commit comments