Skip to content

Commit cb9cbb9

Browse files
committed
refactor: exclude some tabs tokens
1 parent 15923a8 commit cb9cbb9

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/components-examples/material/tabs/tab-group-align/tab-group-align-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- #docregion align-start -->
2-
<mat-tab-group mat-stretch-tabs="false" mat-align-tabs="start">
2+
<mat-tab-group mat-stretch-tabs="false" color="accent" mat-align-tabs="start" backgroundColor="accent">
33
<!-- #enddocregion align-start -->
44
<mat-tab label="First">Content 1</mat-tab>
55
<mat-tab label="Second">Content 2</mat-tab>

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: 33 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,43 @@
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, $exclude: (background-color, foreground-color)));
3637

37-
&.mat-accent, &.mat-background-accent {
38+
&.mat-accent {
3839
@include token-utils.create-token-values-mixed(
39-
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, accent));
40+
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, accent, $exclude: (background-color, foreground-color)));
4041
}
4142

42-
&.mat-warn, &.mat-background-warn {
43+
&.mat-warn {
4344
@include token-utils.create-token-values-mixed(
44-
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, warn));
45+
m2-tabs.$prefix, m2-tabs.get-color-tokens($theme, warn, $exclude: (background-color, foreground-color)));
46+
}
47+
48+
&.mat-background-primary {
49+
$tokens: m2-tabs.get-color-tokens($theme, primary);
50+
@include token-utils.create-token-values-mixed(
51+
m2-tabs.$prefix, (
52+
background-color: map.get($tokens, background-color),
53+
foreground-color: map.get($tokens, foreground-color),
54+
));
55+
}
56+
57+
&.mat-background-accent {
58+
$tokens: m2-tabs.get-color-tokens($theme, accent);
59+
@include token-utils.create-token-values-mixed(
60+
m2-tabs.$prefix, (
61+
background-color: map.get($tokens, background-color),
62+
foreground-color: map.get($tokens, foreground-color),
63+
));
64+
}
65+
66+
&.mat-background-warn {
67+
$tokens: m2-tabs.get-color-tokens($theme, warn);
68+
@include token-utils.create-token-values-mixed(
69+
m2-tabs.$prefix, (
70+
background-color: map.get($tokens, background-color),
71+
foreground-color: map.get($tokens, foreground-color),
72+
));
4573
}
4674
}
4775
}

0 commit comments

Comments
 (0)