Skip to content

Commit

Permalink
feat(chips): add high contrast support
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 542694155
  • Loading branch information
asyncLiz authored and copybara-github committed Jun 22, 2023
1 parent 39af025 commit 950cd4f
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 5 deletions.
4 changes: 3 additions & 1 deletion chips/assist-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {customElement} from 'lit/decorators.js';

import {AssistChip} from './lib/assist-chip.js';
import {styles as forcedColorsStyles} from './lib/assist-forced-colors-styles.css.js';
import {styles} from './lib/assist-styles.css.js';
import {styles as elevatedStyles} from './lib/elevated-styles.css.js';
import {styles as sharedStyles} from './lib/shared-styles.css.js';
Expand All @@ -25,5 +26,6 @@ declare global {
*/
@customElement('md-assist-chip')
export class MdAssistChip extends AssistChip {
static override styles = [sharedStyles, elevatedStyles, styles];
static override styles =
[sharedStyles, elevatedStyles, styles, forcedColorsStyles];
}
4 changes: 3 additions & 1 deletion chips/filter-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {customElement} from 'lit/decorators.js';

import {styles as elevatedStyles} from './lib/elevated-styles.css.js';
import {FilterChip} from './lib/filter-chip.js';
import {styles as forcedColorsStyles} from './lib/filter-forced-colors-styles.css.js';
import {styles} from './lib/filter-styles.css.js';
import {styles as selectableStyles} from './lib/selectable-styles.css.js';
import {styles as sharedStyles} from './lib/shared-styles.css.js';
Expand All @@ -28,6 +29,7 @@ declare global {
@customElement('md-filter-chip')
export class MdFilterChip extends FilterChip {
static override styles = [
sharedStyles, elevatedStyles, trailingIconStyles, selectableStyles, styles
sharedStyles, elevatedStyles, trailingIconStyles, selectableStyles, styles,
forcedColorsStyles
];
}
7 changes: 5 additions & 2 deletions chips/input-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {customElement} from 'lit/decorators.js';

import {InputChip} from './lib/input-chip.js';
import {styles as forcedColorsStyles} from './lib/input-forced-colors-styles.css.js';
import {styles} from './lib/input-styles.css.js';
import {styles as selectableStyles} from './lib/selectable-styles.css.js';
import {styles as sharedStyles} from './lib/shared-styles.css.js';
Expand All @@ -26,6 +27,8 @@ declare global {
*/
@customElement('md-input-chip')
export class MdInputChip extends InputChip {
static override styles =
[sharedStyles, trailingIconStyles, selectableStyles, styles];
static override styles = [
sharedStyles, trailingIconStyles, selectableStyles, styles,
forcedColorsStyles
];
}
14 changes: 14 additions & 0 deletions chips/lib/_elevated.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@
background: var(--_elevated-disabled-container-color);
opacity: var(--_elevated-disabled-container-opacity);
}

@media (forced-colors: active) {
.elevated md-elevation {
border: 1px solid transparent;
}

.elevated.link md-elevation {
border-color: ActiveText;
}

.elevated.disabled md-elevation {
border-color: GrayText;
}
}
}
8 changes: 8 additions & 0 deletions chips/lib/_selectable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@
.selected:active .leading.icon {
color: var(--_selected-pressed-leading-icon-color);
}

@media (forced-colors: active) {
.selected:not(.elevated)::before {
// for forced-colors. Don't add it to elevated containers since elevation
// already have a border added.
border: 1px solid transparent;
}
}
}
1 change: 1 addition & 0 deletions chips/lib/assist-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class AssistChip extends Chip {
// Link chips cannot be disabled
disabled: !this.href && this.disabled,
elevated: this.elevated,
link: !!this.href,
};
}

Expand Down
27 changes: 27 additions & 0 deletions chips/lib/assist-forced-colors-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './assist-chip';
// go/keep-sorted end

@media (forced-colors: active) {
:host {
@include assist-chip.theme(
(
'disabled-label-text-color': GrayText,
'disabled-label-text-opacity': 1,
'disabled-leading-icon-color': GrayText,
'disabled-leading-icon-opacity': 1,
'disabled-outline-color': GrayText,
'disabled-outline-opacity': 1,
)
);
}

.link .outline {
border-color: ActiveText;
}
}
34 changes: 34 additions & 0 deletions chips/lib/filter-forced-colors-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './filter-chip';
// go/keep-sorted end

@media (forced-colors: active) {
:host {
@include filter-chip.theme(
(
'disabled-label-text-color': GrayText,
'disabled-label-text-opacity': 1,
'disabled-leading-icon-color': GrayText,
'disabled-leading-icon-opacity': 1,
'disabled-trailing-icon-color': GrayText,
'disabled-trailing-icon-opacity': 1,
'disabled-outline-color': GrayText,
'disabled-outline-opacity': 1,
'trailing-icon-color': ButtonText,
'hover-trailing-icon-color': ButtonText,
'focus-trailing-icon-color': ButtonText,
'pressed-trailing-icon-color': ButtonText,
'selected-trailing-icon-color': ButtonText,
'selected-hover-trailing-icon-color': ButtonText,
'selected-focus-trailing-icon-color': ButtonText,
'selected-pressed-trailing-icon-color': ButtonText,
'selected-outline-width': 1px,
)
);
}
}
1 change: 1 addition & 0 deletions chips/lib/input-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class InputChip extends MultiActionChip {
avatar: this.avatar,
// Link chips cannot be disabled
disabled: !this.href && this.disabled,
link: !!this.href,
selected: this.selected,
'has-trailing': true,
};
Expand Down
39 changes: 39 additions & 0 deletions chips/lib/input-forced-colors-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './input-chip';
// go/keep-sorted end

@media (forced-colors: active) {
:host {
@include input-chip.theme(
(
'disabled-avatar-opacity': 1,
'disabled-label-text-color': GrayText,
'disabled-label-text-opacity': 1,
'disabled-leading-icon-color': GrayText,
'disabled-leading-icon-opacity': 1,
'disabled-trailing-icon-color': GrayText,
'disabled-trailing-icon-opacity': 1,
'disabled-outline-color': GrayText,
'disabled-outline-opacity': 1,
'trailing-icon-color': ButtonText,
'hover-trailing-icon-color': ButtonText,
'focus-trailing-icon-color': ButtonText,
'pressed-trailing-icon-color': ButtonText,
'selected-trailing-icon-color': ButtonText,
'selected-hover-trailing-icon-color': ButtonText,
'selected-focus-trailing-icon-color': ButtonText,
'selected-pressed-trailing-icon-color': ButtonText,
'selected-outline-width': 1px,
)
);
}

.link .outline {
border-color: ActiveText;
}
}
27 changes: 27 additions & 0 deletions chips/lib/suggestion-forced-colors-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './suggestion-chip';
// go/keep-sorted end

@media (forced-colors: active) {
:host {
@include suggestion-chip.theme(
(
'disabled-label-text-color': GrayText,
'disabled-label-text-opacity': 1,
'disabled-leading-icon-color': GrayText,
'disabled-leading-icon-opacity': 1,
'disabled-outline-color': GrayText,
'disabled-outline-opacity': 1,
)
);
}

.link .outline {
border-color: ActiveText;
}
}
4 changes: 3 additions & 1 deletion chips/suggestion-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {customElement} from 'lit/decorators.js';
import {styles as elevatedStyles} from './lib/elevated-styles.css.js';
import {styles as sharedStyles} from './lib/shared-styles.css.js';
import {SuggestionChip} from './lib/suggestion-chip.js';
import {styles as forcedColorsStyles} from './lib/suggestion-forced-colors-styles.css.js';
import {styles} from './lib/suggestion-styles.css.js';

declare global {
Expand All @@ -25,5 +26,6 @@ declare global {
*/
@customElement('md-suggestion-chip')
export class MdSuggestionChip extends SuggestionChip {
static override styles = [sharedStyles, elevatedStyles, styles];
static override styles =
[sharedStyles, elevatedStyles, styles, forcedColorsStyles];
}
1 change: 1 addition & 0 deletions tokens/_md-comp-suggestion-chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $supported-tokens: (
'disabled-label-text-color',
'disabled-label-text-opacity',
'disabled-leading-icon-color',
'disabled-leading-icon-opacity',
'disabled-outline-color',
'disabled-outline-opacity',
'elevated-container-color',
Expand Down

0 comments on commit 950cd4f

Please sign in to comment.