@design.estate/dees-catalog 1.0.229 → 1.0.230

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design.estate/dees-catalog",
3
- "version": "1.0.229",
3
+ "version": "1.0.230",
4
4
  "private": false,
5
5
  "description": "website for lossless.com",
6
6
  "main": "dist_ts_web/index.js",
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@design.estate/dees-catalog',
6
- version: '1.0.229',
6
+ version: '1.0.230',
7
7
  description: 'website for lossless.com'
8
8
  }
@@ -22,6 +22,7 @@ export const demoFunc = () => html`
22
22
  ></dees-chips>
23
23
  <dees-chips
24
24
  selectionMode="single"
25
+ chipsAreRemovable
25
26
  .selectableChips=${[
26
27
  { key: 'account1', value: 'Payment Account 1' },
27
28
  { key: 'account2', value: 'PaymentAccount2' },
@@ -19,7 +19,7 @@ declare global {
19
19
  }
20
20
  }
21
21
 
22
- type Tag = { key: string, value: string };
22
+ type Tag = { key: string; value: string };
23
23
 
24
24
  @customElement('dees-chips')
25
25
  export class DeesChips extends DeesElement {
@@ -29,7 +29,12 @@ export class DeesChips extends DeesElement {
29
29
  public selectionMode: 'none' | 'single' | 'multiple' = 'single';
30
30
 
31
31
  @property({
32
- type: Array
32
+ type: Boolean,
33
+ })
34
+ public chipsAreRemovable: boolean = false;
35
+
36
+ @property({
37
+ type: Array,
33
38
  })
34
39
  public selectableChips: Tag[] = [];
35
40
 
@@ -37,10 +42,9 @@ export class DeesChips extends DeesElement {
37
42
  public selectedChip: Tag = null;
38
43
 
39
44
  @property({
40
- type: Array
45
+ type: Array,
41
46
  })
42
47
  public selectedChips: Tag[] = [];
43
-
44
48
 
45
49
  constructor() {
46
50
  super();
@@ -49,7 +53,6 @@ export class DeesChips extends DeesElement {
49
53
  public static styles = [
50
54
  cssManager.defaultStyles,
51
55
  css`
52
-
53
56
  :host {
54
57
  display: block;
55
58
  box-sizing: border-box;
@@ -73,20 +76,20 @@ export class DeesChips extends DeesElement {
73
76
  margin-bottom: 4px;
74
77
  position: relative;
75
78
  overflow: hidden;
76
- box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
79
+ box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
77
80
  }
78
81
 
79
82
  .chip:hover {
80
83
  background: #666666;
81
- cursor: pointer;
84
+ cursor: pointer;
82
85
  }
83
86
 
84
87
  .chip.selected {
85
- background: #00A3FF;
88
+ background: #00a3ff;
86
89
  }
87
90
 
88
91
  .chipKey {
89
- background: rgba(0,0,0,0.3);
92
+ background: rgba(0, 0, 0, 0.3);
90
93
  height: 100%;
91
94
  display: inline-block;
92
95
  margin-left: -8px;
@@ -94,18 +97,44 @@ export class DeesChips extends DeesElement {
94
97
  padding-right: 8px;
95
98
  margin-right: 8px;
96
99
  }
97
-
100
+
101
+ dees-icon {
102
+ padding: 0px 6px 0px 4px;
103
+ margin-left: 4px;
104
+ margin-right: -8px;
105
+ background: rgba(0, 0, 0, 0.3);
106
+ }
107
+
108
+ dees-icon:hover {
109
+ background: #e4002b;
110
+ }
98
111
  `,
99
112
  ];
100
113
 
101
114
  public render(): TemplateResult {
102
115
  return html`
103
116
  <div class="mainbox">
104
- ${this.selectableChips.map(chip => html`
105
- <div @click=${() => this.selectChip(chip)} class="chip ${this.isSelected(chip) ? 'selected' : ''}">
106
- ${chip.key ? html`<div class="chipKey">${chip.key}</div>` : html``}${chip.value}
107
- </div>
108
- `)}
117
+ ${this.selectableChips.map(
118
+ (chip) => html`
119
+ <div
120
+ @click=${() => this.selectChip(chip)}
121
+ class="chip ${this.isSelected(chip) ? 'selected' : ''}"
122
+ >
123
+ ${chip.key ? html`<div class="chipKey">${chip.key}</div>` : html``} ${chip.value}
124
+ ${this.chipsAreRemovable
125
+ ? html`
126
+ <dees-icon
127
+ @click=${(event: Event) => {
128
+ event.stopPropagation(); // prevent the selectChip event from being triggered
129
+ this.removeChip(chip);
130
+ }}
131
+ .iconFA=${'xmark'}
132
+ ></dees-icon>
133
+ `
134
+ : html``}
135
+ </div>
136
+ `
137
+ )}
109
138
  </div>
110
139
  `;
111
140
  }
@@ -121,7 +150,7 @@ export class DeesChips extends DeesElement {
121
150
  if (this.selectionMode === 'single') {
122
151
  return this.selectedChip?.key === chip.key;
123
152
  } else {
124
- return this.selectedChips.some(selected => selected.key === chip.key);
153
+ return this.selectedChips.some((selected) => selected.key === chip.key);
125
154
  }
126
155
  }
127
156
 
@@ -138,9 +167,9 @@ export class DeesChips extends DeesElement {
138
167
  this.selectedChip = chip;
139
168
  this.selectedChips = [chip];
140
169
  }
141
- } else if(this.selectionMode === 'multiple') {
170
+ } else if (this.selectionMode === 'multiple') {
142
171
  if (this.isSelected(chip)) {
143
- this.selectedChips = this.selectedChips.filter(selected => selected.key !== chip.key);
172
+ this.selectedChips = this.selectedChips.filter((selected) => selected.key !== chip.key);
144
173
  } else {
145
174
  this.selectedChips = [...this.selectedChips, chip];
146
175
  }
@@ -148,4 +177,20 @@ export class DeesChips extends DeesElement {
148
177
  }
149
178
  console.log(this.selectedChips);
150
179
  }
180
+
181
+ public removeChip(chipToRemove: Tag): void {
182
+ // Remove the chip from selectableChips
183
+ this.selectableChips = this.selectableChips.filter((chip) => chip.key !== chipToRemove.key);
184
+
185
+ // Remove the chip from selectedChips if present
186
+ this.selectedChips = this.selectedChips.filter((chip) => chip.key !== chipToRemove.key);
187
+
188
+ // If the removed chip was the selectedChip, set selectedChip to null
189
+ if (this.selectedChip && this.selectedChip.key === chipToRemove.key) {
190
+ this.selectedChip = null;
191
+ }
192
+
193
+ // Trigger an update to re-render the component
194
+ this.requestUpdate();
195
+ }
151
196
  }