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`