|
9 | 9 | @use '../../material/core/typography/typography';
|
10 | 10 | @use '../../material/core/theming/theming';
|
11 | 11 |
|
12 |
| -@mixin _base-chip($is-dark) { |
13 |
| - $on-surface-state-content: if($is-dark, mdc-color-palette.$grey-50, mdc-color-palette.$grey-900); |
14 |
| - $surface: |
15 |
| - color.mix(mdc-theme-color.prop-value(on-surface), mdc-theme-color.prop-value(surface), 12%); |
16 |
| - |
17 |
| - // TODO(crisbeto): ideally the $label-text-color would be something along the lines of: |
18 |
| - // `if($is-dark, mdc-color-palette.$grey-100, mdc-color-palette.$grey-800)`, because it allows |
19 |
| - // the user to distinguish between when the primary action is focused versus the remove icon. |
20 |
| - // The problem is that the color contrast is worse and there are a lot of Google screenshot tests |
21 |
| - // that expect the darker color. |
22 |
| - $label-text-color: $on-surface-state-content; |
23 |
| - |
24 |
| - @include mdc-chip-theme.theme-styles(( |
25 |
| - flat-focus-outline-color: $on-surface-state-content, |
26 |
| - flat-unselected-focus-outline-color: $on-surface-state-content, |
27 |
| - focus-label-text-color: $on-surface-state-content, |
28 |
| - focus-outline-color: $on-surface-state-content, |
29 |
| - hover-label-text-color: $on-surface-state-content, |
30 |
| - pressed-label-text-color: $on-surface-state-content, |
31 |
| - unselected-focus-label-text-color: $on-surface-state-content, |
32 |
| - unselected-hover-label-text-color: $on-surface-state-content, |
33 |
| - unselected-pressed-label-text-color: $on-surface-state-content, |
34 |
| - with-trailing-icon-trailing-icon-color: $on-surface-state-content, |
35 |
| - with-leading-icon-leading-icon-color: $on-surface-state-content, |
36 |
| - |
37 |
| - elevated-disabled-container-color: $surface, |
38 |
| - elevated-container-color: $surface, |
39 |
| - elevated-unselected-container-color: $surface, |
40 |
| - |
41 |
| - with-icon-unselected-icon-color: $label-text-color, |
42 |
| - unselected-label-text-color: $label-text-color, |
43 |
| - label-text-color: $label-text-color, |
44 |
| - disabled-label-text-color: $label-text-color, |
45 |
| - )); |
46 |
| - |
47 |
| - // We should be able to customize this using the `with-icon-selected-disabled-icon-color` key, |
48 |
| - // but the MDC validation blocks us, even though they have a lookup for it. |
49 |
| - @include mdc-chip-theme.checkmark-color((disabled: $label-text-color)); |
| 12 | +// Customizes the appearance of a chip. Note that ideally we would be doing this using the |
| 13 | +// `theme-styles` mixin, however it has the following problems: |
| 14 | +// 1. Some of MDC's base styles have **very** high specificity. E.g. setting the background of a |
| 15 | +// non-selected, enabled chip uses a selector like `.chip:not(.selected):not(.disabled)` instead of |
| 16 | +// just `.chip`. This specificity increase has a ripple effect over all other components that are |
| 17 | +// built on top of ours, making overrides extremely difficult and brittle. |
| 18 | +// 2. Including the individual mixins allows us to avoid a lot of unnecessary CSS (~35kb in the |
| 19 | +// dev app theme). |
| 20 | +@mixin _chip-variant($background, $foreground) { |
| 21 | + @include mdc-chip-theme.container-color($background); |
| 22 | + @include mdc-chip-theme.icon-color($foreground); |
| 23 | + @include mdc-chip-theme.trailing-action-color($foreground); |
| 24 | + @include mdc-chip-theme.checkmark-color($foreground); |
| 25 | + @include mdc-chip-theme.text-label-color($foreground); |
| 26 | + |
| 27 | + // Technically the avatar is only supposed to have an image, but we also allow for icons. |
| 28 | + // Set the color so the icons inherit the correct color. |
| 29 | + .mat-mdc-chip-avatar { |
| 30 | + color: $foreground; |
| 31 | + } |
50 | 32 | }
|
51 | 33 |
|
52 | 34 | @mixin _colored-chip($palette) {
|
53 | 35 | $background: theming.get-color-from-palette($palette);
|
54 | 36 | $foreground: theming.get-color-from-palette($palette, default-contrast);
|
55 | 37 |
|
56 |
| - &.mat-mdc-chip-selected { |
57 |
| - @include mdc-chip-theme.theme-styles(( |
58 |
| - elevated-selected-container-color: $background, |
59 |
| - flat-selected-container-color: $background, |
60 |
| - |
61 |
| - selected-focus-label-text-color: $foreground, |
62 |
| - selected-hover-label-text-color: $foreground, |
63 |
| - selected-pressed-label-text-color: $foreground, |
64 |
| - with-icon-selected-focus-icon-color: $foreground, |
65 |
| - with-icon-selected-hover-icon-color: $foreground, |
66 |
| - with-icon-selected-pressed-icon-color: $foreground, |
67 |
| - with-trailing-icon-trailing-icon-color: $foreground, |
68 |
| - |
69 |
| - with-icon-focus-icon-color: $foreground, |
70 |
| - with-icon-hover-icon-color: $foreground, |
71 |
| - with-icon-pressed-icon-color: $foreground, |
72 |
| - |
73 |
| - selected-label-text-color: $foreground, |
74 |
| - with-icon-selected-icon-color: $foreground, |
75 |
| - |
76 |
| - // TODO: the previous styles preserved the color when disabled and selected. It seems like |
77 |
| - // this could be supported by passing in `selected-disabled-label-text-color`, but the |
78 |
| - // theme key validation rejects it. |
79 |
| - )); |
80 |
| - } |
81 |
| - |
82 |
| - |
| 38 | + &.mat-mdc-chip-selected, |
83 | 39 | &.mat-mdc-chip-highlighted {
|
84 |
| - $icon-color: $foreground; |
85 |
| - $icon-map: ( |
86 |
| - enabled: $icon-color, |
87 |
| - disabled: $icon-color, |
88 |
| - hover: $icon-color, |
89 |
| - focus: $icon-color |
90 |
| - ); |
91 |
| - |
92 |
| - @include mdc-chip-theme.container-color($background); |
93 |
| - @include mdc-chip-theme.icon-color($icon-map); |
94 |
| - @include mdc-chip-theme.trailing-action-color($icon-map); |
95 |
| - @include mdc-chip-theme.text-label-color(( |
96 |
| - enabled: $foreground, |
97 |
| - disabled: $foreground, |
98 |
| - hover: $foreground, |
99 |
| - focus: $foreground |
100 |
| - )); |
| 40 | + @include _chip-variant($background, $foreground); |
101 | 41 | }
|
102 | 42 | }
|
103 | 43 |
|
|
111 | 51 |
|
112 | 52 | @include mdc-helpers.mat-using-mdc-theme($config) {
|
113 | 53 | .mat-mdc-standard-chip {
|
114 |
| - @include _base-chip($is-dark); |
| 54 | + @include _chip-variant( |
| 55 | + color.mix(mdc-theme-color.prop-value(on-surface), mdc-theme-color.prop-value(surface), 12%), |
| 56 | + if($is-dark, mdc-color-palette.$grey-50, mdc-color-palette.$grey-900) |
| 57 | + ); |
115 | 58 |
|
116 | 59 | &.mat-primary {
|
117 | 60 | @include _colored-chip($primary);
|
|
0 commit comments