Skip to content

refactor(material/chips): Use tokens for state layer #27245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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