Skip to content

Commit 3be0809

Browse files
authored
refactor(material/chips): Use tokens for state layer (#27245)
Refactors how the state layer for chips components is styled. Use the `focus-state-layer-color` and `focus-state-layer-opacity` to style the focus state layer. Does not make visual changes.
1 parent cc52d61 commit 3be0809

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/material/chips/_chips-theme.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@
5858
}
5959
}
6060
}
61-
62-
.mat-mdc-chip-focus-overlay {
63-
background: map.get(map.get($config, foreground), base);
64-
}
6561
}
6662

6763
@mixin typography($config-or-theme) {

src/material/chips/chip.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@use '../core/style/layout-common';
66
@use '../core/focus-indicators/private' as focus-indicators-private;
77
@use '../core/tokens/m2/mdc/chip' as m2-mdc-chip;
8+
@use '../core/tokens/token-utils';
89
@use '@material/theme/custom-properties' as mdc-custom-properties;
910

1011
// The slots for tokens that will be configured in the theme can be emitted with no fallback.
@@ -21,6 +22,14 @@
2122
// Add default values for tokens that aren't outputted by the theming API.
2223
@include mdc-chip-theme.theme(m2-mdc-chip.get-unthemable-tokens());
2324
}
25+
26+
// Add additional slots for the MDC chip tokens, needed in Angular Material.
27+
@include token-utils.use-tokens(m2-mdc-chip.$prefix, $token-slots) {
28+
.mat-mdc-chip-focus-overlay {
29+
@include token-utils.create-token-slot(background, focus-state-layer-color);
30+
@include token-utils.create-token-slot(opacity, focus-state-layer-opacity);
31+
}
32+
}
2433
}
2534

2635
// We *should* be able to include these styles through MDC's

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ $prefix: (mdc, chip);
135135
// Unused.
136136
focus-outline-color: null,
137137
// Unused.
138-
focus-state-layer-color: null,
139-
// Unused.
140-
focus-state-layer-opacity: null,
141-
// Unused.
142138
hover-label-text-color: null,
143139
// Unused.
144140
hover-state-layer-color: null,
@@ -234,16 +230,24 @@ $prefix: (mdc, chip);
234230
// Tokens that can be configured through Angular Material's color theming API.
235231
@function get-color-tokens($config) {
236232
$palette: map.get($config, primary);
233+
237234
$background: theming.get-color-from-palette($palette);
238235
$foreground: theming.get-color-from-palette($palette, default-contrast);
239236

237+
$state-layer-color: theming.get-color-from-palette(map.get($config, foreground), base);
238+
$state-layer-opacity: 0.12; // 0.12 is a common value in Material Design for opacity.
239+
240240
@return (
241241
// The text color of a disabled chip.
242242
disabled-label-text-color: $foreground,
243243
// The background-color of the chip.
244244
elevated-container-color: $background,
245245
// The background-color of a disabled chip.
246246
elevated-disabled-container-color: $background,
247+
// The color of the focus state layer.
248+
focus-state-layer-color: $state-layer-color,
249+
// The opacity of the focus state layer.
250+
focus-state-layer-opacity: $state-layer-opacity,
247251
// The chip text color.
248252
label-text-color: $foreground,
249253
// The icon color of a chip.

0 commit comments

Comments
 (0)