@@ -214,58 +214,44 @@ $_component-prefix: null;
214
214
@return if ($emit-overrides-only , $overrides , map .merge ($values , $overrides ));
215
215
}
216
216
217
- /// Emits new token values for the given tokens .
218
- /// Verifies that the tokens passed in are valid tokens.
217
+ /// Emits new token values for the given token overrides .
218
+ /// Verifies that the overrides passed in are valid tokens.
219
219
/// New token values are emitted under the current selector or root.
220
- @mixin batch-create-token-values (
221
- $tokens : (),
222
- $mat-prefix : ' ' ,
223
- $mdc-prefix : ' ' ,
224
- $mat-tokens : (),
225
- $mdc-tokens : ()
226
- ) {
227
- $custom-mat-tokens : ();
228
- $custom-mdc-tokens : ();
220
+ @mixin batch-create-token-values ($overrides : (), $token-maps ...) {
221
+ @include _validate-token-overrides ($overrides , $token-maps );
229
222
230
- $mat- token-names : map . keys ( $mat-tokens );
231
- $mdc-token-names : map .keys ( $mdc-tokens );
232
- $valid-token-names : _get-valid-token-names ( $mat-tokens , $mdc- tokens );
223
+ @each $ token-map in $token-maps {
224
+ $prefix : map .get ( $token-map , prefix );
225
+ $tokens : map . get ( $token-map , tokens );
233
226
234
- @each $name , $value in $tokens {
235
- $is-mat-token : list . index ( $mat-token-names , $name ) != null ;
236
- $is-mdc-token : list . index ( $mdc-token-names , $name ) != null;
227
+ @each $name , $value in $tokens {
228
+ $tokens : map . set ( $tokens , $name , map . get ( $overrides , $name )) ;
229
+ }
237
230
238
- @if ( $is-mat-token ) {
239
- $custom-mat-tokens : map . set ( $custom-mat-tokens , $name , $value );
231
+ @include sass-utils . current-selector-or-root ( ) {
232
+ @include create-token-values ( $prefix , $tokens );
240
233
}
234
+ }
235
+ }
236
+
237
+ /// Verifies that the token overrides exist and are used in one of the given token maps.
238
+ @mixin _validate-token-overrides ($overrides : (), $token-maps ) {
239
+ $valid-token-names : ();
241
240
242
- @if ($is-mdc-token ) {
243
- $custom-mdc-tokens : map .set ($custom-mdc-tokens , $name , $value );
241
+ @each $token-map in $token-maps {
242
+ @each $name , $value in map .get ($token-map , tokens ) {
243
+ @if ($value != null and list .index ($valid-token-names , $name ) == null) {
244
+ $valid-token-names : list .append ($valid-token-names , $name );
245
+ }
244
246
}
247
+ }
245
248
249
+ @each $name in map .keys ($overrides ) {
246
250
@if (list .index ($valid-token-names , $name ) == null) {
247
251
@error (
248
252
' Invalid token: "' + $name + ' "'
249
253
' Valid tokens include: ' $valid-token-names
250
254
);
251
255
}
252
256
}
253
-
254
- @include sass-utils .current-selector-or-root () {
255
- @include create-token-values ($mat-prefix , $custom-mat-tokens );
256
- @include create-token-values ($mdc-prefix , $custom-mdc-tokens );
257
- }
258
- }
259
-
260
- /// Returns the union of token names whose values are not null.
261
- @function _get-valid-token-names ($mat-tokens , $mdc-tokens ) {
262
- $mat-and-mdc-tokens : map .merge ($mat-tokens , $mdc-tokens );
263
-
264
- @each $name , $value in $mat-and-mdc-tokens {
265
- @if ($value == null) {
266
- $mat-and-mdc-tokens : map .remove ($mat-and-mdc-tokens , $name );
267
- }
268
- }
269
-
270
- @return map .keys ($mat-and-mdc-tokens );
271
257
}
0 commit comments