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