diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index 2aae417..147e988 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@design.estate/dees-catalog', - version: '1.0.229', + version: '1.0.230', description: 'website for lossless.com' } diff --git a/ts_web/elements/dees-chips.demo.ts b/ts_web/elements/dees-chips.demo.ts index 235f955..6db382e 100644 --- a/ts_web/elements/dees-chips.demo.ts +++ b/ts_web/elements/dees-chips.demo.ts @@ -22,6 +22,7 @@ export const demoFunc = () => html` > - ${this.selectableChips.map(chip => html` -
this.selectChip(chip)} class="chip ${this.isSelected(chip) ? 'selected' : ''}"> - ${chip.key ? html`
${chip.key}
` : html``}${chip.value} -
- `)} + ${this.selectableChips.map( + (chip) => html` +
this.selectChip(chip)} + class="chip ${this.isSelected(chip) ? 'selected' : ''}" + > + ${chip.key ? html`
${chip.key}
` : html``} ${chip.value} + ${this.chipsAreRemovable + ? html` + { + event.stopPropagation(); // prevent the selectChip event from being triggered + this.removeChip(chip); + }} + .iconFA=${'xmark'} + > + ` + : html``} +
+ ` + )} `; } @@ -121,7 +150,7 @@ export class DeesChips extends DeesElement { if (this.selectionMode === 'single') { return this.selectedChip?.key === chip.key; } else { - return this.selectedChips.some(selected => selected.key === chip.key); + return this.selectedChips.some((selected) => selected.key === chip.key); } } @@ -138,9 +167,9 @@ export class DeesChips extends DeesElement { this.selectedChip = chip; this.selectedChips = [chip]; } - } else if(this.selectionMode === 'multiple') { + } else if (this.selectionMode === 'multiple') { if (this.isSelected(chip)) { - this.selectedChips = this.selectedChips.filter(selected => selected.key !== chip.key); + this.selectedChips = this.selectedChips.filter((selected) => selected.key !== chip.key); } else { this.selectedChips = [...this.selectedChips, chip]; } @@ -148,4 +177,20 @@ export class DeesChips extends DeesElement { } console.log(this.selectedChips); } + + public removeChip(chipToRemove: Tag): void { + // Remove the chip from selectableChips + this.selectableChips = this.selectableChips.filter((chip) => chip.key !== chipToRemove.key); + + // Remove the chip from selectedChips if present + this.selectedChips = this.selectedChips.filter((chip) => chip.key !== chipToRemove.key); + + // If the removed chip was the selectedChip, set selectedChip to null + if (this.selectedChip && this.selectedChip.key === chipToRemove.key) { + this.selectedChip = null; + } + + // Trigger an update to re-render the component + this.requestUpdate(); + } }