|
| 1 | +@use 'sass:map'; |
1 | 2 | @use '@material/theme/theme-color' as mdc-theme-color;
|
2 | 3 | @use '@material/theme/theme' as mdc-theme;
|
3 | 4 | @use '@material/tab-indicator' as mdc-tab-indicator;
|
| 5 | +@use '@material/tab-indicator/tab-indicator-theme' as mdc-tab-indicator-theme; |
4 | 6 | @use '@material/tab' as mdc-tab;
|
| 7 | +@use '@material/tab/tab-theme' as mdc-tab-theme; |
5 | 8 | @use '@material/tab-bar' as mdc-tab-bar;
|
6 | 9 | @use '../mdc-helpers/mdc-helpers';
|
7 | 10 | @use '../../material/core/typography/typography';
|
8 | 11 | @use '../../material/core/theming/theming';
|
9 | 12 |
|
10 | 13 | @mixin color($config-or-theme) {
|
11 | 14 | $config: theming.get-color-config($config-or-theme);
|
12 |
| - // Save original values of MDC global variables. We need to save these so we can restore the |
13 |
| - // variables to their original values and prevent unintended side effects from using this mixin. |
14 |
| - $orig-text-label-color-active: mdc-tab.$text-label-color-active; |
15 |
| - $orig-icon-color-active: mdc-tab.$icon-color-active; |
16 |
| - $orig-text-label-color-default: mdc-tab.$text-label-color-default; |
| 15 | + $primary: theming.get-color-from-palette(map.get($config, primary)); |
| 16 | + $accent: theming.get-color-from-palette(map.get($config, accent)); |
| 17 | + $warn: theming.get-color-from-palette(map.get($config, warn)); |
17 | 18 |
|
18 | 19 | @include mdc-helpers.mat-using-mdc-theme($config) {
|
19 |
| - // This value is the same as MDC's default, but MDC defines it once inside |
20 |
| - // a variables file which means that we can't override it with our own palette. |
21 |
| - mdc-tab.$text-label-color-default: |
22 |
| - rgba(mdc-theme-color.prop-value(on-surface), mdc-tab.$text-label-opacity); |
| 20 | + .mat-mdc-tab, .mat-mdc-tab-link { |
| 21 | + $surface: mdc-theme-color.$surface; |
| 22 | + $on-surface: rgba(mdc-theme-color.$on-surface, 0.6); |
| 23 | + |
| 24 | + // TODO(crisbeto): these styles should actually be set through the `theme` mixin while the |
| 25 | + // `theme-styles` are included in the `tab` mixin inside `_tabs-common.scss`. Currently |
| 26 | + // they are not, because `theme-styles` outputs the token values directly, rather than |
| 27 | + // generating CSS variables. |
| 28 | + @include mdc-tab-theme.theme-styles(map.merge(mdc-tab-theme.$light-theme, ( |
| 29 | + container-color: $surface, |
| 30 | + inactive-focus-state-layer-color: $on-surface, |
| 31 | + inactive-hover-state-layer-color: $on-surface, |
| 32 | + inactive-pressed-state-layer-color: $on-surface, |
| 33 | + with-icon-inactive-focus-icon-color: $on-surface, |
| 34 | + with-icon-inactive-hover-icon-color: $on-surface, |
| 35 | + with-icon-inactive-icon-color: $on-surface, |
| 36 | + with-icon-inactive-pressed-icon-color: $on-surface, |
| 37 | + with-label-text-inactive-focus-label-text-color: $on-surface, |
| 38 | + with-label-text-inactive-hover-label-text-color: $on-surface, |
| 39 | + with-label-text-inactive-label-text-color: $on-surface, |
| 40 | + with-label-text-inactive-pressed-label-text-color: $on-surface, |
| 41 | + |
| 42 | + // TODO(crisbeto): MDC's styles are set up so that the icon size is set through a |
| 43 | + // `font-size` at the root of the tab while the text size of the tab is set on |
| 44 | + // `.mdc-tab__text-label` which overrides the one from the root. The problem is that the |
| 45 | + // `$light-theme` is looking for a `subhead2` level which doesn't exist in MDC's code which |
| 46 | + // in turn causes no text label styles to be emitted and for the icon size to be applied to |
| 47 | + // the entire tab. Since we don't support icons inside the tab anyway, we can temporarily |
| 48 | + // work around it by preventing MDC from emitting icon styles. The correct label typography |
| 49 | + // will be applied by our theme instead. |
| 50 | + with-icon-icon-size: null |
| 51 | + ))); |
| 52 | + |
| 53 | + // MDC seems to include a background color on tabs which only stands out on dark themes. |
| 54 | + // Disable for now for backwards compatibility. These styles are inside the theme in order |
| 55 | + // to avoid CSS specificity issues. |
| 56 | + background-color: transparent; |
| 57 | + } |
23 | 58 |
|
24 |
| - @include _palette-styles(mdc-tab.$text-label-color-active); |
| 59 | + @include _palette-styles($primary); |
25 | 60 |
|
26 | 61 | .mat-mdc-tab-group, .mat-mdc-tab-nav-bar {
|
27 | 62 | &.mat-accent {
|
28 |
| - mdc-tab.$text-label-color-active: secondary; |
29 |
| - mdc-tab.$icon-color-active: secondary; |
30 |
| - @include _palette-styles(mdc-tab.$text-label-color-active); |
| 63 | + @include _palette-styles($accent); |
31 | 64 | }
|
32 | 65 |
|
33 | 66 | &.mat-warn {
|
34 |
| - mdc-tab.$text-label-color-active: error; |
35 |
| - mdc-tab.$icon-color-active: error; |
36 |
| - @include _palette-styles(mdc-tab.$text-label-color-active); |
| 67 | + @include _palette-styles($warn); |
37 | 68 | }
|
38 | 69 | }
|
39 | 70 |
|
|
55 | 86 | @include mdc-theme.prop(border-color, on-surface);
|
56 | 87 | }
|
57 | 88 | }
|
58 |
| - |
59 |
| - // Restore original values of MDC global variables. |
60 |
| - mdc-tab.$text-label-color-active: $orig-text-label-color-active; |
61 |
| - mdc-tab.$icon-color-active: $orig-icon-color-active; |
62 |
| - mdc-tab.$text-label-color-default: $orig-text-label-color-default; |
63 | 89 | }
|
64 | 90 |
|
65 | 91 | @mixin _background($background-color, $foreground-color) {
|
|
73 | 99 |
|
74 | 100 | > .mat-mdc-tab-header, > .mat-mdc-tab-link-container {
|
75 | 101 | // Set labels to contrast against background
|
76 |
| - .mdc-tab__text-label, .mat-mdc-tab-link { |
| 102 | + .mat-mdc-tab .mdc-tab__text-label, .mat-mdc-tab-link .mdc-tab__text-label { |
77 | 103 | @include mdc-theme.prop(color, $foreground-color);
|
78 | 104 | }
|
79 | 105 |
|
|
96 | 122 | }
|
97 | 123 |
|
98 | 124 | @mixin _palette-styles($color) {
|
99 |
| - @include mdc-tab.without-ripple($query: mdc-helpers.$mat-theme-styles-query); |
100 |
| - @include mdc-tab-indicator.underline-color($color, $query: mdc-helpers.$mat-theme-styles-query); |
101 |
| - @include mdc-tab-indicator.icon-color($color, $query: mdc-helpers.$mat-theme-styles-query); |
| 125 | + .mat-mdc-tab, .mat-mdc-tab-link { |
| 126 | + // TODO(crisbeto): these styles should actually be set through the `theme` mixin while the |
| 127 | + // `theme-styles` are included in the `tab` mixin inside `_tabs-common.scss`. Currently |
| 128 | + // they are not, because `theme-styles` outputs the token values directly, rather than |
| 129 | + // generating CSS variables. |
| 130 | + @include mdc-tab-theme.theme-styles(( |
| 131 | + active-focus-state-layer-color: $color, |
| 132 | + active-hover-state-layer-color: $color, |
| 133 | + active-pressed-state-layer-color: $color, |
| 134 | + with-icon-active-focus-icon-color: $color, |
| 135 | + with-icon-active-hover-icon-color: $color, |
| 136 | + with-icon-active-icon-color: $color, |
| 137 | + with-icon-active-pressed-icon-color: $color, |
| 138 | + with-label-text-active-focus-label-text-color: $color, |
| 139 | + with-label-text-active-hover-label-text-color: $color, |
| 140 | + with-label-text-active-label-text-color: $color, |
| 141 | + with-label-text-active-pressed-label-text-color: $color, |
| 142 | + )); |
| 143 | + |
| 144 | + @include mdc-tab-indicator-theme.theme-styles(( |
| 145 | + active-indicator-color: $color |
| 146 | + )); |
| 147 | + } |
102 | 148 |
|
103 | 149 | .mdc-tab__ripple::before,
|
104 | 150 | .mat-mdc-tab .mat-ripple-element,
|
|
0 commit comments