Skip to content

Commit

Permalink
feat(material/theming): extend-theme sass function
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnermaciel committed Apr 26, 2024
1 parent d0a2d3a commit 853278c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/material/checkbox/_checkbox-theme.scss
Expand Up @@ -102,6 +102,13 @@
);
}

/// Returns a theme config with the given tokens overridden.
/// @param {Map} $theme The material theme for an application.
/// @param {Map} $overrides The token values to override in the theme.
@function extend-theme($theme, $overrides: ()) {
@return token-utils.extend-theme($theme, checkbox, $overrides);
}

/// 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
30 changes: 30 additions & 0 deletions src/material/core/tokens/_token-utils.scss
Expand Up @@ -255,3 +255,33 @@ $_component-prefix: null;
}
}
}

/// Returns a theme config with the given tokens overridden.
/// @param {Map} $theme The material theme for an application.
/// @param {Map} $overrides The token values to override in the theme.
@function extend-theme($theme, $component, $overrides: ()) {
$internals: _mat-theming-internals-do-not-access;

@each $system in (color, typography, density, base) {

$system-name: $system + '-tokens';
$namespaces: map.get($theme, $internals, $system-name);
@each $namespace, $tokens in $namespaces {

@if (list.nth($namespace, 2) == $component) {
$namespace-overrides: if(list.length($namespace) == 3,
map.get($overrides, list.nth($namespace, 3)),
$overrides);

@each $name, $value in $tokens {
$token: map.get($namespace-overrides, $name);
@if $token != null {
$theme: map.set($theme, $internals, $system-name, $namespace, $name, $token);
}
}
}
}
}

@return $theme;
}

0 comments on commit 853278c

Please sign in to comment.