|
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 | +// 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 | + } |
| 32 | +} |
| 33 | + |
| 34 | +@mixin _colored-chip($palette) { |
| 35 | + $background: theming.get-color-from-palette($palette); |
| 36 | + $foreground: theming.get-color-from-palette($palette, default-contrast); |
| 37 | + |
| 38 | + &.mat-mdc-chip-selected, |
| 39 | + &.mat-mdc-chip-highlighted { |
| 40 | + @include _chip-variant($background, $foreground); |
| 41 | + } |
20 | 42 | }
|
21 | 43 |
|
22 | 44 | @mixin color($config-or-theme) {
|
23 | 45 | $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; |
| 46 | + $primary: map.get($config, primary); |
| 47 | + $accent: map.get($config, accent); |
| 48 | + $warn: map.get($config, warn); |
| 49 | + $foreground: map.get($config, foreground); |
| 50 | + $is-dark: map.get($config, is-dark); |
35 | 51 |
|
36 | 52 | @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); |
| 53 | + .mat-mdc-standard-chip { |
| 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 | + ); |
44 | 58 |
|
45 |
| - .mat-mdc-chip { |
46 |
| - @include mdc-chips.fill-color-accessible($unselected-background, |
47 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
48 |
| - |
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 | 59 | &.mat-primary {
|
53 |
| - &.mdc-chip--selected, &.mat-mdc-chip-highlighted { |
54 |
| - @include _selected-color($primary); |
55 |
| - } |
| 60 | + @include _colored-chip($primary); |
56 | 61 | }
|
57 | 62 |
|
58 | 63 | &.mat-accent {
|
59 |
| - &.mdc-chip--selected, &.mat-mdc-chip-highlighted { |
60 |
| - @include _selected-color($accent); |
61 |
| - } |
| 64 | + @include _colored-chip($accent); |
62 | 65 | }
|
63 | 66 |
|
64 | 67 | &.mat-warn {
|
65 |
| - &.mdc-chip--selected, &.mat-mdc-chip-highlighted { |
66 |
| - @include _selected-color($warn); |
67 |
| - } |
| 68 | + @include _colored-chip($warn); |
68 | 69 | }
|
69 | 70 | }
|
70 | 71 | }
|
71 | 72 |
|
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; |
| 73 | + .mat-mdc-chip-focus-overlay { |
| 74 | + background: map.get($foreground, base); |
| 75 | + } |
76 | 76 | }
|
77 | 77 |
|
78 | 78 | @mixin typography($config-or-theme) {
|
79 | 79 | $config: typography.private-typography-to-2018-config(
|
80 | 80 | theming.get-typography-config($config-or-theme));
|
81 |
| - @include mdc-chips.set-core-styles($query: mdc-helpers.$mat-typography-styles-query); |
| 81 | + @include mdc-chip-set.core-styles($query: mdc-helpers.$mat-typography-styles-query); |
82 | 82 | @include mdc-helpers.mat-using-mdc-typography($config) {
|
83 |
| - @include mdc-chips.without-ripple($query: mdc-helpers.$mat-typography-styles-query); |
| 83 | + @include mdc-chip.without-ripple-styles($query: mdc-helpers.$mat-typography-styles-query); |
84 | 84 | }
|
85 | 85 | }
|
86 | 86 |
|
87 | 87 | @mixin density($config-or-theme) {
|
88 | 88 | $density-scale: theming.get-density-config($config-or-theme);
|
89 | 89 | .mat-mdc-chip {
|
90 |
| - @include mdc-chips.density($density-scale, $query: mdc-helpers.$mat-base-styles-query); |
| 90 | + @include mdc-chip-theme.density($density-scale, $query: mdc-helpers.$mat-base-styles-query); |
91 | 91 | }
|
92 | 92 | }
|
93 | 93 |
|
|
0 commit comments