@nectary/components 0.41.1 → 0.42.0
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/accordion/index.js +0 -16
- package/accordion/types.d.ts +9 -1
- package/accordion-item/index.js +0 -24
- package/accordion-item/types.d.ts +18 -3
- package/action-menu/index.js +1 -45
- package/action-menu-option/index.js +0 -18
- package/alert/index.js +0 -10
- package/alert/types.d.ts +6 -0
- package/avatar/index.js +57 -20
- package/avatar/types.d.ts +25 -7
- package/avatar/utils.d.ts +10 -2
- package/avatar/utils.js +23 -2
- package/badge/index.d.ts +11 -0
- package/badge/index.js +140 -0
- package/badge/types.d.ts +38 -0
- package/badge/utils.d.ts +11 -0
- package/badge/utils.js +23 -0
- package/button/index.js +0 -18
- package/card/index.js +0 -16
- package/card/types.d.ts +15 -3
- package/card-container/index.js +0 -1
- package/chat/index.js +0 -1
- package/chat-block/index.js +0 -19
- package/chat-block/types.d.ts +16 -4
- package/chat-bubble/index.js +0 -9
- package/chat-bubble/types.d.ts +6 -0
- package/checkbox/index.js +0 -23
- package/chip/index.js +16 -25
- package/chip/utils.d.ts +3 -0
- package/chip/utils.js +11 -0
- package/color-menu/index.js +8 -86
- package/color-menu/utils.js +0 -4
- package/color-swatch/index.js +17 -17
- package/color-swatch/types.d.ts +2 -2
- package/color-swatch/utils.d.ts +3 -0
- package/color-swatch/utils.js +11 -0
- package/date-picker/index.js +1 -50
- package/date-picker/utils.js +0 -7
- package/dialog/index.js +1 -17
- package/field/index.js +0 -19
- package/file-drop/index.js +0 -40
- package/file-drop/utils.js +0 -6
- package/file-picker/index.js +0 -17
- package/file-picker/utils.js +0 -1
- package/file-status/index.js +0 -12
- package/grid/index.js +0 -1
- package/grid-item/index.js +0 -9
- package/help-tooltip/index.js +0 -14
- package/horizontal-stepper/index.js +0 -12
- package/horizontal-stepper-item/index.js +0 -14
- package/icon-button/index.js +0 -15
- package/icons/create-icon-class.js +0 -2
- package/icons-branded/create-icon-class.js +0 -8
- package/icons-channel/create-icon-class.js +0 -6
- package/illustrations/create-illustration-class.js +0 -11
- package/inline-alert/index.js +0 -14
- package/input/index.js +0 -37
- package/link/index.js +0 -25
- package/list/index.js +0 -2
- package/list-item/index.js +0 -2
- package/logo/create-logo-class.js +0 -9
- package/package.json +1 -1
- package/pagination/index.js +0 -31
- package/pop/index.js +26 -68
- package/pop/utils.js +0 -1
- package/popover/index.js +0 -33
- package/popover/utils.js +0 -2
- package/progress/index.js +0 -10
- package/radio/index.js +0 -30
- package/radio-option/index.js +0 -20
- package/segment/index.js +0 -15
- package/segment-collapse/index.js +0 -13
- package/segmented-control/index.js +0 -12
- package/segmented-control-option/index.js +0 -18
- package/segmented-icon-control/index.js +0 -16
- package/segmented-icon-control-option/index.js +0 -14
- package/select-button/index.js +0 -23
- package/select-menu/index.js +1 -63
- package/select-menu-option/index.js +0 -14
- package/spinner/index.js +0 -4
- package/stop-events/index.js +0 -5
- package/table/index.js +0 -2
- package/table-body/index.js +0 -2
- package/table-cell/index.js +0 -4
- package/table-head/index.js +0 -2
- package/table-head-cell/index.js +0 -11
- package/table-row/index.js +0 -6
- package/tabs/index.js +0 -30
- package/tabs-option/index.js +0 -19
- package/tag/index.js +18 -21
- package/tag/utils.d.ts +3 -0
- package/tag/utils.js +11 -0
- package/text/index.js +1 -12
- package/textarea/index.js +0 -40
- package/{utils → theme}/colors.d.ts +0 -1
- package/{utils → theme}/colors.js +0 -1
- package/theme.css +13 -209
- package/tile-control/index.js +0 -24
- package/tile-control-option/index.js +0 -18
- package/time-picker/index.js +2 -51
- package/time-picker/utils.js +0 -18
- package/title/index.js +1 -12
- package/title/utils.js +0 -5
- package/toast/index.js +0 -19
- package/toast-manager/index.js +0 -27
- package/toggle/index.js +0 -23
- package/tooltip/index.js +0 -27
- package/tooltip/utils.js +0 -4
- package/utils/animation.js +0 -20
- package/utils/context.js +0 -6
- package/utils/index.d.ts +1 -0
- package/utils/index.js +11 -52
- package/vertical-stepper/index.js +0 -12
- package/vertical-stepper-item/index.js +0 -14
- package/avatar-badge/index.d.ts +0 -11
- package/avatar-badge/index.js +0 -38
- package/avatar-badge/types.d.ts +0 -8
- package/avatar-status/index.d.ts +0 -11
- package/avatar-status/index.js +0 -37
- package/avatar-status/types.d.ts +0 -9
- package/avatar-status/types.js +0 -1
- package/avatar-status/utils.d.ts +0 -5
- package/avatar-status/utils.js +0 -6
- package/chat-avatar/index.d.ts +0 -12
- package/chat-avatar/index.js +0 -52
- package/chat-avatar/types.d.ts +0 -12
- package/chat-avatar/types.js +0 -1
- /package/{avatar-badge → badge}/types.js +0 -0
package/color-menu/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import '../color-swatch';
|
|
2
2
|
import '../tooltip';
|
|
3
3
|
import '../icons/check';
|
|
4
|
+
import { getSwatchColorFg } from '../color-swatch/utils';
|
|
5
|
+
import { lightColorNames, darkColorNames, vibrantColorNames } from '../theme/colors';
|
|
4
6
|
import { attrValueToPixels, defineCustomElement, getAttribute, getBooleanAttribute, getCsvSet, getIntegerAttribute, getReactEventHandler, getRect, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute, updateIntegerAttribute } from '../utils';
|
|
5
|
-
import { lightColorNames, darkColorNames, vibrantColorNames, NO_COLOR } from '../utils/colors';
|
|
6
7
|
import { dispatchContextConnectEvent, dispatchContextDisconnectEvent } from '../utils/context';
|
|
7
8
|
const optionTemplateHTML = '<div class="option" role="option"><sinch-tooltip inverted class="tooltip"><div class="swatch-wrapper"><sinch-color-swatch class="swatch"></sinch-color-swatch><sinch-icon-check class="check"></sinch-icon-check></div></sinch-tooltip></div>';
|
|
8
9
|
const templateHTML = '<style>:host{display:block;outline:0}#listbox{display:flex;flex-direction:row;flex-wrap:wrap;padding:4px 10px;overflow-y:auto}#listbox:empty{display:none}.option{padding:12px 6px;--sinch-color-icon:var(--sinch-color-stormy-500)}.swatch-wrapper{position:relative;cursor:pointer;width:32px;height:32px}.swatch-wrapper::after{content:"";position:absolute;width:34px;height:34px;inset:-3px;border:2px solid transparent;border-radius:50%;pointer-events:none}.option[data-selected]:not([data-checked]) .swatch-wrapper::after{border-color:var(--sinch-color-border-focus)}.check{display:none;position:absolute;left:4px;top:4px;pointer-events:none;--sinch-size-icon:24px}.option[data-checked] .check{display:block}</style><div id="listbox" role="presentation"></div>';
|
|
@@ -19,14 +20,12 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
19
20
|
#controller = null;
|
|
20
21
|
#prevColorsValue = '';
|
|
21
22
|
#isConnected = false;
|
|
22
|
-
|
|
23
23
|
constructor() {
|
|
24
24
|
super();
|
|
25
25
|
const shadowRoot = this.attachShadow();
|
|
26
26
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
27
27
|
this.#$listbox = shadowRoot.querySelector('#listbox');
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
connectedCallback() {
|
|
31
30
|
this.#controller = new AbortController();
|
|
32
31
|
const {
|
|
@@ -56,7 +55,6 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
56
55
|
dispatchContextConnectEvent(this, 'keydown');
|
|
57
56
|
requestAnimationFrame(this.#onMount);
|
|
58
57
|
}
|
|
59
|
-
|
|
60
58
|
disconnectedCallback() {
|
|
61
59
|
this.#isConnected = false;
|
|
62
60
|
this.#prevColorsValue = null;
|
|
@@ -64,114 +62,88 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
64
62
|
dispatchContextDisconnectEvent(this, 'keydown');
|
|
65
63
|
this.#controller.abort();
|
|
66
64
|
}
|
|
67
|
-
|
|
68
65
|
static get observedAttributes() {
|
|
69
66
|
return ['value', 'rows', 'cols', 'colors'];
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
set value(value) {
|
|
73
69
|
updateAttribute(this, 'value', value);
|
|
74
70
|
}
|
|
75
|
-
|
|
76
71
|
get value() {
|
|
77
|
-
return getAttribute(this, 'value',
|
|
72
|
+
return getAttribute(this, 'value', '');
|
|
78
73
|
}
|
|
79
|
-
|
|
80
74
|
set colors(value) {
|
|
81
75
|
updateAttribute(this, 'colors', value);
|
|
82
76
|
}
|
|
83
|
-
|
|
84
77
|
get colors() {
|
|
85
78
|
return getAttribute(this, 'colors');
|
|
86
79
|
}
|
|
87
|
-
|
|
88
80
|
set rows(value) {
|
|
89
81
|
updateIntegerAttribute(this, 'rows', value);
|
|
90
82
|
}
|
|
91
|
-
|
|
92
83
|
get rows() {
|
|
93
84
|
return getIntegerAttribute(this, 'rows', null);
|
|
94
85
|
}
|
|
95
|
-
|
|
96
86
|
set cols(value) {
|
|
97
87
|
updateIntegerAttribute(this, 'cols', value);
|
|
98
88
|
}
|
|
99
|
-
|
|
100
89
|
get cols() {
|
|
101
90
|
return getIntegerAttribute(this, 'cols', null);
|
|
102
91
|
}
|
|
103
|
-
|
|
104
92
|
get focusable() {
|
|
105
93
|
return true;
|
|
106
94
|
}
|
|
107
|
-
|
|
108
95
|
nthItemRect(index) {
|
|
109
96
|
const $item = this.#$listbox.children[index];
|
|
110
|
-
|
|
111
97
|
if ($item != null) {
|
|
112
98
|
return getRect($item);
|
|
113
99
|
}
|
|
114
|
-
|
|
115
100
|
return null;
|
|
116
101
|
}
|
|
117
|
-
|
|
118
102
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
119
103
|
if (oldVal === newVal) {
|
|
120
104
|
return;
|
|
121
105
|
}
|
|
122
|
-
|
|
123
106
|
switch (name) {
|
|
124
107
|
case 'value':
|
|
125
108
|
{
|
|
126
109
|
if (this.#isConnected) {
|
|
127
110
|
this.#onValueChange();
|
|
128
111
|
}
|
|
129
|
-
|
|
130
112
|
break;
|
|
131
113
|
}
|
|
132
|
-
|
|
133
114
|
case 'colors':
|
|
134
115
|
{
|
|
135
116
|
if (this.#isConnected) {
|
|
136
117
|
this.#updateColors();
|
|
137
118
|
}
|
|
138
|
-
|
|
139
119
|
break;
|
|
140
120
|
}
|
|
141
|
-
|
|
142
121
|
case 'rows':
|
|
143
122
|
{
|
|
144
123
|
this.#updateRows();
|
|
145
124
|
break;
|
|
146
125
|
}
|
|
147
|
-
|
|
148
126
|
case 'cols':
|
|
149
127
|
{
|
|
150
128
|
if (this.#isConnected) {
|
|
151
129
|
this.#updateColumns();
|
|
152
130
|
}
|
|
153
|
-
|
|
154
131
|
break;
|
|
155
132
|
}
|
|
156
133
|
}
|
|
157
134
|
}
|
|
158
|
-
|
|
159
135
|
#updateColors() {
|
|
160
136
|
const colorsValue = this.colors;
|
|
161
|
-
|
|
162
137
|
if (colorsValue === this.#prevColorsValue) {
|
|
163
138
|
return;
|
|
164
139
|
}
|
|
165
|
-
|
|
166
140
|
this.#prevColorsValue = colorsValue;
|
|
167
141
|
const colorNames = getCsvSet(colorsValue ?? `${lightColorNames},${vibrantColorNames},${darkColorNames}`);
|
|
168
142
|
const fragment = document.createDocumentFragment();
|
|
169
|
-
|
|
170
143
|
for (const color of colorNames) {
|
|
171
|
-
if (color ===
|
|
144
|
+
if (color.length === 0) {
|
|
172
145
|
continue;
|
|
173
146
|
}
|
|
174
|
-
|
|
175
147
|
const optFrag = optionTemplate.content.cloneNode(true);
|
|
176
148
|
const $option = optFrag.querySelector('.option');
|
|
177
149
|
const $swatch = optFrag.querySelector('.swatch');
|
|
@@ -179,15 +151,15 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
179
151
|
updateAttribute($option, 'data-value', color);
|
|
180
152
|
updateAttribute($tooltip, 'text', color);
|
|
181
153
|
updateAttribute($swatch, 'name', color);
|
|
182
|
-
$option.style.setProperty('--sinch-color-icon',
|
|
154
|
+
$option.style.setProperty('--sinch-color-icon', getSwatchColorFg(color));
|
|
183
155
|
fragment.appendChild(optFrag);
|
|
184
156
|
}
|
|
185
|
-
|
|
186
157
|
this.#$listbox.replaceChildren(fragment);
|
|
158
|
+
|
|
187
159
|
this.#updateColumns();
|
|
160
|
+
|
|
188
161
|
this.#onValueChange();
|
|
189
162
|
}
|
|
190
|
-
|
|
191
163
|
#updateRows() {
|
|
192
164
|
const rowsValue = getAttribute(this, 'rows');
|
|
193
165
|
this.#$listbox.style.maxHeight = attrValueToPixels(rowsValue, {
|
|
@@ -195,7 +167,6 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
195
167
|
itemSizeMultiplier: ITEM_HEIGHT
|
|
196
168
|
});
|
|
197
169
|
}
|
|
198
|
-
|
|
199
170
|
#updateColumns() {
|
|
200
171
|
const colsValue = getAttribute(this, 'cols');
|
|
201
172
|
const numItems = this.#$listbox.children.length;
|
|
@@ -206,7 +177,6 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
206
177
|
itemSizeMultiplier: ITEM_WIDTH
|
|
207
178
|
});
|
|
208
179
|
}
|
|
209
|
-
|
|
210
180
|
#onMount = () => {
|
|
211
181
|
this.#updateColors();
|
|
212
182
|
this.#isConnected = true;
|
|
@@ -216,11 +186,9 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
216
186
|
};
|
|
217
187
|
#onListboxClick = e => {
|
|
218
188
|
const $elem = e.target;
|
|
219
|
-
|
|
220
189
|
if ($elem === this.#$listbox) {
|
|
221
190
|
return;
|
|
222
191
|
}
|
|
223
|
-
|
|
224
192
|
const $option = getParentOption($elem);
|
|
225
193
|
this.#dispatchChangeEvent($option);
|
|
226
194
|
this.#selectOption($option);
|
|
@@ -238,43 +206,36 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
238
206
|
#onListboxKeyDown = e => {
|
|
239
207
|
this.#handleKeydown(e);
|
|
240
208
|
};
|
|
241
|
-
|
|
242
209
|
#handleKeydown(e) {
|
|
243
210
|
switch (e.code) {
|
|
244
211
|
case 'Space':
|
|
245
212
|
case 'Enter':
|
|
246
213
|
{
|
|
247
214
|
const $option = this.#findSelectedOption();
|
|
248
|
-
|
|
249
215
|
if ($option !== null) {
|
|
250
216
|
e.preventDefault();
|
|
251
217
|
this.#dispatchChangeEvent($option);
|
|
252
218
|
}
|
|
253
|
-
|
|
254
219
|
break;
|
|
255
220
|
}
|
|
256
|
-
|
|
257
221
|
case 'ArrowLeft':
|
|
258
222
|
{
|
|
259
223
|
e.preventDefault();
|
|
260
224
|
this.#selectOption(this.#getPrevOption());
|
|
261
225
|
break;
|
|
262
226
|
}
|
|
263
|
-
|
|
264
227
|
case 'ArrowRight':
|
|
265
228
|
{
|
|
266
229
|
e.preventDefault();
|
|
267
230
|
this.#selectOption(this.#getNextOption());
|
|
268
231
|
break;
|
|
269
232
|
}
|
|
270
|
-
|
|
271
233
|
case 'ArrowDown':
|
|
272
234
|
{
|
|
273
235
|
e.preventDefault();
|
|
274
236
|
this.#selectOption(this.#getNextRowOption());
|
|
275
237
|
break;
|
|
276
238
|
}
|
|
277
|
-
|
|
278
239
|
case 'ArrowUp':
|
|
279
240
|
{
|
|
280
241
|
e.preventDefault();
|
|
@@ -283,104 +244,79 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
283
244
|
}
|
|
284
245
|
}
|
|
285
246
|
}
|
|
286
|
-
|
|
287
247
|
#onValueChange() {
|
|
288
248
|
const value = this.value;
|
|
289
|
-
|
|
290
249
|
for (const $option of this.#getOptionElements()) {
|
|
291
250
|
const isChecked = value === getAttribute($option, 'data-value', '');
|
|
292
251
|
updateBooleanAttribute($option, 'data-checked', isChecked);
|
|
293
252
|
updateExplicitBooleanAttribute($option, 'aria-selected', isChecked);
|
|
294
253
|
}
|
|
295
254
|
}
|
|
296
|
-
|
|
297
255
|
#getFirstOption() {
|
|
298
256
|
const $options = this.#getOptionElements();
|
|
299
257
|
return $options[0] ?? null;
|
|
300
258
|
}
|
|
301
|
-
|
|
302
259
|
#getLastOption() {
|
|
303
260
|
const $options = this.#getOptionElements();
|
|
304
261
|
return $options[$options.length - 1] ?? null;
|
|
305
262
|
}
|
|
306
|
-
|
|
307
263
|
#getNextOption() {
|
|
308
264
|
const index = this.#getSelectedOptionIndex();
|
|
309
|
-
|
|
310
265
|
if (index !== null) {
|
|
311
266
|
const $options = this.#getOptionElements();
|
|
312
267
|
return $options[(1 + index) % $options.length];
|
|
313
268
|
}
|
|
314
|
-
|
|
315
269
|
return this.#getFirstOption();
|
|
316
270
|
}
|
|
317
|
-
|
|
318
271
|
#getPrevOption() {
|
|
319
272
|
const index = this.#getSelectedOptionIndex();
|
|
320
|
-
|
|
321
273
|
if (index !== null) {
|
|
322
274
|
const $options = this.#getOptionElements();
|
|
323
275
|
return $options[(index - 1 + $options.length) % $options.length];
|
|
324
276
|
}
|
|
325
|
-
|
|
326
277
|
return this.#getLastOption();
|
|
327
278
|
}
|
|
328
|
-
|
|
329
279
|
#getNextRowOption() {
|
|
330
280
|
const selectedIndex = this.#getSelectedOptionIndex();
|
|
331
|
-
|
|
332
281
|
if (selectedIndex !== null) {
|
|
333
282
|
const $options = this.#getOptionElements();
|
|
334
283
|
const numCols = Math.min(this.cols ?? NUM_COLS_DEFAULT, $options.length);
|
|
335
284
|
const numColsInLastRow = $options.length % numCols;
|
|
336
|
-
|
|
337
285
|
if (numColsInLastRow > 0) {
|
|
338
286
|
if (selectedIndex < $options.length - numCols) {
|
|
339
287
|
return $options[selectedIndex + numCols];
|
|
340
288
|
}
|
|
341
|
-
|
|
342
289
|
if (numColsInLastRow > 0 && selectedIndex < $options.length - numColsInLastRow) {
|
|
343
290
|
return $options[$options.length - 1];
|
|
344
291
|
}
|
|
345
|
-
|
|
346
292
|
return $options[selectedIndex + numColsInLastRow - $options.length];
|
|
347
293
|
}
|
|
348
|
-
|
|
349
294
|
return $options[(selectedIndex + numCols) % $options.length];
|
|
350
295
|
}
|
|
351
|
-
|
|
352
296
|
return this.#getFirstOption();
|
|
353
297
|
}
|
|
354
|
-
|
|
355
298
|
#getPrevRowOption() {
|
|
356
299
|
const selectedIndex = this.#getSelectedOptionIndex();
|
|
357
|
-
|
|
358
300
|
if (selectedIndex !== null) {
|
|
359
301
|
const $options = this.#getOptionElements();
|
|
360
302
|
const numCols = Math.min(this.cols ?? NUM_COLS_DEFAULT, $options.length);
|
|
361
303
|
const numColsInLastRow = $options.length % numCols;
|
|
362
|
-
|
|
363
304
|
if (selectedIndex < numColsInLastRow) {
|
|
364
305
|
return $options[(selectedIndex - numColsInLastRow + $options.length) % $options.length];
|
|
365
306
|
}
|
|
366
|
-
|
|
367
307
|
if (selectedIndex < numCols) {
|
|
368
308
|
return $options[(selectedIndex - numCols - numColsInLastRow + $options.length) % $options.length];
|
|
369
309
|
}
|
|
370
|
-
|
|
371
310
|
return $options[(selectedIndex - numCols + $options.length) % $options.length];
|
|
372
311
|
}
|
|
373
|
-
|
|
374
312
|
return this.#getFirstOption();
|
|
375
313
|
}
|
|
376
|
-
|
|
377
314
|
#selectOption($option) {
|
|
378
315
|
const hasRows = this.hasAttribute('rows');
|
|
379
|
-
|
|
380
316
|
for (const $op of this.#getOptionElements()) {
|
|
381
317
|
const isSelected = $op === $option;
|
|
382
|
-
updateBooleanAttribute($op, 'data-selected', isSelected);
|
|
383
318
|
|
|
319
|
+
updateBooleanAttribute($op, 'data-selected', isSelected);
|
|
384
320
|
if (isSelected && hasRows) {
|
|
385
321
|
$op.scrollIntoView?.({
|
|
386
322
|
block: 'nearest'
|
|
@@ -388,62 +324,48 @@ defineCustomElement('sinch-color-menu', class extends NectaryElement {
|
|
|
388
324
|
}
|
|
389
325
|
}
|
|
390
326
|
}
|
|
391
|
-
|
|
392
327
|
#getOptionElements() {
|
|
393
328
|
return Array.from(this.#$listbox.children);
|
|
394
329
|
}
|
|
395
|
-
|
|
396
330
|
#getSelectedOptionIndex() {
|
|
397
331
|
const elements = this.#getOptionElements();
|
|
398
|
-
|
|
399
332
|
for (let i = 0; i < elements.length; i++) {
|
|
400
333
|
const el = elements[i];
|
|
401
|
-
|
|
402
334
|
if (getBooleanAttribute(el, 'data-selected')) {
|
|
403
335
|
return i;
|
|
404
336
|
}
|
|
405
337
|
}
|
|
406
|
-
|
|
407
338
|
return null;
|
|
408
339
|
}
|
|
409
|
-
|
|
410
340
|
#findSelectedOption() {
|
|
411
341
|
const elements = this.#getOptionElements();
|
|
412
|
-
|
|
413
342
|
for (const el of elements) {
|
|
414
343
|
if (getBooleanAttribute(el, 'data-selected')) {
|
|
415
344
|
return el;
|
|
416
345
|
}
|
|
417
346
|
}
|
|
418
|
-
|
|
419
347
|
return null;
|
|
420
348
|
}
|
|
421
|
-
|
|
422
349
|
#findCheckedOption() {
|
|
423
350
|
const elements = this.#getOptionElements();
|
|
424
351
|
const value = this.value;
|
|
425
|
-
|
|
426
352
|
for (const $el of elements) {
|
|
427
353
|
if (getAttribute($el, 'data-value') === value) {
|
|
428
354
|
return $el;
|
|
429
355
|
}
|
|
430
356
|
}
|
|
431
|
-
|
|
432
357
|
return null;
|
|
433
358
|
}
|
|
434
|
-
|
|
435
359
|
#dispatchChangeEvent($opt) {
|
|
436
360
|
if ($opt === null) {
|
|
437
361
|
return;
|
|
438
362
|
}
|
|
439
|
-
|
|
440
363
|
if ($opt !== null) {
|
|
441
364
|
this.dispatchEvent(new CustomEvent('-change', {
|
|
442
365
|
detail: getAttribute($opt, 'data-value')
|
|
443
366
|
}));
|
|
444
367
|
}
|
|
445
368
|
}
|
|
446
|
-
|
|
447
369
|
#onChangeReactHandler = e => {
|
|
448
370
|
getReactEventHandler(this, 'on-change')?.(e);
|
|
449
371
|
};
|
package/color-menu/utils.js
CHANGED
package/color-swatch/index.js
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
import '../icons/cancel';
|
|
2
2
|
import '../text';
|
|
3
3
|
import { defineCustomElement, NectaryElement, setClass, getAttribute, updateAttribute } from '../utils';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{width:var(--sinch-size-icon,32px);height:var(--sinch-size-icon,32px);border-radius:50%}#wrapper.no-color{background:linear-gradient(45deg,var(--sinch-color-swatch-color-light-orange-bg),var(--sinch-color-swatch-color-light-yellow-bg),var(--sinch-color-swatch-color-light-green-bg),var(--sinch-color-swatch-color-light-blue-bg),var(--sinch-color-swatch-color-light-violet-bg))}</style><div id="wrapper"></div>';
|
|
5
|
+
import { assertSwatchColor, getSwatchColorBg } from './utils';
|
|
6
6
|
const template = document.createElement('template');
|
|
7
7
|
template.innerHTML = templateHTML;
|
|
8
8
|
defineCustomElement('sinch-color-swatch', class extends NectaryElement {
|
|
9
9
|
#$wrapper;
|
|
10
|
-
|
|
10
|
+
#isConnected = false;
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
13
13
|
const shadowRoot = this.attachShadow();
|
|
14
14
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
15
15
|
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
connectedCallback() {
|
|
18
|
+
this.#isConnected = true;
|
|
19
19
|
this.#updateColor();
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
disconnectedCallback() {
|
|
22
|
+
this.#isConnected = false;
|
|
23
|
+
}
|
|
22
24
|
get name() {
|
|
23
|
-
return getAttribute(this, 'name'
|
|
25
|
+
return getAttribute(this, 'name');
|
|
24
26
|
}
|
|
25
|
-
|
|
26
27
|
set name(value) {
|
|
27
28
|
updateAttribute(this, 'name', value);
|
|
28
29
|
}
|
|
29
|
-
|
|
30
30
|
static get observedAttributes() {
|
|
31
31
|
return ['name'];
|
|
32
32
|
}
|
|
33
|
-
|
|
34
33
|
attributeChangedCallback(name, oldValue, newVal) {
|
|
35
34
|
if (oldValue === newVal) {
|
|
36
35
|
return;
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
switch (name) {
|
|
40
38
|
case 'name':
|
|
41
39
|
{
|
|
@@ -44,17 +42,19 @@ defineCustomElement('sinch-color-swatch', class extends NectaryElement {
|
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
|
|
48
45
|
#updateColor() {
|
|
46
|
+
if (!this.#isConnected) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
49
|
const colorName = this.name;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (colorName !== null && colorName.length > 0) {
|
|
51
|
+
assertSwatchColor(this, colorName);
|
|
52
|
+
const bg = getSwatchColorBg(colorName);
|
|
53
|
+
this.#$wrapper.style.setProperty('background-color', bg);
|
|
54
|
+
setClass(this.#$wrapper, 'no-color', false);
|
|
53
55
|
} else {
|
|
54
56
|
this.#$wrapper.style.removeProperty('background-color');
|
|
57
|
+
setClass(this.#$wrapper, 'no-color', true);
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
setClass(this.#$wrapper, 'no-color', colorName === NO_COLOR);
|
|
58
59
|
}
|
|
59
|
-
|
|
60
60
|
});
|
package/color-swatch/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { TSinchElementReact } from '../types';
|
|
2
2
|
export declare type TSinchColorSwatchElement = HTMLElement & {
|
|
3
3
|
/** Color name */
|
|
4
|
-
name: string;
|
|
4
|
+
name: string | null;
|
|
5
5
|
/** Color name */
|
|
6
6
|
setAttribute(name: 'name', value: string): void;
|
|
7
7
|
};
|
|
8
8
|
export declare type TSinchColorSwatchReact = TSinchElementReact<TSinchColorSwatchElement> & {
|
|
9
9
|
/** Color name */
|
|
10
|
-
name
|
|
10
|
+
name?: string;
|
|
11
11
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getSwatchColorBg = id => {
|
|
2
|
+
return `var(--sinch-color-swatch-color-${id}-bg)`;
|
|
3
|
+
};
|
|
4
|
+
export const getSwatchColorFg = id => {
|
|
5
|
+
return `var(--sinch-color-swatch-color-${id}-fg)`;
|
|
6
|
+
};
|
|
7
|
+
export const assertSwatchColor = (root, id) => {
|
|
8
|
+
if (id === null || window.getComputedStyle(root).getPropertyValue(`--sinch-color-swatch-color-${id}-bg`).length === 0) {
|
|
9
|
+
throw new Error(`Invalid sinch-color-swatch color name: ${id}`);
|
|
10
|
+
}
|
|
11
|
+
};
|