import { LitElement, html, css, CSSResultArray, TemplateResult } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import NileElement from '../internal/nile-element'; import { styles } from './nile-filter-chip.css'; /** * Nile filter-chip component. * * @tag nile-filter-chip */ @customElement('nile-filter-chip') export class NileFilterChip extends NileElement { @property({ type: String }) label = ''; @property({ type: String }) value = ''; @property({ type: Number }) viewMoreCount: number = 0; @property({ type: Boolean }) editable = false; @property({ type: Boolean }) closable = false; @property({ type: String }) icon = ''; @property({ type: String }) removeIcon = ''; @property({ type: Boolean, reflect: true }) active = false; @property({type:Boolean, reflect:true}) disabled = false; private static activeChips: NileFilterChip[] = []; public static get styles(): CSSResultArray { return [styles]; } connectedCallback() { super.connectedCallback(); this.registerChip(); } disconnectedCallback() { super.disconnectedCallback(); this.unregisterChip(); } private registerChip() { NileFilterChip.activeChips.push(this); } private unregisterChip() { NileFilterChip.activeChips = NileFilterChip.activeChips.filter( (chip) => chip !== this ); } private handleClose(event: Event) { event.stopPropagation(); this.dispatchEvent( new CustomEvent('nile-close', { detail: { value: this.value, viewMoreCount: this.viewMoreCount } }) ); this.remove(); } private handleClick() { if (this.disabled) return; this.dispatchEvent( new CustomEvent('nile-click', { detail: { value: this.value, viewMoreCount: this.viewMoreCount } }) ); } private getLabelSlot(): TemplateResult { return html` ${this.label}: `; } private getValueSlot(): TemplateResult { return html` ${this.value} `; } private getviewMoreCountSlot(): TemplateResult { return html` ${this.viewMoreCount ? html` +${this.viewMoreCount} ` : html``} `; } private getCloseIconSlot(): TemplateResult { return html` ${this.closable ? html` ` : html``} `; } public render(): TemplateResult { return html`
${this.icon ? html`${this.icon}` : html``} ${this.getLabelSlot()} ${this.getValueSlot()} ${this.getviewMoreCountSlot()} ${this.getCloseIconSlot()}
`; } } export default NileFilterChip; declare global { interface HTMLElementTagNameMap { 'nile-filter-chip': NileFilterChip; } }