@nectary/components 0.9.0 → 0.11.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 (106) hide show
  1. package/accordion/index.js +5 -1
  2. package/accordion-item/index.js +7 -7
  3. package/alert/index.js +2 -2
  4. package/alert-button/index.js +1 -1
  5. package/alert-close/index.js +2 -2
  6. package/button/index.d.ts +2 -1
  7. package/button/index.js +7 -3
  8. package/card/index.d.ts +23 -0
  9. package/card/index.js +164 -0
  10. package/card-button/index.d.ts +27 -0
  11. package/card-button/index.js +83 -0
  12. package/card-link/index.d.ts +29 -0
  13. package/card-link/index.js +121 -0
  14. package/checkbox/index.d.ts +3 -0
  15. package/checkbox/index.js +27 -18
  16. package/dialog/index.d.ts +23 -0
  17. package/dialog/index.js +181 -0
  18. package/dropdown/index.d.ts +34 -0
  19. package/dropdown/index.js +451 -0
  20. package/dropdown-option/index.d.ts +44 -0
  21. package/dropdown-option/index.js +116 -0
  22. package/help-tooltip/index.js +5 -1
  23. package/icon/arrow-back/index.d.ts +11 -0
  24. package/icon/arrow-back/index.js +4 -0
  25. package/icon/arrow-downward/index.d.ts +11 -0
  26. package/icon/arrow-downward/index.js +4 -0
  27. package/icon/arrow-forward/index.d.ts +11 -0
  28. package/icon/arrow-forward/index.js +4 -0
  29. package/icon/arrow-upward/index.d.ts +11 -0
  30. package/icon/arrow-upward/index.js +4 -0
  31. package/icon/cancel/index.js +1 -1
  32. package/icon/close/index.js +1 -1
  33. package/icon/create-icon-class.js +1 -1
  34. package/icon/east/index.js +1 -1
  35. package/icon/help-outline/index.js +1 -1
  36. package/icon/more-horiz/index.js +1 -1
  37. package/icon/more-vert/index.js +1 -1
  38. package/icon/north/index.js +1 -1
  39. package/icon/north-east/index.js +1 -1
  40. package/icon/north-west/index.js +1 -1
  41. package/icon/open-in-new/index.js +1 -1
  42. package/icon/south/index.js +1 -1
  43. package/icon/south-east/index.js +1 -1
  44. package/icon/south-west/index.js +1 -1
  45. package/icon/west/index.js +1 -1
  46. package/icon-branded/barchart-down/index.js +1 -1
  47. package/icon-branded/barchart-up/index.js +1 -1
  48. package/icon-branded/campaigns/index.js +1 -1
  49. package/icon-branded/chatbot/index.js +1 -1
  50. package/icon-branded/contact/index.js +1 -1
  51. package/icon-branded/create-icon-class.js +1 -1
  52. package/icon-branded/home/index.js +1 -1
  53. package/icon-branded/multiple-channels/index.js +1 -1
  54. package/icon-branded/rocket/index.js +1 -1
  55. package/icon-branded/settings/index.js +1 -1
  56. package/icon-branded/user/index.js +1 -1
  57. package/icon-branded/users/index.js +1 -1
  58. package/illustration/create-illustration-class.d.ts +308 -0
  59. package/illustration/create-illustration-class.js +53 -0
  60. package/illustration/phone-and-cat/index.d.ts +11 -0
  61. package/illustration/phone-and-cat/index.js +4 -0
  62. package/illustration/types.d.ts +7 -0
  63. package/illustration/types.js +1 -0
  64. package/index.d.ts +11 -0
  65. package/index.js +12 -1
  66. package/input/index.d.ts +3 -1
  67. package/input/index.js +59 -11
  68. package/link/index.js +2 -2
  69. package/logo/create-logo-class.js +1 -1
  70. package/logo/sinch-icon/index.js +1 -1
  71. package/logo/sinch-icon-wordmark/index.js +1 -1
  72. package/package.json +1 -1
  73. package/pagination/index.js +1 -6
  74. package/radio/index.d.ts +1 -0
  75. package/radio/index.js +97 -71
  76. package/radio-option/index.d.ts +1 -0
  77. package/radio-option/index.js +4 -1
  78. package/select/index.d.ts +4 -1
  79. package/select/index.js +72 -265
  80. package/select-option/index.d.ts +3 -17
  81. package/select-option/index.js +4 -103
  82. package/spinner/index.js +1 -1
  83. package/table/index.js +1 -1
  84. package/table-body/index.js +1 -1
  85. package/table-cell/index.js +1 -1
  86. package/table-head/index.js +1 -1
  87. package/table-head-cell/index.js +3 -2
  88. package/table-head-sort/index.d.ts +1 -0
  89. package/table-head-sort/index.js +3 -1
  90. package/table-row/index.js +1 -1
  91. package/tabs/index.d.ts +1 -0
  92. package/tabs/index.js +96 -66
  93. package/tabs-option/index.d.ts +1 -0
  94. package/tabs-option/index.js +4 -2
  95. package/tag/index.js +1 -1
  96. package/tag-close/index.js +2 -2
  97. package/textarea/index.d.ts +3 -1
  98. package/textarea/index.js +58 -11
  99. package/theme.css +6 -2
  100. package/toggle/index.d.ts +1 -0
  101. package/toggle/index.js +4 -5
  102. package/tooltip/index.d.ts +2 -1
  103. package/tooltip/index.js +7 -3
  104. package/types.d.ts +7 -0
  105. package/utils.d.ts +3 -0
  106. package/utils.js +17 -0
package/select/index.js CHANGED
@@ -1,109 +1,30 @@
1
1
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
2
  import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
3
 
4
- var _$button, _$buttonContent, _$label, _$optionalText, _$additionalText, _$invalidText, _$selectSlot, _$listbox, _onButtonClick, _onListboxClick, _onListboxKeyUp, _onListboxKeyDown, _onSlotChange, _onListboxBlur;
4
+ var _$button, _$buttonContent, _$label, _$optionalText, _$additionalText, _$invalidText, _$dropdown, _$optionSlot, _updateButtonContent, _onValueChange, _getOptionWithValue, _onLabelClick;
5
+
6
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
5
7
 
6
8
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
9
 
8
10
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
11
 
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);background-color:var(--sinch-color-snow-100)}#dropdown-icon{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)}#button:disabled #dropdown-icon{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])){--sinch-color-icon:var(--sinch-color-stormy-100)}#listbox{position:absolute;left:0;top:0;padding-top:74px;width:100%;display:none;list-style:none;outline:0;z-index:1}#listbox>*{font:var(--sinch-font-body);color:var(--sinch-color-text-default);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
- };
12
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
100
13
 
14
+ import { isDropdownOptionElement } from '../dropdown-option';
15
+ import '../select-option';
16
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, isAttrTrue, updateAttribute, updateBooleanAttribute, updateIntegerAttribute } from '../utils';
17
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0;--sinch-color-icon:var(--sinch-color-stormy-500)}#wrapper{position:relative}sinch-dropdown{display:block}#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);background-color:var(--sinch-color-snow-100);cursor:pointer}#button:focus{border-color:var(--sinch-color-stormy-300)}#dropdown-icon{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);cursor:initial}#button:disabled #dropdown-icon{fill:var(--sinch-color-stormy-100)}: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])){--sinch-color-icon:var(--sinch-color-stormy-100)}#listbox{position:absolute;left:0;top:0;padding-top:74px;width:100%;display:none;list-style:none;outline:0;z-index:1}#listbox-body{font:var(--sinch-font-body);color:var(--sinch-color-text-default);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]~#listbox{display:block}</style><div id="wrapper"><div id="top"><label id="label" for="dropdown"></label><slot name="tooltip"></slot><span id="optional"></span></div><sinch-dropdown id="dropdown"><button slot="target" id="button"><span id="content"></span> <svg id="dropdown-icon" width="12" height="8" aria-hidden="true"><path d="M1.41.59 6 5.17 10.59.59 12 2 6 8 0 2 1.41.59Z"/></svg></button><slot name="option" slot="option"></slot></sinch-dropdown><div id="bottom"><span id="invalid"></span> <span id="additional"></span></div></div>';
101
18
  const template = document.createElement('template');
102
19
  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 {
20
+ defineCustomElement('sinch-select', (_$button = new WeakMap(), _$buttonContent = new WeakMap(), _$label = new WeakMap(), _$optionalText = new WeakMap(), _$additionalText = new WeakMap(), _$invalidText = new WeakMap(), _$dropdown = new WeakMap(), _$optionSlot = new WeakMap(), _updateButtonContent = new WeakSet(), _onValueChange = new WeakMap(), _getOptionWithValue = new WeakSet(), _onLabelClick = new WeakMap(), class extends HTMLElement {
104
21
  constructor() {
105
22
  super();
106
23
 
24
+ _classPrivateMethodInitSpec(this, _getOptionWithValue);
25
+
26
+ _classPrivateMethodInitSpec(this, _updateButtonContent);
27
+
107
28
  _classPrivateFieldInitSpec(this, _$button, {
108
29
  writable: true,
109
30
  value: void 0
@@ -134,113 +55,35 @@ defineCustomElement('sinch-select', (_$button = new WeakMap(), _$buttonContent =
134
55
  value: void 0
135
56
  });
136
57
 
137
- _classPrivateFieldInitSpec(this, _$selectSlot, {
58
+ _classPrivateFieldInitSpec(this, _$dropdown, {
138
59
  writable: true,
139
60
  value: void 0
140
61
  });
141
62
 
142
- _classPrivateFieldInitSpec(this, _$listbox, {
63
+ _classPrivateFieldInitSpec(this, _$optionSlot, {
143
64
  writable: true,
144
65
  value: void 0
145
66
  });
146
67
 
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, {
68
+ _classPrivateFieldInitSpec(this, _onValueChange, {
175
69
  writable: true,
176
70
  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
- }
71
+ this.dispatchEvent(new CustomEvent('change', {
72
+ detail: e.detail,
73
+ bubbles: true
74
+ }));
190
75
  }
191
76
  });
192
77
 
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, {
78
+ _classPrivateFieldInitSpec(this, _onLabelClick, {
227
79
  writable: true,
228
80
  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();
81
+ this.focus();
239
82
  }
240
83
  });
241
84
 
242
85
  const shadowRoot = this.attachShadow({
243
- mode: 'production' === 'development' ? 'open' : 'closed',
86
+ mode: 'closed',
244
87
  delegatesFocus: true
245
88
  });
246
89
  shadowRoot.appendChild(template.content.cloneNode(true));
@@ -249,8 +92,6 @@ defineCustomElement('sinch-select', (_$button = new WeakMap(), _$buttonContent =
249
92
 
250
93
  _classPrivateFieldSet(this, _$buttonContent, shadowRoot.querySelector('#content'));
251
94
 
252
- _classPrivateFieldSet(this, _$listbox, shadowRoot.querySelector('#listbox'));
253
-
254
95
  _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#label'));
255
96
 
256
97
  _classPrivateFieldSet(this, _$optionalText, shadowRoot.querySelector('#optional'));
@@ -259,41 +100,27 @@ defineCustomElement('sinch-select', (_$button = new WeakMap(), _$buttonContent =
259
100
 
260
101
  _classPrivateFieldSet(this, _$invalidText, shadowRoot.querySelector('#invalid'));
261
102
 
262
- _classPrivateFieldSet(this, _$selectSlot, shadowRoot.querySelector('slot[name="select"]'));
103
+ _classPrivateFieldSet(this, _$dropdown, shadowRoot.querySelector('sinch-dropdown'));
104
+
105
+ _classPrivateFieldSet(this, _$optionSlot, shadowRoot.querySelector('slot[name="option"]'));
263
106
  }
264
107
 
265
108
  connectedCallback() {
266
109
  this.setAttribute('role', 'listbox');
267
110
 
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));
111
+ _classPrivateFieldGet(this, _$dropdown).addEventListener('change', _classPrivateFieldGet(this, _onValueChange));
273
112
 
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));
113
+ _classPrivateFieldGet(this, _$label).addEventListener('click', _classPrivateFieldGet(this, _onLabelClick));
279
114
  }
280
115
 
281
116
  disconnectedCallback() {
282
- _classPrivateFieldGet(this, _$button).removeEventListener('click', _classPrivateFieldGet(this, _onButtonClick));
283
-
284
- _classPrivateFieldGet(this, _$listbox).removeEventListener('blur', _classPrivateFieldGet(this, _onListboxBlur));
117
+ _classPrivateFieldGet(this, _$dropdown).removeEventListener('change', _classPrivateFieldGet(this, _onValueChange));
285
118
 
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));
119
+ _classPrivateFieldGet(this, _$label).removeEventListener('click', _classPrivateFieldGet(this, _onLabelClick));
293
120
  }
294
121
 
295
122
  static get observedAttributes() {
296
- return ['value', 'label', 'optionaltext', 'additionaltext', 'invalidtext', 'disabled', 'maxvisibleitems'];
123
+ return ['value', 'label', 'placeholder', 'optionaltext', 'additionaltext', 'invalidtext', 'disabled', 'maxvisibleitems'];
297
124
  }
298
125
 
299
126
  get nodeName() {
@@ -364,24 +191,33 @@ defineCustomElement('sinch-select', (_$button = new WeakMap(), _$buttonContent =
364
191
  return getIntegerAttribute(this, 'maxvisibleitems', null);
365
192
  }
366
193
 
194
+ get dropdownRect() {
195
+ return _classPrivateFieldGet(this, _$dropdown).dropdownRect;
196
+ }
197
+
367
198
  attributeChangedCallback(name, oldVal, newVal) {
368
199
  switch (name) {
369
200
  case 'value':
370
201
  {
371
- this.onValueChange(newVal ?? '');
202
+ updateAttribute(_classPrivateFieldGet(this, _$dropdown), 'value', newVal);
203
+
204
+ _classPrivateMethodGet(this, _updateButtonContent, _updateButtonContent2).call(this);
205
+
372
206
  break;
373
207
  }
374
208
 
375
209
  case 'placeholder':
376
210
  {
377
- this.onValueChange(this.value);
211
+ updateAttribute(this, 'role-description', newVal);
212
+
213
+ _classPrivateMethodGet(this, _updateButtonContent, _updateButtonContent2).call(this);
214
+
378
215
  break;
379
216
  }
380
217
 
381
218
  case 'label':
382
219
  {
383
220
  _classPrivateFieldGet(this, _$label).textContent = newVal;
384
- updateAttribute(this, 'aria-label', newVal ?? '');
385
221
  break;
386
222
  }
387
223
 
@@ -400,93 +236,64 @@ defineCustomElement('sinch-select', (_$button = new WeakMap(), _$buttonContent =
400
236
  case 'invalidtext':
401
237
  {
402
238
  _classPrivateFieldGet(this, _$invalidText).textContent = newVal;
239
+ updateAttribute(this, 'aria-invalid', String(newVal !== null && newVal !== ''));
403
240
  break;
404
241
  }
405
242
 
406
243
  case 'disabled':
407
244
  {
245
+ updateAttribute(_classPrivateFieldGet(this, _$dropdown), 'disabled', newVal);
408
246
  _classPrivateFieldGet(this, _$button).disabled = isAttrTrue(newVal);
409
-
410
- if (_classPrivateFieldGet(this, _$button).disabled) {
411
- this.onCollapse();
412
- }
413
-
414
247
  break;
415
248
  }
416
249
 
417
250
  case 'maxvisibleitems':
418
251
  {
419
- const $list = _classPrivateFieldGet(this, _$listbox).firstElementChild;
420
-
421
- $list.style.maxHeight = attrValueToPixels(newVal, {
422
- min: 2,
423
- multiplier: ITEM_HEIGHT
424
- });
252
+ updateAttribute(_classPrivateFieldGet(this, _$dropdown), 'maxvisibleitems', newVal);
425
253
  break;
426
254
  }
427
255
  }
428
256
  }
429
257
 
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)));
258
+ focus() {
259
+ _classPrivateFieldGet(this, _$dropdown).focus();
436
260
  }
437
261
 
438
- onCollapse() {
439
- _classPrivateFieldGet(this, _$button).setAttribute('aria-expanded', 'false');
262
+ blur() {
263
+ _classPrivateFieldGet(this, _$dropdown).blur();
440
264
  }
441
265
 
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
- }
266
+ }));
457
267
 
458
- this.updateButtonContent($checkedOption);
268
+ function _updateButtonContent2() {
269
+ if (_classPrivateFieldGet(this, _$button).firstElementChild !== _classPrivateFieldGet(this, _$buttonContent)) {
270
+ _classPrivateFieldGet(this, _$button).removeChild(_classPrivateFieldGet(this, _$button).firstElementChild);
459
271
  }
460
272
 
461
- updateButtonContent($option) {
462
- if (_classPrivateFieldGet(this, _$button).firstElementChild !== _classPrivateFieldGet(this, _$buttonContent)) {
463
- _classPrivateFieldGet(this, _$button).removeChild(_classPrivateFieldGet(this, _$button).firstElementChild);
464
- }
273
+ const $option = _classPrivateMethodGet(this, _getOptionWithValue, _getOptionWithValue2).call(this, this.value);
465
274
 
466
- if ($option === null) {
467
- _classPrivateFieldGet(this, _$button).setAttribute('data-unselected', '');
275
+ if ($option == null) {
276
+ _classPrivateFieldGet(this, _$button).setAttribute('data-unselected', '');
468
277
 
469
- _classPrivateFieldGet(this, _$buttonContent).textContent = this.placeholder ?? '';
470
- } else {
471
- _classPrivateFieldGet(this, _$button).removeAttribute('data-unselected');
278
+ _classPrivateFieldGet(this, _$buttonContent).textContent = this.placeholder ?? '';
279
+ } else {
280
+ _classPrivateFieldGet(this, _$button).removeAttribute('data-unselected');
472
281
 
473
- _classPrivateFieldGet(this, _$buttonContent).textContent = $option.text;
474
- const $icon = $option.icon?.cloneNode(true);
282
+ _classPrivateFieldGet(this, _$buttonContent).textContent = $option.text;
283
+ const $icon = $option.icon;
475
284
 
476
- if ($icon != null) {
477
- _classPrivateFieldGet(this, _$button).prepend($icon);
478
- }
285
+ if ($icon != null) {
286
+ _classPrivateFieldGet(this, _$button).prepend($icon.cloneNode(true));
479
287
  }
480
288
  }
289
+ }
481
290
 
482
- focus() {
483
- _classPrivateFieldGet(this, _$button).focus();
484
- }
485
-
486
- blur() {
487
- _classPrivateFieldGet(this, _$button).blur();
488
-
489
- _classPrivateFieldGet(this, _$listbox).blur();
291
+ function _getOptionWithValue2(value) {
292
+ for (const $option of _classPrivateFieldGet(this, _$optionSlot).assignedElements()) {
293
+ if (isDropdownOptionElement($option) && $option.disabled !== true && $option.value === value) {
294
+ return $option;
295
+ }
490
296
  }
491
297
 
492
- }));
298
+ return null;
299
+ }
@@ -1,20 +1,6 @@
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
- };
1
+ import type { TSinchDropdownOptionElement, TSinchDropdownOptionReact } from '../dropdown-option';
2
+ export declare type TSinchSelectOptionElement = TSinchDropdownOptionElement;
3
+ export declare type TSinchSelectOptionReact = TSinchDropdownOptionReact;
18
4
  declare global {
19
5
  namespace JSX {
20
6
  interface IntrinsicElements {
@@ -1,107 +1,8 @@
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);--sinch-color-icon: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 {
1
+ import { DropdownOption } from '../dropdown-option';
2
+ import { defineCustomElement } from '../utils';
3
+ defineCustomElement('sinch-select-option', class extends DropdownOption {
18
4
  constructor() {
19
5
  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
6
  }
106
7
 
107
- }));
8
+ });
package/spinner/index.js CHANGED
@@ -7,7 +7,7 @@ defineCustomElement('sinch-spinner', class extends HTMLElement {
7
7
  constructor() {
8
8
  super();
9
9
  const shadowRoot = this.attachShadow({
10
- mode: 'production' === 'development' ? 'open' : 'closed'
10
+ mode: 'closed'
11
11
  });
12
12
  shadowRoot.appendChild(template.content.cloneNode(true));
13
13
  }
package/table/index.js CHANGED
@@ -6,7 +6,7 @@ defineCustomElement('sinch-table', class extends HTMLElement {
6
6
  constructor() {
7
7
  super();
8
8
  const shadowRoot = this.attachShadow({
9
- mode: 'production' === 'development' ? 'open' : 'closed'
9
+ mode: 'closed'
10
10
  });
11
11
  shadowRoot.appendChild(template.content.cloneNode(true));
12
12
  }
@@ -6,7 +6,7 @@ defineCustomElement('sinch-table-body', class extends HTMLElement {
6
6
  constructor() {
7
7
  super();
8
8
  const shadowRoot = this.attachShadow({
9
- mode: 'production' === 'development' ? 'open' : 'closed'
9
+ mode: 'closed'
10
10
  });
11
11
  shadowRoot.appendChild(template.content.cloneNode(true));
12
12
  }
@@ -7,7 +7,7 @@ defineCustomElement('sinch-table-cell', class extends HTMLElement {
7
7
  constructor() {
8
8
  super();
9
9
  const shadowRoot = this.attachShadow({
10
- mode: 'production' === 'development' ? 'open' : 'closed'
10
+ mode: 'closed'
11
11
  });
12
12
  shadowRoot.appendChild(template.content.cloneNode(true));
13
13
  }
@@ -6,7 +6,7 @@ defineCustomElement('sinch-table-head', class extends HTMLElement {
6
6
  constructor() {
7
7
  super();
8
8
  const shadowRoot = this.attachShadow({
9
- mode: 'production' === 'development' ? 'open' : 'closed'
9
+ mode: 'closed'
10
10
  });
11
11
  shadowRoot.appendChild(template.content.cloneNode(true));
12
12
  }