-
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.
feat(chips): add removable filter chips
PiperOrigin-RevId: 530739415
- Loading branch information
1 parent
095355d
commit 748d70e
Showing
6 changed files
with
101 additions
and
13 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
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
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
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,49 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import '../../focus/focus-ring.js'; | ||
import '../../ripple/ripple.js'; | ||
|
||
import {html} from 'lit'; | ||
import {createRef, ref} from 'lit/directives/ref.js'; | ||
|
||
import {ripple} from '../../ripple/directive.js'; | ||
import {MdRipple} from '../../ripple/ripple.js'; | ||
|
||
import {Chip} from './chip.js'; | ||
|
||
/** @protected */ | ||
export function renderRemoveButton({disabled}: {disabled: boolean}) { | ||
const rippleRef = createRef<MdRipple>(); | ||
return html` | ||
<button class="trailing action" | ||
?disabled=${disabled ?? false} | ||
@click=${handleRemoveClick} | ||
${ripple(() => rippleRef.value || null)} | ||
> | ||
<md-focus-ring></md-focus-ring> | ||
<md-ripple ${ref(rippleRef)} unbounded></md-ripple> | ||
<svg class="icon" viewBox="0 96 960 960"> | ||
<path d="m249 849-42-42 231-231-231-231 42-42 231 231 231-231 42 42-231 231 231 231-42 42-231-231-231 231Z" /> | ||
</svg> | ||
<span class="touch"></span> | ||
</button> | ||
`; | ||
} | ||
|
||
function handleRemoveClick(this: Chip, event: Event) { | ||
if (this.disabled) { | ||
return; | ||
} | ||
|
||
event.stopPropagation(); | ||
const preventDefault = !this.dispatchEvent(new Event('remove')); | ||
if (preventDefault) { | ||
return; | ||
} | ||
|
||
this.remove(); | ||
} |