Skip to content

Commit 0a1c8ee

Browse files
authored
fix(material/chips): Tokenize chip outline and disabled opacity (#28488)
This will give us the flexibility we need to implement M3 chips
1 parent 25a6b78 commit 0a1c8ee

File tree

5 files changed

+80
-23
lines changed

5 files changed

+80
-23
lines changed

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,6 @@
201201
radius: 8px,
202202
), $exclude-hardcoded),
203203
with-avatar-avatar-size: _hardcode(24px, $exclude-hardcoded),
204-
elevated-container-color: map.get($systems, md-sys-color, surface-container-low),
205-
elevated-disabled-container-color: mat.private-safe-color-change(
206-
map.get($systems, md-sys-color, on-surface),
207-
$alpha: 0.12,
208-
),
209204
label-text-color: map.get($systems, md-sys-color, on-surface-variant),
210205
disabled-label-text-color: mat.private-safe-color-change(
211206
map.get($systems, md-sys-color, on-surface),
@@ -225,6 +220,13 @@
225220
),
226221
focus-state-layer-opacity: map.get($systems, md-sys-state, focus-state-layer-opacity),
227222
focus-state-layer-color: map.get($systems, md-sys-color, on-surface-variant),
223+
outline-width: _hardcode(1px, $exclude-hardcoded),
224+
outline-color: map.get($systems, md-sys-color, outline),
225+
disabled-outline-color: mat.private-safe-color-change(
226+
map.get($systems, md-sys-color, on-surface),
227+
$alpha: 0.12,
228+
),
229+
focus-outline-color: map.get($systems, md-sys-color, on-surface-variant),
228230
),
229231
), (
230232
// Color variants:

src/material/chips/_chips-theme.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use 'sass:color';
22
@use '@material/chips/chip-theme' as mdc-chip-theme;
33
@use '../core/tokens/m2/mdc/chip' as tokens-mdc-chip;
4+
@use '../core/tokens/m2/mat/chip' as tokens-mat-chip;
45
@use '../core/tokens/token-utils';
56
@use '../core/theming/theming';
67
@use '../core/theming/inspection';
@@ -16,6 +17,8 @@
1617
@else {
1718
.mat-mdc-standard-chip {
1819
@include mdc-chip-theme.theme(tokens-mdc-chip.get-unthemable-tokens());
20+
@include token-utils.create-token-values(
21+
tokens-mat-chip.$prefix, tokens-mat-chip.get-unthemable-tokens());
1922
}
2023
}
2124
}
@@ -33,6 +36,8 @@
3336
.mat-mdc-standard-chip {
3437
$default-color-tokens: tokens-mdc-chip.get-color-tokens($theme);
3538
@include mdc-chip-theme.theme($default-color-tokens);
39+
@include token-utils.create-token-values(
40+
tokens-mat-chip.$prefix, tokens-mat-chip.get-color-tokens($theme));
3641

3742
&.mat-mdc-chip-selected,
3843
&.mat-mdc-chip-highlighted {
@@ -66,6 +71,8 @@
6671

6772
.mat-mdc-standard-chip {
6873
@include mdc-chip-theme.theme($typography-tokens);
74+
@include token-utils.create-token-values(
75+
tokens-mat-chip.$prefix, tokens-mat-chip.get-typography-tokens($theme));
6976
}
7077
}
7178
}
@@ -81,6 +88,8 @@
8188

8289
.mat-mdc-chip.mat-mdc-standard-chip {
8390
@include mdc-chip-theme.theme($density-tokens);
91+
@include token-utils.create-token-values(
92+
tokens-mat-chip.$prefix, tokens-mat-chip.get-density-tokens($theme));
8493
}
8594
}
8695
}
@@ -112,5 +121,7 @@
112121

113122
@mixin _theme-from-tokens($tokens, $options...) {
114123
$mdc-chip-tokens: token-utils.get-tokens-for($tokens, tokens-mdc-chip.$prefix, $options...);
124+
$mat-chip-tokens: token-utils.get-tokens-for($tokens, tokens-mat-chip.$prefix);
115125
@include mdc-chip-theme.theme($mdc-chip-tokens);
126+
@include token-utils.create-token-values(tokens-mat-chip.$prefix, $mat-chip-tokens);
116127
}

src/material/chips/chip.scss

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,46 @@
44
@use '../core/mdc-helpers/mdc-helpers';
55
@use '../core/style/layout-common';
66
@use '../core/focus-indicators/private' as focus-indicators-private;
7-
@use '../core/tokens/m2/mdc/chip' as m2-mdc-chip;
7+
@use '../core/tokens/m2/mdc/chip' as tokens-mdc-chip;
8+
@use '../core/tokens/m2/mat/chip' as tokens-mat-chip;
89
@use '../core/tokens/token-utils';
910
@use '@material/theme/custom-properties' as mdc-custom-properties;
1011

1112
// The slots for tokens that will be configured in the theme can be emitted with no fallback.
1213
@include mdc-custom-properties.configure($emit-fallback-values: false, $emit-fallback-vars: false) {
13-
$token-slots: m2-mdc-chip.get-token-slots();
14+
$mdc-chip-token-slots: tokens-mdc-chip.get-token-slots();
15+
$mat-chip-token-slots: tokens-mat-chip.get-token-slots();
1416

1517
// Add the MDC chip static styles.
1618
@include mdc-chip.static-styles();
1719

1820
.mat-mdc-standard-chip {
1921
// Add the official slots for the MDC chip.
20-
@include mdc-chip-theme.theme-styles($token-slots);
22+
@include mdc-chip-theme.theme-styles($mdc-chip-token-slots);
2123
}
2224

2325
// Add additional slots for the MDC chip tokens, needed in Angular Material.
24-
@include token-utils.use-tokens(m2-mdc-chip.$prefix, $token-slots) {
26+
@include token-utils.use-tokens(tokens-mdc-chip.$prefix, $mdc-chip-token-slots) {
2527
.mat-mdc-chip-focus-overlay {
2628
@include token-utils.create-token-slot(background, focus-state-layer-color);
2729
@include token-utils.create-token-slot(opacity, focus-state-layer-opacity);
2830
}
2931
}
32+
33+
@include token-utils.use-tokens(tokens-mat-chip.$prefix, $mat-chip-token-slots) {
34+
// Historically, MDC did not support disabled chips, so we needed our own disabled styles.
35+
// Now that MDC supports disabled styles, we should switch to using theirs.
36+
.mat-mdc-standard-chip.mdc-evolution-chip--disabled {
37+
@include token-utils.create-token-slot(opacity, disabled-container-opacity);
38+
}
39+
}
3040
}
3141

3242
// We *should* be able to include these styles through MDC's
3343
// `theme-styles` mixin, but we can't at the time of writing.
3444
@mixin _missing-mdc-theme-styles() {
3545
.mat-mdc-standard-chip {
46+
@include mdc-chip-theme.outline-style(solid);
3647
@include mdc-chip-theme.checkmark-size(mdc-chip-theme.$checkmark-size);
3748
@include mdc-chip-theme.trailing-action-size(mdc-chip-theme.$trailing-action-size);
3849
@include mdc-chip-theme.horizontal-padding(
@@ -98,12 +109,6 @@
98109
}
99110
}
100111

101-
// Angular Material supports disabled chips, which MDC does not.
102-
// Dim the disabled chips and stop MDC from changing the icon color on click.
103-
&.mdc-evolution-chip--disabled {
104-
opacity: 0.4;
105-
}
106-
107112
// MDC sets `overflow: hidden` on these elements in order to truncate the text. This is
108113
// unnecessary since our chips don't truncate their text and it makes it difficult to style
109114
// the strong focus indicators so we need to override it.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@use '../../token-utils';
2+
@use '../../../style/sass-utils';
3+
4+
// The prefix used to generate the fully qualified name for tokens in this file.
5+
$prefix: (mat, chip);
6+
7+
// Tokens that can't be configured through Angular Material's current theming API,
8+
// but may be in a future version of the theming API.
9+
@function get-unthemable-tokens() {
10+
@return (
11+
disabled-container-opacity: 0.4,
12+
);
13+
}
14+
15+
// Tokens that can be configured through Angular Material's color theming API.
16+
@function get-color-tokens($theme) {
17+
@return ();
18+
}
19+
20+
// Tokens that can be configured through Angular Material's typography theming API.
21+
@function get-typography-tokens($theme) {
22+
@return ();
23+
}
24+
25+
// Tokens that can be configured through Angular Material's density theming API.
26+
@function get-density-tokens($theme) {
27+
@return ();
28+
}
29+
30+
// Combines the tokens generated by the above functions into a single map with placeholder values.
31+
// This is used to create token slots.
32+
@function get-token-slots() {
33+
@return sass-utils.deep-merge-all(
34+
get-unthemable-tokens(),
35+
get-color-tokens(token-utils.$placeholder-color-config),
36+
get-typography-tokens(token-utils.$placeholder-typography-config),
37+
get-density-tokens(token-utils.$placeholder-density-config)
38+
);
39+
}

src/material/core/tokens/m2/mdc/_chip.scss

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ $prefix: (mdc, chip);
3939
with-avatar-avatar-size: 28px,
4040
// The width & height of the chip icon.
4141
with-icon-icon-size: 18px,
42+
// The chip's border width.
43+
outline-width: 0,
44+
// The chip's border color.
45+
outline-color: transparent,
46+
// The chip's border color when disabled.
47+
disabled-outline-color: transparent,
48+
// The chip's border color when focused.
49+
focus-outline-color: transparent,
4250
// Not used by MDC.
4351
disabled-label-text-opacity: null,
4452
// Not used by MDC.
@@ -55,8 +63,6 @@ $prefix: (mdc, chip);
5563
flat-selected-outline-width: null,
5664
// Our chips do not have a border.
5765
flat-unselected-outline-width: null,
58-
// Our chips do not have a border.
59-
outline-width: null,
6066
// Not used by MDC.
6167
with-avatar-disabled-avatar-opacity: null,
6268
// Not used by MDC.
@@ -73,8 +79,6 @@ $prefix: (mdc, chip);
7379
container-elevation: null,
7480
// Elevated chips not implemented.
7581
container-shadow-color: null,
76-
// Our chips do not have a border.
77-
disabled-outline-color: null,
7882
// Elevated chips not implemented.
7983
elevated-container-elevation: null,
8084
// Elevated chips not implemented.
@@ -136,16 +140,12 @@ $prefix: (mdc, chip);
136140
// Unused.
137141
focus-label-text-color: null,
138142
// Unused.
139-
focus-outline-color: null,
140-
// Unused.
141143
hover-label-text-color: null,
142144
// Unused.
143145
hover-state-layer-color: null,
144146
// Unused.
145147
hover-state-layer-opacity: null,
146148
// Unused.
147-
outline-color: null,
148-
// Unused.
149149
pressed-label-text-color: null,
150150
// Unused.
151151
pressed-state-layer-color: null,

0 commit comments

Comments
 (0)