Skip to content

Commit

Permalink
refactor(material/chips): Use tokens for state layer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zarend committed Jun 15, 2023
1 parent 840878f commit 8b55472
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/material/chips/_chips-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
}
}
}

.mat-mdc-chip-focus-overlay {
background: map.get(map.get($config, foreground), base);
}
}

@mixin typography($config-or-theme) {
Expand Down
9 changes: 9 additions & 0 deletions src/material/chips/chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@use '../core/style/layout-common';
@use '../core/focus-indicators/private' as focus-indicators-private;
@use '../core/tokens/m2/mdc/chip' as m2-mdc-chip;
@use '../core/tokens/token-utils';
@use '@material/theme/custom-properties' as mdc-custom-properties;

// The slots for tokens that will be configured in the theme can be emitted with no fallback.
Expand All @@ -21,6 +22,14 @@
// Add default values for tokens that aren't outputted by the theming API.
@include mdc-chip-theme.theme(m2-mdc-chip.get-unthemable-tokens());
}

// Add additional slots for the MDC chip tokens, needed in Angular Material.
@include token-utils.use-tokens(m2-mdc-chip.$prefix, $token-slots) {
.mat-mdc-chip-focus-overlay {
@include token-utils.create-token-slot(background, focus-state-layer-color);
@include token-utils.create-token-slot(opacity, focus-state-layer-opacity);
}
}
}

// We *should* be able to include these styles through MDC's
Expand Down
12 changes: 8 additions & 4 deletions src/material/core/tokens/m2/mdc/_chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ $prefix: (mdc, chip);
// Unused.
focus-outline-color: null,
// Unused.
focus-state-layer-color: null,
// Unused.
focus-state-layer-opacity: null,
// Unused.
hover-label-text-color: null,
// Unused.
hover-state-layer-color: null,
Expand Down Expand Up @@ -234,16 +230,24 @@ $prefix: (mdc, chip);
// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($config) {
$palette: map.get($config, primary);

$background: theming.get-color-from-palette($palette);
$foreground: theming.get-color-from-palette($palette, default-contrast);

$state-layer-color: theming.get-color-from-palette(map.get($config, foreground), base);
$state-layer-opacity: 0.12; // 0.12 is a common value in Material Design for opacity.

@return (
// The text color of a disabled chip.
disabled-label-text-color: $foreground,
// The background-color of the chip.
elevated-container-color: $background,
// The background-color of a disabled chip.
elevated-disabled-container-color: $background,
// The color of the focus state layer.
focus-state-layer-color: $state-layer-color,
// The opacity of the focus state layer.
focus-state-layer-opacity: $state-layer-opacity,
// The chip text color.
label-text-color: $foreground,
// The icon color of a chip.
Expand Down

0 comments on commit 8b55472

Please sign in to comment.