|
2 | 2 | @use 'sass:map';
|
3 | 3 | @use 'sass:meta';
|
4 | 4 | @use '@material/chips/chip-theme' as mdc-chip-theme;
|
5 |
| -@use '@material/chips/chip-set' as mdc-chip-set; |
6 |
| -@use '@material/theme/theme-color' as mdc-theme-color; |
7 |
| -@use '@material/theme/color-palette' as mdc-color-palette; |
8 |
| -@use '@material/typography' as mdc-typography; |
9 |
| -@use '../core/mdc-helpers/mdc-helpers'; |
| 5 | +@use '../core/tokens/m2/mdc/chip' as tokens-mdc-chip; |
| 6 | +@use '../core/theming/palette'; |
10 | 7 | @use '../core/theming/theming';
|
11 | 8 | @use '../core/typography/typography';
|
| 9 | +@use '../core/mdc-helpers/mdc-helpers'; |
12 | 10 |
|
13 |
| -@mixin _chip-variant($background, $foreground) { |
14 |
| - @include mdc-chip-theme.theme(( |
15 |
| - elevated-container-color: $background, |
16 |
| - elevated-disabled-container-color: $background, |
17 |
| - label-text-color: $foreground, |
18 |
| - disabled-label-text-color: $foreground, |
19 |
| - with-icon-icon-color: $foreground, |
20 |
| - with-icon-disabled-icon-color: $foreground, |
21 |
| - with-trailing-icon-disabled-trailing-icon-color: $foreground, |
22 |
| - with-trailing-icon-trailing-icon-color: $foreground, |
23 |
| - with-icon-selected-icon-color: $foreground, |
24 |
| - )); |
25 |
| -} |
| 11 | +@function _get-default-palette($config) { |
| 12 | + $is-dark: map.get($config, is-dark); |
| 13 | + $grey-50: map.get(palette.$grey-palette, 50); |
| 14 | + $grey-900: map.get(palette.$grey-palette, 900); |
| 15 | + $default-foreground: if($is-dark, $grey-50, $grey-900); |
26 | 16 |
|
27 |
| -@mixin _colored-chip($palette) { |
28 |
| - $background: theming.get-color-from-palette($palette); |
29 |
| - $foreground: theming.get-color-from-palette($palette, default-contrast); |
| 17 | + $surface: map.get(map.get($config, background), card); |
| 18 | + $on-surface: if( |
| 19 | + mdc-helpers.variable-safe-contrast-tone($surface, $is-dark) == 'dark', |
| 20 | + #000, |
| 21 | + #fff |
| 22 | + ); |
| 23 | + $default-background: if( |
| 24 | + meta.type-of($on-surface) == color and meta.type-of($surface) == color, |
| 25 | + color.mix($on-surface, $surface, 12%), |
| 26 | + $on-surface |
| 27 | + ); |
30 | 28 |
|
31 |
| - &.mat-mdc-chip-selected, |
32 |
| - &.mat-mdc-chip-highlighted { |
33 |
| - @include _chip-variant($background, $foreground); |
34 |
| - } |
| 29 | + @return (default: $default-background, default-contrast: $default-foreground); |
35 | 30 | }
|
36 | 31 |
|
37 | 32 | @mixin color($config-or-theme) {
|
38 | 33 | $config: theming.get-color-config($config-or-theme);
|
39 |
| - $primary: map.get($config, primary); |
40 |
| - $accent: map.get($config, accent); |
41 |
| - $warn: map.get($config, warn); |
42 |
| - $foreground: map.get($config, foreground); |
43 |
| - $is-dark: map.get($config, is-dark); |
44 |
| - |
45 |
| - @include mdc-helpers.using-mdc-theme($config) { |
46 |
| - $on-surface: mdc-theme-color.prop-value(on-surface); |
47 |
| - $surface: mdc-theme-color.prop-value(surface); |
48 |
| - |
49 |
| - .mat-mdc-standard-chip { |
50 |
| - $standard-background: if( |
51 |
| - meta.type-of($on-surface) == color and meta.type-of($surface) == color, |
52 |
| - color.mix($on-surface, $surface, 12%), |
53 |
| - $on-surface |
54 |
| - ); |
55 | 34 |
|
56 |
| - @include _chip-variant( |
57 |
| - $standard-background, |
58 |
| - if($is-dark, mdc-color-palette.$grey-50, mdc-color-palette.$grey-900) |
59 |
| - ); |
| 35 | + .mat-mdc-standard-chip { |
| 36 | + $default-palette: _get-default-palette($config); |
| 37 | + $default-config: map.merge($config, (primary: $default-palette)); |
| 38 | + $default-color-tokens: tokens-mdc-chip.get-color-tokens($default-config); |
| 39 | + @include mdc-chip-theme.theme($default-color-tokens); |
60 | 40 |
|
| 41 | + &.mat-mdc-chip-selected, |
| 42 | + &.mat-mdc-chip-highlighted { |
61 | 43 | &.mat-primary {
|
62 |
| - @include _colored-chip($primary); |
| 44 | + $primary-color-tokens: tokens-mdc-chip.get-color-tokens($config); |
| 45 | + @include mdc-chip-theme.theme($primary-color-tokens); |
63 | 46 | }
|
64 | 47 |
|
65 | 48 | &.mat-accent {
|
66 |
| - @include _colored-chip($accent); |
| 49 | + $accent-config: map.merge($config, (primary: map.get($config, accent))); |
| 50 | + $accent-color-tokens: tokens-mdc-chip.get-color-tokens($accent-config); |
| 51 | + @include mdc-chip-theme.theme($accent-color-tokens); |
67 | 52 | }
|
68 | 53 |
|
69 | 54 | &.mat-warn {
|
70 |
| - @include _colored-chip($warn); |
| 55 | + $warn-config: map.merge($config, (primary: map.get($config, warn))); |
| 56 | + $warn-color-tokens: tokens-mdc-chip.get-color-tokens($warn-config); |
| 57 | + @include mdc-chip-theme.theme($warn-color-tokens); |
71 | 58 | }
|
72 | 59 | }
|
73 | 60 | }
|
74 | 61 |
|
75 | 62 | .mat-mdc-chip-focus-overlay {
|
76 |
| - background: map.get($foreground, base); |
| 63 | + background: map.get(map.get($config, foreground), base); |
77 | 64 | }
|
78 | 65 | }
|
79 | 66 |
|
80 | 67 | @mixin typography($config-or-theme) {
|
81 | 68 | $config: typography.private-typography-to-2018-config(
|
82 |
| - theming.get-typography-config($config-or-theme)); |
83 |
| - @include mdc-chip-set.core-styles($query: mdc-helpers.$mdc-typography-styles-query); |
84 |
| - @include mdc-helpers.using-mdc-typography($config) { |
85 |
| - // Note that we don't go through MDC's typography mixin, because it assigns the styles to |
86 |
| - // an inner element which makes it difficult for clients to customize. Instead we apply the |
87 |
| - // same styles ourselves to the root. |
88 |
| - .mat-mdc-standard-chip { |
89 |
| - @include mdc-typography.typography(body2, $query: mdc-helpers.$mdc-typography-styles-query); |
90 |
| - } |
| 69 | + theming.get-typography-config($config-or-theme) |
| 70 | + ); |
| 71 | + $typography-tokens: tokens-mdc-chip.get-typography-tokens($config); |
| 72 | + |
| 73 | + .mat-mdc-standard-chip { |
| 74 | + @include mdc-chip-theme.theme($typography-tokens); |
91 | 75 | }
|
92 | 76 | }
|
93 | 77 |
|
94 | 78 | @mixin density($config-or-theme) {
|
95 | 79 | $density-scale: theming.get-density-config($config-or-theme);
|
96 |
| - $density-scale: theming.clamp-density($density-scale, -2); |
| 80 | + $density-tokens: tokens-mdc-chip.get-density-tokens($density-scale); |
97 | 81 | .mat-mdc-chip.mat-mdc-standard-chip {
|
98 |
| - @include mdc-chip-theme.density($density-scale, $query: mdc-helpers.$mdc-base-styles-query); |
| 82 | + @include mdc-chip-theme.theme($density-tokens); |
99 | 83 | }
|
100 | 84 | }
|
101 | 85 |
|
|
0 commit comments