|
1 |
| -@use '@material/chips/deprecated' as mdc-chips; |
| 1 | +@use '@material/chips/chip' as mdc-chip; |
| 2 | +@use '@material/chips/chip-theme' as mdc-chip-theme; |
| 3 | +@use '@material/chips/chip-set' as mdc-chip-set; |
2 | 4 | @use '@material/theme/theme-color' as mdc-theme-color;
|
| 5 | +@use '@material/theme/color-palette' as mdc-color-palette; |
3 | 6 | @use 'sass:color';
|
4 | 7 | @use 'sass:map';
|
5 | 8 | @use '../mdc-helpers/mdc-helpers';
|
6 | 9 | @use '../../material/core/typography/typography';
|
7 | 10 | @use '../../material/core/theming/theming';
|
8 | 11 |
|
9 |
| -@mixin _selected-color($color) { |
10 |
| - @include mdc-chips.fill-color($color, $query: mdc-helpers.$mat-theme-styles-query); |
11 |
| - @include mdc-chips.ink-color(text-primary-on-dark, $query: mdc-helpers.$mat-theme-styles-query); |
12 |
| - @include mdc-chips.selected-ink-color-without-ripple_( |
13 |
| - text-primary-on-dark, |
14 |
| - $query: mdc-helpers.$mat-theme-styles-query |
15 |
| - ); |
16 |
| - @include mdc-chips.leading-icon-color(text-primary-on-dark, |
17 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
18 |
| - @include mdc-chips.trailing-icon-color(text-primary-on-dark, |
19 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 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)); |
| 50 | +} |
| 51 | + |
| 52 | +@mixin _colored-chip($palette) { |
| 53 | + $background: theming.get-color-from-palette($palette); |
| 54 | + $foreground: theming.get-color-from-palette($palette, default-contrast); |
| 55 | + |
| 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 | + |
| 83 | + &.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 | + )); |
| 101 | + } |
20 | 102 | }
|
21 | 103 |
|
22 | 104 | @mixin color($config-or-theme) {
|
23 | 105 | $config: theming.get-color-config($config-or-theme);
|
24 |
| - $primary: theming.get-color-from-palette(map.get($config, primary)); |
25 |
| - $accent: theming.get-color-from-palette(map.get($config, accent)); |
26 |
| - $warn: theming.get-color-from-palette(map.get($config, warn)); |
27 |
| - $background: map.get($config, background); |
28 |
| - $unselected-background: theming.get-color-from-palette($background, unselected-chip); |
29 |
| - |
30 |
| - // Save original values of MDC global variables. We need to save these so we can restore the |
31 |
| - // variables to their original values and prevent unintended side effects from using this mixin. |
32 |
| - $orig-mdc-chips-fill-color-default: mdc-chips.$fill-color-default; |
33 |
| - $orig-mdc-chips-ink-color-default: mdc-chips.$ink-color-default; |
34 |
| - $orig-mdc-chips-icon-color: mdc-chips.$icon-color; |
| 106 | + $primary: map.get($config, primary); |
| 107 | + $accent: map.get($config, accent); |
| 108 | + $warn: map.get($config, warn); |
| 109 | + $foreground: map.get($config, foreground); |
| 110 | + $is-dark: map.get($config, is-dark); |
35 | 111 |
|
36 | 112 | @include mdc-helpers.mat-using-mdc-theme($config) {
|
37 |
| - mdc-chips.$fill-color-default: |
38 |
| - color.mix(mdc-theme-color.prop-value(on-surface), mdc-theme-color.prop-value(surface), 12%); |
39 |
| - mdc-chips.$ink-color-default: rgba(mdc-theme-color.prop-value(on-surface), 0.87); |
40 |
| - mdc-chips.$icon-color: mdc-theme-color.prop-value(on-surface); |
41 |
| - |
42 |
| - @include mdc-chips.set-core-styles($query: mdc-helpers.$mat-theme-styles-query); |
43 |
| - @include mdc-chips.without-ripple($query: mdc-helpers.$mat-theme-styles-query); |
44 |
| - |
45 |
| - .mat-mdc-chip { |
46 |
| - @include mdc-chips.fill-color-accessible($unselected-background, |
47 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 113 | + .mat-mdc-standard-chip { |
| 114 | + @include _base-chip($is-dark); |
48 | 115 |
|
49 |
| - // mdc-chip-fill-color-accessible includes mdc-chip-selected-ink-color which overrides the |
50 |
| - // opacity so selected chips always show a ripple. |
51 |
| - // Include the same mixins but use mdc-chip-selected-ink-color-without-ripple |
52 | 116 | &.mat-primary {
|
53 |
| - &.mdc-chip--selected, &.mat-mdc-chip-highlighted { |
54 |
| - @include _selected-color($primary); |
55 |
| - } |
| 117 | + @include _colored-chip($primary); |
56 | 118 | }
|
57 | 119 |
|
58 | 120 | &.mat-accent {
|
59 |
| - &.mdc-chip--selected, &.mat-mdc-chip-highlighted { |
60 |
| - @include _selected-color($accent); |
61 |
| - } |
| 121 | + @include _colored-chip($accent); |
62 | 122 | }
|
63 | 123 |
|
64 | 124 | &.mat-warn {
|
65 |
| - &.mdc-chip--selected, &.mat-mdc-chip-highlighted { |
66 |
| - @include _selected-color($warn); |
67 |
| - } |
| 125 | + @include _colored-chip($warn); |
68 | 126 | }
|
69 | 127 | }
|
70 | 128 | }
|
71 | 129 |
|
72 |
| - // Restore original values of MDC global variables. |
73 |
| - mdc-chips.$fill-color-default: $orig-mdc-chips-fill-color-default; |
74 |
| - mdc-chips.$ink-color-default: $orig-mdc-chips-ink-color-default; |
75 |
| - mdc-chips.$icon-color: $orig-mdc-chips-icon-color; |
| 130 | + .mat-mdc-chip-focus-overlay { |
| 131 | + background: map.get($foreground, base); |
| 132 | + } |
| 133 | + |
| 134 | + .mat-mdc-chip { |
| 135 | + &.mat-primary { |
| 136 | + &.mat-mdc-chip-highlighted, |
| 137 | + &.mat-mdc-chip-selected { |
| 138 | + .mat-mdc-focus-indicator::before { |
| 139 | + // Strong focus indicators use the primary color for their border which will blend in |
| 140 | + // with the background of a selected/highlighted chip. Use an accent color instead |
| 141 | + // so the indicator still stands out. |
| 142 | + border-color: theming.get-color-from-palette($accent); |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + } |
76 | 147 | }
|
77 | 148 |
|
78 | 149 | @mixin typography($config-or-theme) {
|
79 | 150 | $config: typography.private-typography-to-2018-config(
|
80 | 151 | theming.get-typography-config($config-or-theme));
|
81 |
| - @include mdc-chips.set-core-styles($query: mdc-helpers.$mat-typography-styles-query); |
| 152 | + @include mdc-chip-set.core-styles($query: mdc-helpers.$mat-typography-styles-query); |
82 | 153 | @include mdc-helpers.mat-using-mdc-typography($config) {
|
83 |
| - @include mdc-chips.without-ripple($query: mdc-helpers.$mat-typography-styles-query); |
| 154 | + @include mdc-chip.without-ripple-styles($query: mdc-helpers.$mat-typography-styles-query); |
84 | 155 | }
|
85 | 156 | }
|
86 | 157 |
|
87 | 158 | @mixin density($config-or-theme) {
|
88 | 159 | $density-scale: theming.get-density-config($config-or-theme);
|
89 | 160 | .mat-mdc-chip {
|
90 |
| - @include mdc-chips.density($density-scale, $query: mdc-helpers.$mat-base-styles-query); |
| 161 | + @include mdc-chip-theme.density($density-scale, $query: mdc-helpers.$mat-base-styles-query); |
91 | 162 | }
|
92 | 163 | }
|
93 | 164 |
|
|
0 commit comments