-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
275 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// | ||
// Copyright 2023 Google LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
@forward './lib/filter-chip' show theme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {customElement} from 'lit/decorators.js'; | ||
|
||
import {FilterChip} from './lib/filter-chip.js'; | ||
import {styles} from './lib/filter-styles.css.js'; | ||
import {styles as sharedStyles} from './lib/shared-styles.css.js'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'md-filter-chip': MdFilterChip; | ||
} | ||
} | ||
|
||
/** | ||
* TODO(b/243982145): add docs | ||
* | ||
* @final | ||
* @suppress {visibility} | ||
*/ | ||
@customElement('md-filter-chip') | ||
export class MdFilterChip extends FilterChip { | ||
static override styles = [sharedStyles, styles]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// import 'jasmine'; (google3-only) | ||
|
||
import {createTokenTests} from '../testing/tokens.js'; | ||
|
||
import {MdFilterChip} from './filter-chip.js'; | ||
|
||
describe('<md-filter-chip>', () => { | ||
describe('.styles', () => { | ||
createTokenTests(MdFilterChip.styles); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// | ||
// Copyright 2023 Google LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// go/keep-sorted start | ||
@use '../../ripple/ripple'; | ||
@use '../../sass/theme'; | ||
@use '../../tokens'; | ||
// go/keep-sorted end | ||
|
||
@mixin theme($tokens) { | ||
$tokens: theme.validate-theme(tokens.md-comp-filter-chip-values(), $tokens); | ||
|
||
@each $token, $value in $tokens { | ||
--md-filter-chip-#{$token}: #{$value}; | ||
} | ||
} | ||
|
||
@mixin styles() { | ||
$tokens: tokens.md-comp-filter-chip-values(); | ||
|
||
:host { | ||
@each $token, $value in $tokens { | ||
--_#{$token}: #{$value}; | ||
} | ||
} | ||
|
||
.selected { | ||
@include ripple.theme( | ||
( | ||
focus-color: var(--_selected-focus-state-layer-color), | ||
focus-opacity: var(--_selected-focus-state-layer-opacity), | ||
hover-color: var(--_selected-hover-state-layer-color), | ||
hover-opacity: var(--_selected-hover-state-layer-opacity), | ||
pressed-color: var(--_selected-pressed-state-layer-color), | ||
pressed-opacity: var(--_selected-pressed-state-layer-opacity), | ||
) | ||
); | ||
} | ||
|
||
.selected .icon.leading { | ||
width: var(--_icon-size); | ||
} | ||
|
||
.checkmark { | ||
inset: 0; | ||
opacity: 0; | ||
position: absolute; | ||
} | ||
|
||
.selected .checkmark { | ||
opacity: 1; | ||
} | ||
|
||
.selected::before { | ||
background: var(--_selected-container-color); | ||
} | ||
|
||
.selected .outline { | ||
border-width: var(--_selected-outline-width); | ||
} | ||
|
||
.selected.elevated::before { | ||
background: var(--_elevated-selected-container-color); | ||
} | ||
|
||
.selected.disabled::before { | ||
background: var(--_disabled-selected-container-color); | ||
opacity: var(--_disabled-selected-container-opacity); | ||
} | ||
|
||
.selected .label { | ||
color: var(--_selected-label-text-color); | ||
} | ||
|
||
.selected:hover .label { | ||
color: var(--_selected-hover-label-text-color); | ||
} | ||
|
||
.selected:focus .label { | ||
color: var(--_selected-focus-label-text-color); | ||
} | ||
|
||
.selected:active .label { | ||
color: var(--_selected-pressed-label-text-color); | ||
} | ||
|
||
.selected .icon.leading { | ||
color: var(--_selected-leading-icon-color); | ||
} | ||
|
||
.selected:hover .icon.leading { | ||
color: var(--_selected-hover-leading-icon-color); | ||
} | ||
|
||
.selected:focus .icon.leading { | ||
color: var(--_selected-focus-leading-icon-color); | ||
} | ||
|
||
.selected:active .icon.leading { | ||
color: var(--_selected-pressed-leading-icon-color); | ||
} | ||
|
||
.icon.trailing { | ||
color: var(--_trailing-icon-color); | ||
} | ||
|
||
:hover .icon.trailing { | ||
color: var(--_hover-trailing-icon-color); | ||
} | ||
|
||
:focus .icon.trailing { | ||
color: var(--_focus-trailing-icon-color); | ||
} | ||
|
||
:active .icon.trailing { | ||
color: var(--_pressed-trailing-icon-color); | ||
} | ||
|
||
.disabled .icon.trailing { | ||
color: var(--_disabled-trailing-icon-color); | ||
opacity: var(--_disabled-trailing-icon-opacity); | ||
} | ||
|
||
.selected .icon.trailing { | ||
color: var(--_selected-trailing-icon-color); | ||
} | ||
|
||
.selected:hover .icon.trailing { | ||
color: var(--_selected-hover-trailing-icon-color); | ||
} | ||
|
||
.selected:focus .icon.trailing { | ||
color: var(--_selected-focus-trailing-icon-color); | ||
} | ||
|
||
.selected:active .icon.trailing { | ||
color: var(--_selected-pressed-trailing-icon-color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {PropertyValues, svg} from 'lit'; | ||
import {property} from 'lit/decorators.js'; | ||
|
||
import {Chip} from './chip.js'; | ||
|
||
/** | ||
* A filter chip component. | ||
*/ | ||
export class FilterChip extends Chip { | ||
@property({type: Boolean}) selected = false; | ||
|
||
constructor() { | ||
super(); | ||
this.addEventListener('click', () => { | ||
this.selected = !this.selected; | ||
}); | ||
} | ||
|
||
protected override updated(changedProperties: PropertyValues<FilterChip>) { | ||
if (changedProperties.has('selected')) { | ||
this.dispatchEvent(new Event('change', {bubbles: true})); | ||
} | ||
} | ||
|
||
protected override getContainerClasses() { | ||
const classes = super.getContainerClasses(); | ||
return { | ||
...classes, | ||
selected: this.selected, | ||
}; | ||
} | ||
|
||
protected override renderLeadingIcon() { | ||
if (!this.selected) { | ||
return super.renderLeadingIcon(); | ||
} | ||
|
||
return svg` | ||
<svg class="checkmark" viewBox="0 0 18 18"> | ||
<path d="M6.75012 12.1274L3.62262 8.99988L2.55762 10.0574L6.75012 14.2499L15.7501 5.24988L14.6926 4.19238L6.75012 12.1274Z" /> | ||
</svg> | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// Copyright 2023 Google LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// go/keep-sorted start | ||
@use './filter-chip'; | ||
// go/keep-sorted end | ||
|
||
@include filter-chip.styles; |