Skip to content
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

feat(tags): support removable #1266

Merged
merged 11 commits into from
May 30, 2022
11 changes: 11 additions & 0 deletions components/tags/src/vwc-tag-base.ts
Expand Up @@ -8,6 +8,7 @@ import type { ClassInfo } from 'lit-html/directives/class-map.js';
import {
LitElement, html, property, TemplateResult, queryAsync, state, query, eventOptions
} from 'lit-element';
import { nothing } from 'lit-html';


type TagConnotation = Extract<
Expand Down Expand Up @@ -44,6 +45,9 @@ export class VWCTagBase extends LitElement {
@property({ type: Boolean, reflect: true })
selectable = false;

@property({ type: Boolean, reflect: true })
removable = false;

@state() protected shouldRenderRipple = false;

protected rippleHandlers = new RippleHandlers(() => {
Expand Down Expand Up @@ -120,11 +124,18 @@ export class VWCTagBase extends LitElement {
</span>`;
}

protected renderRemoveButton(): TemplateResult {
return html`<button class="remove-button" @click="${()=> this.remove()}">
${this.renderIcon('close-line')}
</button>`;
}

override render(): TemplateResult {
return this.selectable
? this.renderTagSelectable()
: html`<span class="vwc-tag ${classMap(this.getRenderClasses())}">
${this.text}
${this.removable ? this.renderRemoveButton() : nothing}
</span>`;
}

Expand Down
10 changes: 10 additions & 0 deletions components/tags/src/vwc-tag.scss
Expand Up @@ -83,6 +83,7 @@

&.vwc-tag--selected {
&.layout-outlined {
border-color: var(#{layout.$vvd-layout-color-outline});
yinonov marked this conversation as resolved.
Show resolved Hide resolved
background-color: var(#{connotation.$vvd-color-connotation}-soft);
color: var(#{connotation.$vvd-color-connotation}-contrast);
}
Expand All @@ -105,6 +106,7 @@
}

> .vwc-tag__icon {
#{connotation.$vvd-color-connotation}: initial;
block-size: var(#{tags-variables.$namespace-icon-checkmark--size});
inline-size: var(#{tags-variables.$namespace-icon-checkmark--size});

Expand All @@ -126,3 +128,11 @@
// }
// }

.remove-button {
all: unset;
margin-inline-start: 10px;

.vwc-tag__icon {
--vvd-icon-size: 12px;
}
}
3 changes: 3 additions & 0 deletions components/tags/stories/tag.stories.js
Expand Up @@ -25,3 +25,6 @@ Outlined.args = { text: 'Outlined', layout: 'outlined' };

export const Selected = Template.bind({});
Selected.args = { text: 'Selected', selectable: true, selected: true };

export const Removable = Template.bind({});
Removable.args = { text: 'Removable', Removable: true };
Binary file modified ui-tests/snapshots/vwc-tags.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.