diff --git a/src/material/checkbox/_checkbox-theme.scss b/src/material/checkbox/_checkbox-theme.scss index e522f33f4195..fcd29930db88 100644 --- a/src/material/checkbox/_checkbox-theme.scss +++ b/src/material/checkbox/_checkbox-theme.scss @@ -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): diff --git a/src/material/core/tokens/_token-utils.scss b/src/material/core/tokens/_token-utils.scss index 7dd35dd31856..e40dc81ba80f 100644 --- a/src/material/core/tokens/_token-utils.scss +++ b/src/material/core/tokens/_token-utils.scss @@ -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; +}