Skip to content

Commit

Permalink
feat(material/theming): Disambiguate token names in theme overrides
Browse files Browse the repository at this point in the history
Prior to this change a single key in the theme overrides map sometimes
resulted in mutliple tokens being overridden. This change gives every
token a unique name, by prefixing when necessary. The old ambiguous keys
are still allowed for compatibility, but will now log a warning when
they're used.
  • Loading branch information
mmalerba committed Oct 10, 2024
1 parent 48b2680 commit 60f5400
Show file tree
Hide file tree
Showing 44 changed files with 1,960 additions and 1,048 deletions.
51 changes: 30 additions & 21 deletions src/material/autocomplete/_autocomplete-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,70 @@
@mixin base($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-unthemable-tokens());
@include token-utils.create-token-values(
tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-unthemable-tokens()
);
}
}
}

@mixin color($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-color-tokens($theme));
@include token-utils.create-token-values(
tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-color-tokens($theme)
);
}
}
}

@mixin typography($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-typography-tokens($theme));
@include token-utils.create-token-values(
tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-typography-tokens($theme)
);
}
}
}

@mixin density($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-density-tokens($theme));
@include token-utils.create-token-values(
tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-density-tokens($theme)
);
}
}
}

@mixin overrides($tokens: ()) {
@include token-utils.batch-create-token-values(
$tokens,
(prefix: tokens-mat-autocomplete.$prefix, tokens: tokens-mat-autocomplete.get-token-slots()),
(
namespace: tokens-mat-autocomplete.$prefix,
tokens: tokens-mat-autocomplete.get-token-slots(),
)
);
}

@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-autocomplete') {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
}
@else {
} @else {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
Expand All @@ -84,9 +90,12 @@

@mixin _theme-from-tokens($tokens) {
@include validation.selector-defined(
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
);
@if ($tokens != ()) {
@include token-utils.create-token-values(
tokens-mat-autocomplete.$prefix, map.get($tokens, tokens-mat-autocomplete.$prefix));
tokens-mat-autocomplete.$prefix,
map.get($tokens, tokens-mat-autocomplete.$prefix)
);
}
}
52 changes: 31 additions & 21 deletions src/material/badge/_badge-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
@mixin base($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.get-unthemable-tokens());
@include token-utils.create-token-values(
tokens-mat-badge.$prefix,
tokens-mat-badge.get-unthemable-tokens()
);
}
}
}
Expand All @@ -30,21 +31,26 @@
@mixin color($theme, $options...) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.get-color-tokens($theme));
@include token-utils.create-token-values(
tokens-mat-badge.$prefix,
tokens-mat-badge.get-color-tokens($theme)
);
}

.mat-badge-accent {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.private-get-color-palette-color-tokens($theme, accent));
@include token-utils.create-token-values(
tokens-mat-badge.$prefix,
tokens-mat-badge.private-get-color-palette-color-tokens($theme, accent)
);
}

.mat-badge-warn {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.private-get-color-palette-color-tokens($theme, warn));
@include token-utils.create-token-values(
tokens-mat-badge.$prefix,
tokens-mat-badge.private-get-color-palette-color-tokens($theme, warn)
);
}
}
}
Expand All @@ -54,11 +60,12 @@
@mixin typography($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.get-typography-tokens($theme));
@include token-utils.create-token-values(
tokens-mat-badge.$prefix,
tokens-mat-badge.get-typography-tokens($theme)
);
}
}
}
Expand All @@ -68,16 +75,19 @@
@mixin density($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
} @else {
}
@else {}
}

/// 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,
(prefix: tokens-mat-badge.$prefix, tokens: tokens-mat-badge.get-token-slots()),
(
namespace: tokens-mat-badge.$prefix,
tokens: tokens-mat-badge.get-token-slots(),
)
);
}

Expand All @@ -90,8 +100,7 @@
@include theming.private-check-duplicate-theme-styles($theme, 'mat-badge') {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
}
@else {
} @else {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
Expand All @@ -108,7 +117,8 @@

@mixin _theme-from-tokens($tokens, $options...) {
@include validation.selector-defined(
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
);
$mat-badge-tokens: token-utils.get-tokens-for($tokens, tokens-mat-badge.$prefix, $options...);
@include token-utils.create-token-values(tokens-mat-badge.$prefix, $mat-badge-tokens);
}
42 changes: 25 additions & 17 deletions src/material/bottom-sheet/_bottom-sheet-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,64 @@
@mixin base($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(
tokens-mat-bottom-sheet.$prefix, tokens-mat-bottom-sheet.get-unthemable-tokens());
tokens-mat-bottom-sheet.$prefix,
tokens-mat-bottom-sheet.get-unthemable-tokens()
);
}
}
}

@mixin color($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-bottom-sheet.$prefix,
tokens-mat-bottom-sheet.get-color-tokens($theme));
@include token-utils.create-token-values(
tokens-mat-bottom-sheet.$prefix,
tokens-mat-bottom-sheet.get-color-tokens($theme)
);
}
}
}

@mixin typography($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
}
@else {
} @else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-bottom-sheet.$prefix,
tokens-mat-bottom-sheet.get-typography-tokens($theme));
@include token-utils.create-token-values(
tokens-mat-bottom-sheet.$prefix,
tokens-mat-bottom-sheet.get-typography-tokens($theme)
);
}
}
}

@mixin density($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
} @else {
}
@else {}
}

@mixin overrides($tokens: ()) {
@include token-utils.batch-create-token-values(
$tokens,
(prefix: tokens-mat-bottom-sheet.$prefix, tokens: tokens-mat-bottom-sheet.get-token-slots()),
(
namespace: tokens-mat-bottom-sheet.$prefix,
tokens: tokens-mat-bottom-sheet.get-token-slots(),
)
);
}

@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-bottom-sheet') {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
}
@else {
} @else {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
Expand All @@ -79,9 +84,12 @@

@mixin _theme-from-tokens($tokens) {
@include validation.selector-defined(
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
);
@if ($tokens != ()) {
@include token-utils.create-token-values(
tokens-mat-bottom-sheet.$prefix, map.get($tokens, tokens-mat-bottom-sheet.$prefix));
tokens-mat-bottom-sheet.$prefix,
map.get($tokens, tokens-mat-bottom-sheet.$prefix)
);
}
}
Loading

0 comments on commit 60f5400

Please sign in to comment.