@nectary/components 0.8.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.
Files changed (132) hide show
  1. package/accordion/index.d.ts +21 -0
  2. package/accordion/index.js +118 -0
  3. package/accordion-item/index.d.ts +33 -0
  4. package/accordion-item/index.js +139 -0
  5. package/alert/index.d.ts +26 -0
  6. package/alert/index.js +91 -0
  7. package/alert-button/index.d.ts +23 -0
  8. package/alert-button/index.js +62 -0
  9. package/alert-close/index.d.ts +22 -0
  10. package/alert-close/index.js +41 -0
  11. package/button/index.d.ts +32 -0
  12. package/button/index.js +100 -0
  13. package/checkbox/index.d.ts +29 -0
  14. package/checkbox/index.js +134 -0
  15. package/help-tooltip/index.d.ts +15 -0
  16. package/help-tooltip/index.js +80 -0
  17. package/icon/cancel/index.d.ts +11 -0
  18. package/icon/cancel/index.js +4 -0
  19. package/icon/close/index.d.ts +11 -0
  20. package/icon/close/index.js +4 -0
  21. package/icon/create-icon-class.d.ts +308 -0
  22. package/icon/create-icon-class.js +53 -0
  23. package/icon/east/index.d.ts +11 -0
  24. package/icon/east/index.js +4 -0
  25. package/icon/help-outline/index.d.ts +11 -0
  26. package/icon/help-outline/index.js +4 -0
  27. package/icon/more-horiz/index.d.ts +11 -0
  28. package/icon/more-horiz/index.js +4 -0
  29. package/icon/more-vert/index.d.ts +11 -0
  30. package/icon/more-vert/index.js +4 -0
  31. package/icon/north/index.d.ts +11 -0
  32. package/icon/north/index.js +4 -0
  33. package/icon/north-east/index.d.ts +11 -0
  34. package/icon/north-east/index.js +4 -0
  35. package/icon/north-west/index.d.ts +11 -0
  36. package/icon/north-west/index.js +4 -0
  37. package/icon/open-in-new/index.d.ts +11 -0
  38. package/icon/open-in-new/index.js +4 -0
  39. package/icon/south/index.d.ts +11 -0
  40. package/icon/south/index.js +4 -0
  41. package/icon/south-east/index.d.ts +11 -0
  42. package/icon/south-east/index.js +4 -0
  43. package/icon/south-west/index.d.ts +11 -0
  44. package/icon/south-west/index.js +4 -0
  45. package/icon/types.d.ts +7 -0
  46. package/icon/types.js +1 -0
  47. package/icon/west/index.d.ts +11 -0
  48. package/icon/west/index.js +4 -0
  49. package/icon-branded/barchart-down/index.d.ts +11 -0
  50. package/icon-branded/barchart-down/index.js +4 -0
  51. package/icon-branded/barchart-up/index.d.ts +11 -0
  52. package/icon-branded/barchart-up/index.js +4 -0
  53. package/icon-branded/campaigns/index.d.ts +11 -0
  54. package/icon-branded/campaigns/index.js +4 -0
  55. package/icon-branded/chatbot/index.d.ts +11 -0
  56. package/icon-branded/chatbot/index.js +4 -0
  57. package/icon-branded/contact/index.d.ts +11 -0
  58. package/icon-branded/contact/index.js +4 -0
  59. package/icon-branded/create-icon-class.d.ts +309 -0
  60. package/icon-branded/create-icon-class.js +61 -0
  61. package/icon-branded/home/index.d.ts +11 -0
  62. package/icon-branded/home/index.js +4 -0
  63. package/icon-branded/multiple-channels/index.d.ts +11 -0
  64. package/icon-branded/multiple-channels/index.js +4 -0
  65. package/icon-branded/rocket/index.d.ts +11 -0
  66. package/icon-branded/rocket/index.js +4 -0
  67. package/icon-branded/settings/index.d.ts +11 -0
  68. package/icon-branded/settings/index.js +4 -0
  69. package/icon-branded/types.d.ts +9 -0
  70. package/icon-branded/types.js +1 -0
  71. package/icon-branded/user/index.d.ts +11 -0
  72. package/icon-branded/user/index.js +4 -0
  73. package/icon-branded/users/index.d.ts +11 -0
  74. package/icon-branded/users/index.js +4 -0
  75. package/index.d.ts +56 -0
  76. package/index.js +56 -0
  77. package/input/index.d.ts +35 -0
  78. package/input/index.js +203 -0
  79. package/link/index.d.ts +30 -0
  80. package/link/index.js +118 -0
  81. package/logo/create-logo-class.d.ts +309 -0
  82. package/logo/create-logo-class.js +63 -0
  83. package/logo/sinch-icon/index.d.ts +11 -0
  84. package/logo/sinch-icon/index.js +4 -0
  85. package/logo/sinch-icon-wordmark/index.d.ts +11 -0
  86. package/logo/sinch-icon-wordmark/index.js +4 -0
  87. package/logo/types.d.ts +9 -0
  88. package/logo/types.js +1 -0
  89. package/package.json +34 -0
  90. package/radio/index.d.ts +19 -0
  91. package/radio/index.js +185 -0
  92. package/radio-option/index.d.ts +28 -0
  93. package/radio-option/index.js +134 -0
  94. package/readme.md +172 -0
  95. package/select/index.d.ts +37 -0
  96. package/select/index.js +492 -0
  97. package/select-option/index.d.ts +27 -0
  98. package/select-option/index.js +107 -0
  99. package/spinner/index.d.ts +21 -0
  100. package/spinner/index.js +23 -0
  101. package/table/index.d.ts +13 -0
  102. package/table/index.js +18 -0
  103. package/table-body/index.d.ts +13 -0
  104. package/table-body/index.js +18 -0
  105. package/table-cell/index.d.ts +20 -0
  106. package/table-cell/index.js +27 -0
  107. package/table-head/index.d.ts +13 -0
  108. package/table-head/index.js +18 -0
  109. package/table-head-cell/index.d.ts +24 -0
  110. package/table-head-cell/index.js +74 -0
  111. package/table-head-sort/index.d.ts +25 -0
  112. package/table-head-sort/index.js +92 -0
  113. package/table-row/index.d.ts +17 -0
  114. package/table-row/index.js +26 -0
  115. package/tabs/index.d.ts +19 -0
  116. package/tabs/index.js +181 -0
  117. package/tabs-option/index.d.ts +28 -0
  118. package/tabs-option/index.js +129 -0
  119. package/tag/index.d.ts +27 -0
  120. package/tag/index.js +79 -0
  121. package/tag-close/index.d.ts +24 -0
  122. package/tag-close/index.js +70 -0
  123. package/textarea/index.d.ts +35 -0
  124. package/textarea/index.js +201 -0
  125. package/theme.css +112 -0
  126. package/toggle/index.d.ts +31 -0
  127. package/toggle/index.js +144 -0
  128. package/tooltip/index.d.ts +26 -0
  129. package/tooltip/index.js +68 -0
  130. package/types.d.ts +3 -0
  131. package/utils.d.ts +31 -0
  132. package/utils.js +146 -0
@@ -0,0 +1,492 @@
1
+ import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
+
4
+ var _$button, _$buttonContent, _$label, _$optionalText, _$additionalText, _$invalidText, _$selectSlot, _$listbox, _onButtonClick, _onListboxClick, _onListboxKeyUp, _onListboxKeyDown, _onSlotChange, _onListboxBlur;
5
+
6
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
+
8
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
+
10
+ import { isSelectOptionElement } from '../select-option';
11
+ import { attrValueToPixels, defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, isAttrTrue, updateAttribute, updateBooleanAttribute, updateIntegerAttribute } from '../utils';
12
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;width:100%;box-sizing:border-box}#button{all:initial;display:flex;align-items:center;gap:8px;border:1px solid var(--sinch-color-stormy-200);border-radius:2px;box-sizing:border-box;width:100%;height:48px;margin:2px 0;padding:8px 12px;font:var(--sinch-font-body);color:var(--sinch-color-text-default);fill:var(--sinch-color-stormy-500)}#button>*{pointer-events:none}#button[data-unselected]{color:var(--sinch-color-text-muted)}#button:disabled{border-color:var(--sinch-color-snow-500);color:var(--sinch-color-stormy-100);fill:var(--sinch-color-stormy-100)}#button:focus{border-color:var(--sinch-color-stormy-300)}:host([invalidtext]:not([invalidtext=""])) #button:not(:disabled){border-color:var(--sinch-color-text-invalid)}#content{flex:1;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}#bottom,#top{display:flex;align-items:baseline}#top{height:24px}#bottom{height:20px}#additional,#invalid,#label,#optional{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#label{font:var(--sinch-font-title-4);color:var(--sinch-color-text-default)}#optional{flex:1;text-align:right;font:var(--sinch-font-small-text);color:var(--sinch-color-text-muted)}#additional{flex:1;text-align:right;font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-muted)}#invalid{font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-invalid)}::slotted(sinch-help-tooltip){align-self:center;margin:0 8px}:host([disabled]:not([disabled=false])) :is(#label,#additional,#optional,#invalid){color:var(--sinch-color-stormy-100)}:host([disabled]:not([disabled=false])) ::slotted(sinch-help-tooltip){fill:var(--sinch-color-stormy-100)}#listbox{position:absolute;left:0;top:0;padding-top:74px;width:100%;display:none;list-style:none;outline:0}#listbox>*{font:var(--sinch-font-body);background-color:var(--sinch-color-snow-100);border:1px solid var(--sinch-color-stormy-500);border-top-width:0;border-bottom-left-radius:2px;border-bottom-right-radius:2px;width:100%;box-sizing:border-box;box-shadow:1px 2px 4px rgb(0 0 0 / 15%);overflow-y:auto}#button[aria-expanded=true]{border-bottom-left-radius:0;border-bottom-right-radius:0}#button[aria-expanded=true]~#listbox{display:block}</style><div id="wrapper"><div id="top"><label id="label" for="button"></label><slot name="tooltip"></slot><span id="optional"></span></div><button id="button" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="label button"><span id="content"></span> <svg id="dropdown-icon" width="12" height="8"><path d="M1.41.59 6 5.17 10.59.59 12 2 6 8 0 2 1.41.59Z"/></svg></button><div id="bottom"><span id="invalid"></span> <span id="additional"></span></div><div id="listbox" tabindex="-1"><div><slot name="select"></slot></div></div></div>';
13
+ const ITEM_HEIGHT = 36;
14
+
15
+ const getEnabledOptionElements = $slot => {
16
+ return $slot.assignedElements().filter(opt => isSelectOptionElement(opt) && opt.disabled !== true);
17
+ };
18
+
19
+ const findSelectedOption = elements => {
20
+ return elements.find(el => el.selected) ?? null;
21
+ };
22
+
23
+ const getOptionWithValue = ($slot, value) => {
24
+ for (const $option of $slot.assignedElements()) {
25
+ if (isSelectOptionElement($option) && $option.disabled !== true && $option.value === value) {
26
+ return $option;
27
+ }
28
+ }
29
+
30
+ return null;
31
+ };
32
+
33
+ const getFirstOption = $slot => {
34
+ for (const $option of $slot.assignedElements()) {
35
+ if (isSelectOptionElement($option) && $option.disabled !== true) {
36
+ return $option;
37
+ }
38
+ }
39
+
40
+ return null;
41
+ };
42
+
43
+ const getLastOption = $slot => {
44
+ for (const $option of $slot.assignedElements().reverse()) {
45
+ if (isSelectOptionElement($option) && $option.disabled !== true) {
46
+ return $option;
47
+ }
48
+ }
49
+
50
+ return null;
51
+ };
52
+
53
+ const getNextOption = $slot => {
54
+ const $options = getEnabledOptionElements($slot);
55
+ const $selectedOption = findSelectedOption($options);
56
+ const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
57
+
58
+ if (currentIndex < 0) {
59
+ return getFirstOption($slot);
60
+ }
61
+
62
+ return $options[(currentIndex + 1) % $options.length];
63
+ };
64
+
65
+ const getPrevOption = $slot => {
66
+ const $options = getEnabledOptionElements($slot);
67
+ const $selectedOption = findSelectedOption($options);
68
+ const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
69
+
70
+ if (currentIndex < 0) {
71
+ return getLastOption($slot);
72
+ }
73
+
74
+ return $options[(currentIndex - 1 + $options.length) % $options.length];
75
+ };
76
+
77
+ const selectOption = ($slot, $option) => {
78
+ for (const $op of $slot.assignedElements()) {
79
+ if (isSelectOptionElement($op)) {
80
+ const isSelected = $op === $option;
81
+ $op.selected = isSelected;
82
+
83
+ if (isSelected) {
84
+ $op.scrollIntoView?.({
85
+ block: 'nearest'
86
+ });
87
+ }
88
+ }
89
+ }
90
+ };
91
+
92
+ const dispatchChangeEvent = ($root, $opt) => {
93
+ if ($opt != null && $root.value !== $opt.value) {
94
+ $root.dispatchEvent(new CustomEvent('change', {
95
+ detail: $opt.value,
96
+ bubbles: true
97
+ }));
98
+ }
99
+ };
100
+
101
+ const template = document.createElement('template');
102
+ template.innerHTML = templateHTML;
103
+ defineCustomElement('sinch-select', (_$button = new WeakMap(), _$buttonContent = new WeakMap(), _$label = new WeakMap(), _$optionalText = new WeakMap(), _$additionalText = new WeakMap(), _$invalidText = new WeakMap(), _$selectSlot = new WeakMap(), _$listbox = new WeakMap(), _onButtonClick = new WeakMap(), _onListboxClick = new WeakMap(), _onListboxKeyUp = new WeakMap(), _onListboxKeyDown = new WeakMap(), _onSlotChange = new WeakMap(), _onListboxBlur = new WeakMap(), class extends HTMLElement {
104
+ constructor() {
105
+ super();
106
+
107
+ _classPrivateFieldInitSpec(this, _$button, {
108
+ writable: true,
109
+ value: void 0
110
+ });
111
+
112
+ _classPrivateFieldInitSpec(this, _$buttonContent, {
113
+ writable: true,
114
+ value: void 0
115
+ });
116
+
117
+ _classPrivateFieldInitSpec(this, _$label, {
118
+ writable: true,
119
+ value: void 0
120
+ });
121
+
122
+ _classPrivateFieldInitSpec(this, _$optionalText, {
123
+ writable: true,
124
+ value: void 0
125
+ });
126
+
127
+ _classPrivateFieldInitSpec(this, _$additionalText, {
128
+ writable: true,
129
+ value: void 0
130
+ });
131
+
132
+ _classPrivateFieldInitSpec(this, _$invalidText, {
133
+ writable: true,
134
+ value: void 0
135
+ });
136
+
137
+ _classPrivateFieldInitSpec(this, _$selectSlot, {
138
+ writable: true,
139
+ value: void 0
140
+ });
141
+
142
+ _classPrivateFieldInitSpec(this, _$listbox, {
143
+ writable: true,
144
+ value: void 0
145
+ });
146
+
147
+ _classPrivateFieldInitSpec(this, _onButtonClick, {
148
+ writable: true,
149
+ value: e => {
150
+ e.stopPropagation();
151
+
152
+ if (_classPrivateFieldGet(this, _$button).getAttribute('aria-expanded') !== 'true') {
153
+ this.onExpand();
154
+ }
155
+ }
156
+ });
157
+
158
+ _classPrivateFieldInitSpec(this, _onListboxClick, {
159
+ writable: true,
160
+ value: e => {
161
+ e.stopPropagation();
162
+ const $elem = e.target;
163
+
164
+ if ($elem !== _classPrivateFieldGet(this, _$listbox) && isSelectOptionElement($elem) && $elem.disabled !== true) {
165
+ dispatchChangeEvent(this, $elem);
166
+ }
167
+
168
+ this.onCollapse();
169
+
170
+ _classPrivateFieldGet(this, _$button).focus();
171
+ }
172
+ });
173
+
174
+ _classPrivateFieldInitSpec(this, _onListboxKeyUp, {
175
+ writable: true,
176
+ value: e => {
177
+ switch (e.code) {
178
+ case 'Space':
179
+ case 'Enter':
180
+ {
181
+ e.preventDefault();
182
+ dispatchChangeEvent(this, findSelectedOption(getEnabledOptionElements(_classPrivateFieldGet(this, _$selectSlot))));
183
+ this.onCollapse();
184
+
185
+ _classPrivateFieldGet(this, _$button).focus();
186
+
187
+ break;
188
+ }
189
+ }
190
+ }
191
+ });
192
+
193
+ _classPrivateFieldInitSpec(this, _onListboxKeyDown, {
194
+ writable: true,
195
+ value: e => {
196
+ switch (e.code) {
197
+ case 'ArrowUp':
198
+ case 'ArrowLeft':
199
+ {
200
+ e.preventDefault();
201
+ selectOption(_classPrivateFieldGet(this, _$selectSlot), getPrevOption(_classPrivateFieldGet(this, _$selectSlot)));
202
+ break;
203
+ }
204
+
205
+ case 'ArrowDown':
206
+ case 'ArrowRight':
207
+ {
208
+ e.preventDefault();
209
+ selectOption(_classPrivateFieldGet(this, _$selectSlot), getNextOption(_classPrivateFieldGet(this, _$selectSlot)));
210
+ break;
211
+ }
212
+
213
+ case 'Escape':
214
+ {
215
+ e.preventDefault();
216
+ this.onCollapse();
217
+
218
+ _classPrivateFieldGet(this, _$button).focus();
219
+
220
+ break;
221
+ }
222
+ }
223
+ }
224
+ });
225
+
226
+ _classPrivateFieldInitSpec(this, _onSlotChange, {
227
+ writable: true,
228
+ value: () => {
229
+ this.onCollapse();
230
+ this.onValueChange(this.value);
231
+ }
232
+ });
233
+
234
+ _classPrivateFieldInitSpec(this, _onListboxBlur, {
235
+ writable: true,
236
+ value: e => {
237
+ e.stopPropagation();
238
+ this.onCollapse();
239
+ }
240
+ });
241
+
242
+ const shadowRoot = this.attachShadow({
243
+ mode: 'production' === 'development' ? 'open' : 'closed',
244
+ delegatesFocus: true
245
+ });
246
+ shadowRoot.appendChild(template.content.cloneNode(true));
247
+
248
+ _classPrivateFieldSet(this, _$button, shadowRoot.querySelector('#button'));
249
+
250
+ _classPrivateFieldSet(this, _$buttonContent, shadowRoot.querySelector('#content'));
251
+
252
+ _classPrivateFieldSet(this, _$listbox, shadowRoot.querySelector('#listbox'));
253
+
254
+ _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#label'));
255
+
256
+ _classPrivateFieldSet(this, _$optionalText, shadowRoot.querySelector('#optional'));
257
+
258
+ _classPrivateFieldSet(this, _$additionalText, shadowRoot.querySelector('#additional'));
259
+
260
+ _classPrivateFieldSet(this, _$invalidText, shadowRoot.querySelector('#invalid'));
261
+
262
+ _classPrivateFieldSet(this, _$selectSlot, shadowRoot.querySelector('slot[name="select"]'));
263
+ }
264
+
265
+ connectedCallback() {
266
+ this.setAttribute('role', 'listbox');
267
+
268
+ _classPrivateFieldGet(this, _$button).addEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
269
+
270
+ _classPrivateFieldGet(this, _$listbox).addEventListener('blur', _classPrivateFieldGet(this, _onListboxBlur));
271
+
272
+ _classPrivateFieldGet(this, _$listbox).addEventListener('click', _classPrivateFieldGet(this, _onListboxClick));
273
+
274
+ _classPrivateFieldGet(this, _$listbox).addEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
275
+
276
+ _classPrivateFieldGet(this, _$listbox).addEventListener('keypress', _classPrivateFieldGet(this, _onListboxKeyUp));
277
+
278
+ _classPrivateFieldGet(this, _$selectSlot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
279
+ }
280
+
281
+ disconnectedCallback() {
282
+ _classPrivateFieldGet(this, _$button).removeEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
283
+
284
+ _classPrivateFieldGet(this, _$listbox).removeEventListener('blur', _classPrivateFieldGet(this, _onListboxBlur));
285
+
286
+ _classPrivateFieldGet(this, _$listbox).removeEventListener('click', _classPrivateFieldGet(this, _onListboxClick));
287
+
288
+ _classPrivateFieldGet(this, _$listbox).removeEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
289
+
290
+ _classPrivateFieldGet(this, _$listbox).removeEventListener('keypress', _classPrivateFieldGet(this, _onListboxKeyUp));
291
+
292
+ _classPrivateFieldGet(this, _$selectSlot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
293
+ }
294
+
295
+ static get observedAttributes() {
296
+ return ['value', 'label', 'optionaltext', 'additionaltext', 'invalidtext', 'disabled', 'maxvisibleitems'];
297
+ }
298
+
299
+ get nodeName() {
300
+ return 'select';
301
+ }
302
+
303
+ set value(value) {
304
+ updateAttribute(this, 'value', value);
305
+ }
306
+
307
+ get value() {
308
+ return getAttribute(this, 'value', '');
309
+ }
310
+
311
+ set placeholder(value) {
312
+ updateAttribute(this, 'placeholder', value);
313
+ }
314
+
315
+ get placeholder() {
316
+ return getAttribute(this, 'placeholder', null);
317
+ }
318
+
319
+ set label(value) {
320
+ updateAttribute(this, 'label', value);
321
+ }
322
+
323
+ get label() {
324
+ return getAttribute(this, 'label', '');
325
+ }
326
+
327
+ set optionalText(value) {
328
+ updateAttribute(this, 'optionaltext', value);
329
+ }
330
+
331
+ get optionalText() {
332
+ return getAttribute(this, 'optionaltext', null);
333
+ }
334
+
335
+ set additionalText(value) {
336
+ updateAttribute(this, 'additionaltext', value);
337
+ }
338
+
339
+ get additionalText() {
340
+ return getAttribute(this, 'additionaltext', null);
341
+ }
342
+
343
+ set invalidText(value) {
344
+ updateAttribute(this, 'invalidtext', value);
345
+ }
346
+
347
+ get invalidText() {
348
+ return getAttribute(this, 'placeholder', null);
349
+ }
350
+
351
+ set disabled(isDisabled) {
352
+ updateBooleanAttribute(this, 'disabled', isDisabled);
353
+ }
354
+
355
+ get disabled() {
356
+ return getBooleanAttribute(this, 'disabled');
357
+ }
358
+
359
+ set maxVisibleItems(value) {
360
+ updateIntegerAttribute(this, 'maxvisibleitems', value);
361
+ }
362
+
363
+ get maxVisibleItems() {
364
+ return getIntegerAttribute(this, 'maxvisibleitems', null);
365
+ }
366
+
367
+ attributeChangedCallback(name, oldVal, newVal) {
368
+ switch (name) {
369
+ case 'value':
370
+ {
371
+ this.onValueChange(newVal ?? '');
372
+ break;
373
+ }
374
+
375
+ case 'placeholder':
376
+ {
377
+ this.onValueChange(this.value);
378
+ break;
379
+ }
380
+
381
+ case 'label':
382
+ {
383
+ _classPrivateFieldGet(this, _$label).textContent = newVal;
384
+ updateAttribute(this, 'aria-label', newVal ?? '');
385
+ break;
386
+ }
387
+
388
+ case 'optionaltext':
389
+ {
390
+ _classPrivateFieldGet(this, _$optionalText).textContent = newVal;
391
+ break;
392
+ }
393
+
394
+ case 'additionaltext':
395
+ {
396
+ _classPrivateFieldGet(this, _$additionalText).textContent = newVal;
397
+ break;
398
+ }
399
+
400
+ case 'invalidtext':
401
+ {
402
+ _classPrivateFieldGet(this, _$invalidText).textContent = newVal;
403
+ break;
404
+ }
405
+
406
+ case 'disabled':
407
+ {
408
+ _classPrivateFieldGet(this, _$button).disabled = isAttrTrue(newVal);
409
+
410
+ if (_classPrivateFieldGet(this, _$button).disabled) {
411
+ this.onCollapse();
412
+ }
413
+
414
+ break;
415
+ }
416
+
417
+ case 'maxvisibleitems':
418
+ {
419
+ const $list = _classPrivateFieldGet(this, _$listbox).firstElementChild;
420
+
421
+ $list.style.maxHeight = attrValueToPixels(newVal, {
422
+ min: 2,
423
+ multiplier: ITEM_HEIGHT
424
+ });
425
+ break;
426
+ }
427
+ }
428
+ }
429
+
430
+ onExpand() {
431
+ _classPrivateFieldGet(this, _$button).setAttribute('aria-expanded', 'true');
432
+
433
+ _classPrivateFieldGet(this, _$listbox).focus();
434
+
435
+ selectOption(_classPrivateFieldGet(this, _$selectSlot), getOptionWithValue(_classPrivateFieldGet(this, _$selectSlot), this.value) ?? getFirstOption(_classPrivateFieldGet(this, _$selectSlot)));
436
+ }
437
+
438
+ onCollapse() {
439
+ _classPrivateFieldGet(this, _$button).setAttribute('aria-expanded', 'false');
440
+ }
441
+
442
+ onValueChange(value) {
443
+ let $checkedOption = null;
444
+
445
+ for (const $option of _classPrivateFieldGet(this, _$selectSlot).assignedElements()) {
446
+ if (isSelectOptionElement($option)) {
447
+ const isChecked = $checkedOption === null && $option.disabled !== true && $option.value === value;
448
+ $option.checked = isChecked;
449
+
450
+ if (isChecked) {
451
+ $checkedOption = $option;
452
+
453
+ _classPrivateFieldGet(this, _$listbox).setAttribute('aria-activedescendant', $option.id);
454
+ }
455
+ }
456
+ }
457
+
458
+ this.updateButtonContent($checkedOption);
459
+ }
460
+
461
+ updateButtonContent($option) {
462
+ if (_classPrivateFieldGet(this, _$button).firstElementChild !== _classPrivateFieldGet(this, _$buttonContent)) {
463
+ _classPrivateFieldGet(this, _$button).removeChild(_classPrivateFieldGet(this, _$button).firstElementChild);
464
+ }
465
+
466
+ if ($option === null) {
467
+ _classPrivateFieldGet(this, _$button).setAttribute('data-unselected', '');
468
+
469
+ _classPrivateFieldGet(this, _$buttonContent).textContent = this.placeholder ?? '';
470
+ } else {
471
+ _classPrivateFieldGet(this, _$button).removeAttribute('data-unselected');
472
+
473
+ _classPrivateFieldGet(this, _$buttonContent).textContent = $option.text;
474
+ const $icon = $option.icon?.cloneNode(true);
475
+
476
+ if ($icon != null) {
477
+ _classPrivateFieldGet(this, _$button).prepend($icon);
478
+ }
479
+ }
480
+ }
481
+
482
+ focus() {
483
+ _classPrivateFieldGet(this, _$button).focus();
484
+ }
485
+
486
+ blur() {
487
+ _classPrivateFieldGet(this, _$button).blur();
488
+
489
+ _classPrivateFieldGet(this, _$listbox).blur();
490
+ }
491
+
492
+ }));
@@ -0,0 +1,27 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export declare const isSelectOptionElement: (element: EventTarget | Element | null) => element is TSinchSelectOptionElement;
3
+ export declare type TSinchSelectOptionElement = HTMLElement & {
4
+ value: string;
5
+ text: string;
6
+ checked: boolean;
7
+ selected: boolean;
8
+ disabled: boolean;
9
+ readonly icon: Element | null;
10
+ };
11
+ export declare type TSinchSelectOptionReact = TSinchElementReact<TSinchSelectOptionElement> & {
12
+ value: string;
13
+ text: string;
14
+ checked?: boolean;
15
+ selected?: boolean;
16
+ disabled?: boolean;
17
+ };
18
+ declare global {
19
+ namespace JSX {
20
+ interface IntrinsicElements {
21
+ 'sinch-select-option': TSinchSelectOptionReact;
22
+ }
23
+ }
24
+ interface HTMLElementTagNameMap {
25
+ 'sinch-select-option': TSinchSelectOptionElement;
26
+ }
27
+ }
@@ -0,0 +1,107 @@
1
+ import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
+
4
+ var _$iconSlot, _$content;
5
+
6
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
+
8
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
+
10
+ import { defineCustomElement, getAttribute, getBooleanAttribute, updateAttribute, updateBooleanAttribute } from '../utils';
11
+ const templateHTML = '<style>:host{display:block}*{pointer-events:none}#wrapper{display:flex;position:relative;box-sizing:border-box;padding:6px 12px;width:100%;align-items:center}#content{flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}::slotted(*){margin-right:12px}:host(:hover)>#wrapper,:host([selected])>#wrapper{background-color:var(--sinch-color-snow-500)}:host([checked])>#wrapper{padding-right:36px}:host([checked])>#wrapper::after{content:"";position:absolute;top:10px;right:11px;width:18px;height:14px;background-image:url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cpath d=\'M6 11.17 1.83 7 .41 8.41 6 14 18 2 16.59.59 6 11.17Z\' fill=\'%230A273D\'/%3E%3C/svg%3E");background-size:cover;background-repeat:no-repeat}:host([disabled]:not([disabled=false]))>#wrapper{color:var(--sinch-color-stormy-100);fill:var(--sinch-color-stormy-100)}</style><div id="wrapper"><slot name="icon"></slot><span id="content"></span></div>';
12
+ export const isSelectOptionElement = element => {
13
+ return element instanceof Element && element.tagName === 'SINCH-SELECT-OPTION';
14
+ };
15
+ const template = document.createElement('template');
16
+ template.innerHTML = templateHTML;
17
+ defineCustomElement('sinch-select-option', (_$iconSlot = new WeakMap(), _$content = new WeakMap(), class extends HTMLElement {
18
+ constructor() {
19
+ super();
20
+
21
+ _classPrivateFieldInitSpec(this, _$iconSlot, {
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+
26
+ _classPrivateFieldInitSpec(this, _$content, {
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+
31
+ const shadowRoot = this.attachShadow({
32
+ mode: 'production' === 'development' ? 'open' : 'closed'
33
+ });
34
+ shadowRoot.appendChild(template.content.cloneNode(true));
35
+
36
+ _classPrivateFieldSet(this, _$iconSlot, shadowRoot.querySelector('slot'));
37
+
38
+ _classPrivateFieldSet(this, _$content, shadowRoot.querySelector('span'));
39
+ }
40
+
41
+ connectedCallback() {
42
+ this.setAttribute('role', 'option');
43
+ }
44
+
45
+ static get observedAttributes() {
46
+ return ['text'];
47
+ }
48
+
49
+ attributeChangedCallback(name, oldVal, newVal) {
50
+ if (oldVal === newVal) {
51
+ return;
52
+ }
53
+
54
+ switch (name) {
55
+ case 'text':
56
+ {
57
+ _classPrivateFieldGet(this, _$content).textContent = newVal;
58
+ break;
59
+ }
60
+ }
61
+ }
62
+
63
+ set value(value) {
64
+ updateAttribute(this, 'value', value);
65
+ }
66
+
67
+ get value() {
68
+ return getAttribute(this, 'value', '');
69
+ }
70
+
71
+ set text(value) {
72
+ updateAttribute(this, 'text', value);
73
+ }
74
+
75
+ get text() {
76
+ return getAttribute(this, 'text', '');
77
+ }
78
+
79
+ set disabled(isDisabled) {
80
+ updateBooleanAttribute(this, 'disabled', isDisabled);
81
+ }
82
+
83
+ get disabled() {
84
+ return getBooleanAttribute(this, 'disabled');
85
+ }
86
+
87
+ set checked(isChecked) {
88
+ updateBooleanAttribute(this, 'checked', isChecked);
89
+ }
90
+
91
+ get checked() {
92
+ return getBooleanAttribute(this, 'checked');
93
+ }
94
+
95
+ set selected(isSelected) {
96
+ updateBooleanAttribute(this, 'selected', isSelected);
97
+ }
98
+
99
+ get selected() {
100
+ return getBooleanAttribute(this, 'selected');
101
+ }
102
+
103
+ get icon() {
104
+ return _classPrivateFieldGet(this, _$iconSlot).assignedElements()[0] ?? null;
105
+ }
106
+
107
+ }));
@@ -0,0 +1,21 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ declare const spinnerTypes: readonly ["large", "medium", "small"];
3
+ export declare type TSinchSpinnerType = typeof spinnerTypes[number];
4
+ export declare type TSinchSpinnerElement = HTMLElement & {
5
+ type: TSinchSpinnerType;
6
+ };
7
+ export declare type TSinchSpinnerReact = TSinchElementReact<TSinchSpinnerElement> & {
8
+ type?: TSinchSpinnerType;
9
+ static?: boolean;
10
+ };
11
+ declare global {
12
+ namespace JSX {
13
+ interface IntrinsicElements {
14
+ 'sinch-spinner': TSinchSpinnerReact;
15
+ }
16
+ }
17
+ interface HTMLElementTagNameMap {
18
+ 'sinch-spinner': TSinchSpinnerElement;
19
+ }
20
+ }
21
+ export {};
@@ -0,0 +1,23 @@
1
+ import { defineCustomElement, getLiteralAttribute, updateLiteralAttribute } from '../utils';
2
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}@keyframes spinner{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}div{animation:1.5s linear infinite spinner;animation-play-state:running;border:solid 3px var(--sinch-color-spinner-bg,#d4dadd);border-bottom-color:var(--sinch-color-spinner-fg,#0a273d);border-radius:50%;height:20px;width:20px;box-sizing:border-box;will-change:transform}:host([type=large]) div{height:46px;width:46px;border-width:4px}:host([type=small]) div{height:14px;width:14px;border-width:2px}:host([static]:not([static=false])) div{animation-play-state:paused}</style><div></div>';
3
+ const spinnerTypes = ['large', 'medium', 'small'];
4
+ const template = document.createElement('template');
5
+ template.innerHTML = templateHTML;
6
+ defineCustomElement('sinch-spinner', class extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ const shadowRoot = this.attachShadow({
10
+ mode: 'production' === 'development' ? 'open' : 'closed'
11
+ });
12
+ shadowRoot.appendChild(template.content.cloneNode(true));
13
+ }
14
+
15
+ set type(value) {
16
+ updateLiteralAttribute(this, spinnerTypes, 'type', value);
17
+ }
18
+
19
+ get type() {
20
+ return getLiteralAttribute(this, spinnerTypes, 'type', 'medium');
21
+ }
22
+
23
+ });
@@ -0,0 +1,13 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export declare type TSinchTableElement = HTMLElement;
3
+ export declare type TSinchTableReact = TSinchElementReact<TSinchTableElement>;
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'sinch-table': TSinchTableReact;
8
+ }
9
+ }
10
+ interface HTMLElementTagNameMap {
11
+ 'sinch-table': TSinchTableElement;
12
+ }
13
+ }