Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/material/checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
}
}

/// Outputs the CSS variable values for the given tokens.
/// @param {Map} $tokens The token values to emit.
@mixin overrides($tokens: ()) {
@include token-utils.batch-create-token-values(
$tokens,
$mat-prefix: tokens-mat-checkbox.$prefix,
$mdc-prefix: tokens-mdc-checkbox.$prefix,
$mat-tokens: tokens-mat-checkbox.get-token-slots(),
$mdc-tokens: tokens-mdc-checkbox.get-token-slots(),
);
}

/// Outputs all (base, color, typography, and density) theme styles for the mat-checkbox.
/// @param {Map} $theme The theme to generate styles for.
/// @param {ArgList} Additional optional arguments (only supported for M3 themes):
Expand Down
56 changes: 56 additions & 0 deletions src/material/core/tokens/_token-utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,59 @@ $_component-prefix: null;
}
@return map.merge($values, $overrides);
}

/// Emits new token values for the given tokens.
/// Verifies that the tokens passed in are valid tokens.
/// New token values are emitted under the current selector or root.
@mixin batch-create-token-values(
$tokens: (),
$mat-prefix: '',
$mdc-prefix: '',
$mat-tokens: (),
$mdc-tokens: ()
) {
$custom-mat-tokens: ();
$custom-mdc-tokens: ();

$mat-token-names: map.keys($mat-tokens);
$mdc-token-names: map.keys($mdc-tokens);
$valid-token-names: _get-valid-token-names($mat-tokens, $mdc-tokens);

@each $name, $value in $tokens {
$is-mat-token: list.index($mat-token-names, $name) != null;
$is-mdc-token: list.index($mdc-token-names, $name) != null;

@if ($is-mat-token) {
$custom-mat-tokens: map.set($custom-mat-tokens, $name, $value);
}

@if ($is-mdc-token) {
$custom-mdc-tokens: map.set($custom-mdc-tokens, $name, $value);
}

@if (list.index($valid-token-names, $name) == null) {
@error (
'Invalid token: "' + $name + '"'
'Valid tokens include: ' $valid-token-names
);
}
}

@include sass-utils.current-selector-or-root() {
@include create-token-values($mat-prefix, $custom-mat-tokens);
@include create-token-values($mdc-prefix, $custom-mdc-tokens);
}
}

/// Returns the union of token names whose values are not null.
@function _get-valid-token-names($mat-tokens, $mdc-tokens) {
$mat-and-mdc-tokens: map.merge($mat-tokens, $mdc-tokens);

@each $name, $value in $mat-and-mdc-tokens {
@if ($value == null) {
$mat-and-mdc-tokens: map.remove($mat-and-mdc-tokens, $name);
}
}

@return map.keys($mat-and-mdc-tokens);
}