Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(material/theming): extend-theme sass function #28972

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}