Skip to content

Commit 0ad7d4f

Browse files
committed
refactor: fix tabs tokens
1 parent 15923a8 commit 0ad7d4f

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

src/material/tabs/_m2-tabs.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ $prefix: (mat, tab);
2929
}
3030

3131
// Tokens that can be configured through Angular Material's color theming API.
32-
@function get-color-tokens($theme, $palette-name: primary) {
32+
@function get-color-tokens($theme, $palette-name: primary, $exclude: ()) {
3333
$is-dark: inspection.get-theme-type($theme) == dark;
3434
$inactive-label-text-color: inspection.get-theme-color($theme, foreground, text, 0.6);
3535
$active-label-text-color: inspection.get-theme-color($theme, $palette-name, default);
3636
$ripple-color: inspection.get-theme-color($theme, $palette-name, default);
3737

38-
@return (
38+
$tokens: (
3939
disabled-ripple-color: inspection.get-theme-color($theme, foreground, disabled),
4040
pagination-icon-color: inspection.get-theme-color($theme, foreground, icon, 1),
4141

@@ -56,6 +56,12 @@ $prefix: (mat, tab);
5656
background-color: inspection.get-theme-color($theme, $palette-name, default),
5757
foreground-color: inspection.get-theme-color($theme, $palette-name, default-contrast),
5858
);
59+
60+
@each $token in $exclude {
61+
$tokens: map.remove($tokens, $token);
62+
}
63+
64+
@return $tokens;
5965
}
6066

6167
// Tokens that can be configured through Angular Material's typography theming API.

src/material/tabs/_tabs-theme.scss

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@use '../core/theming/validation';
66
@use '../core/typography/typography';
77
@use '../core/tokens/token-utils';
8+
@use 'sass:map';
89

910
/// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
1011
/// for the mat-tab.
@@ -32,16 +33,46 @@
3233
.mat-mdc-tab-group,
3334
.mat-mdc-tab-nav-bar {
3435
@include token-utils.create-token-values-mixed(
35-
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, primary));
36+
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, primary,
37+
$exclude: (background-color, foreground-color)));
3638

37-
&.mat-accent, &.mat-background-accent {
39+
&.mat-accent {
3840
@include token-utils.create-token-values-mixed(
39-
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, accent));
41+
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, accent,
42+
$exclude: (background-color, foreground-color)));
4043
}
4144

42-
&.mat-warn, &.mat-background-warn {
45+
&.mat-warn {
4346
@include token-utils.create-token-values-mixed(
44-
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, warn));
47+
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, warn,
48+
$exclude: (background-color, foreground-color)));
49+
}
50+
51+
&.mat-background-primary {
52+
$tokens: m2-tabs.get-color-tokens($theme, primary);
53+
@include token-utils.create-token-values-mixed(
54+
m2-tabs.$prefix, (
55+
background-color: map.get($tokens, background-color),
56+
foreground-color: map.get($tokens, foreground-color),
57+
));
58+
}
59+
60+
&.mat-background-accent {
61+
$tokens: m2-tabs.get-color-tokens($theme, accent);
62+
@include token-utils.create-token-values-mixed(
63+
m2-tabs.$prefix, (
64+
background-color: map.get($tokens, background-color),
65+
foreground-color: map.get($tokens, foreground-color),
66+
));
67+
}
68+
69+
&.mat-background-warn {
70+
$tokens: m2-tabs.get-color-tokens($theme, warn);
71+
@include token-utils.create-token-values-mixed(
72+
m2-tabs.$prefix, (
73+
background-color: map.get($tokens, background-color),
74+
foreground-color: map.get($tokens, foreground-color),
75+
));
4576
}
4677
}
4778
}
@@ -118,5 +149,8 @@
118149
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
119150
);
120151
$tabs-tokens: token-utils.get-tokens-for($tokens, m2-tabs.$prefix, $options...);
152+
$tabs-tokens-without-options: token-utils.get-tokens-for($tokens, m2-tabs.$prefix);
153+
154+
@include token-utils.create-token-values(m2-tabs.$prefix, $tabs-tokens-without-options);
121155
@include token-utils.create-token-values(m2-tabs.$prefix, $tabs-tokens);
122156
}

0 commit comments

Comments
 (0)