@nectary/components 0.38.0 → 0.40.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 (148) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion/types.d.ts +1 -0
  3. package/accordion-item/index.js +26 -53
  4. package/action-menu/index.d.ts +0 -1
  5. package/action-menu/index.js +179 -223
  6. package/action-menu/types.d.ts +8 -18
  7. package/action-menu-option/index.d.ts +1 -0
  8. package/action-menu-option/index.js +51 -62
  9. package/action-menu-option/types.d.ts +9 -0
  10. package/action-menu-option/utils.d.ts +2 -0
  11. package/action-menu-option/utils.js +3 -0
  12. package/alert/index.js +6 -20
  13. package/avatar/index.js +12 -31
  14. package/avatar-badge/index.js +8 -22
  15. package/avatar-status/index.js +1 -1
  16. package/button/index.js +42 -92
  17. package/card/index.d.ts +2 -0
  18. package/card/index.js +24 -87
  19. package/chat-avatar/index.js +8 -22
  20. package/chat-block/index.js +29 -69
  21. package/chat-bubble/index.js +6 -20
  22. package/checkbox/index.js +55 -107
  23. package/chip/index.d.ts +13 -0
  24. package/chip/index.js +137 -0
  25. package/chip/types.d.ts +38 -0
  26. package/color-menu/index.d.ts +13 -0
  27. package/color-menu/index.js +464 -0
  28. package/color-menu/types.d.ts +37 -0
  29. package/color-swatch/index.d.ts +13 -0
  30. package/color-swatch/index.js +59 -0
  31. package/color-swatch/types.d.ts +12 -0
  32. package/colors.json +57 -49
  33. package/date-picker/index.js +196 -287
  34. package/date-picker/types.d.ts +25 -1
  35. package/dialog/index.d.ts +1 -0
  36. package/dialog/index.js +72 -143
  37. package/dropdown-checkbox-option/index.js +6 -20
  38. package/dropdown-radio-option/index.js +6 -20
  39. package/field/index.js +25 -63
  40. package/file-drop/index.js +123 -200
  41. package/file-picker/index.d.ts +0 -1
  42. package/file-picker/index.js +55 -108
  43. package/file-status/index.js +15 -39
  44. package/help-tooltip/index.js +1 -1
  45. package/horizontal-stepper/index.js +33 -59
  46. package/horizontal-stepper-item/index.js +13 -37
  47. package/icon-button/index.js +39 -84
  48. package/icons-channel/notify/index.d.ts +11 -0
  49. package/icons-channel/notify/index.js +4 -0
  50. package/illustrations/create-illustration-class.js +1 -1
  51. package/inline-alert/index.js +30 -82
  52. package/input/index.js +113 -222
  53. package/link/index.js +46 -96
  54. package/list-item/index.js +1 -1
  55. package/package.json +12 -14
  56. package/pagination/index.js +109 -163
  57. package/pagination/types.d.ts +1 -0
  58. package/popover/index.js +224 -294
  59. package/progress/index.js +9 -28
  60. package/radio/index.js +103 -169
  61. package/radio/types.d.ts +1 -0
  62. package/radio-option/index.js +24 -48
  63. package/segment/index.js +50 -131
  64. package/segment-collapse/index.js +24 -49
  65. package/segment-collapse/types.d.ts +1 -0
  66. package/segmented-control/index.js +36 -73
  67. package/segmented-control/types.d.ts +1 -0
  68. package/segmented-control-option/index.js +41 -87
  69. package/segmented-icon-control/index.js +47 -84
  70. package/segmented-icon-control/types.d.ts +1 -0
  71. package/segmented-icon-control-option/index.js +38 -79
  72. package/select-button/index.d.ts +13 -0
  73. package/select-button/index.js +153 -0
  74. package/select-button/types.d.ts +43 -0
  75. package/select-menu/index.d.ts +11 -0
  76. package/select-menu/index.js +346 -0
  77. package/select-menu/types.d.ts +29 -0
  78. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  79. package/select-menu-option/index.js +76 -0
  80. package/{select-option → select-menu-option}/types.d.ts +8 -9
  81. package/stop-events/index.js +7 -20
  82. package/table-head-cell/index.js +7 -21
  83. package/tabs/index.js +103 -165
  84. package/tabs/types.d.ts +1 -0
  85. package/tabs-option/index.js +20 -44
  86. package/tag/index.d.ts +1 -1
  87. package/tag/index.js +42 -36
  88. package/tag/types.d.ts +13 -7
  89. package/textarea/index.js +92 -167
  90. package/theme.css +80 -49
  91. package/tile-control/index.js +55 -96
  92. package/tile-control-option/index.js +40 -86
  93. package/time-picker/index.js +224 -368
  94. package/time-picker/types.d.ts +5 -1
  95. package/title/index.js +6 -20
  96. package/toast/index.d.ts +17 -0
  97. package/toast/index.js +115 -0
  98. package/toast/types.d.ts +28 -0
  99. package/toast/utils.d.ts +5 -0
  100. package/toast/utils.js +6 -0
  101. package/toast-manager/index.d.ts +17 -0
  102. package/toast-manager/index.js +195 -0
  103. package/toast-manager/types.d.ts +7 -0
  104. package/toggle/index.js +55 -108
  105. package/toggle/types.d.ts +1 -0
  106. package/types.d.ts +7 -0
  107. package/utils/colors.d.ts +10 -0
  108. package/utils/colors.js +121 -0
  109. package/{utils.d.ts → utils/index.d.ts} +18 -9
  110. package/{utils.js → utils/index.js} +118 -39
  111. package/vertical-stepper/index.js +29 -50
  112. package/vertical-stepper-item/index.js +13 -37
  113. package/card-button/index.d.ts +0 -11
  114. package/card-button/index.js +0 -77
  115. package/card-button/types.d.ts +0 -12
  116. package/card-link/index.d.ts +0 -12
  117. package/card-link/index.js +0 -115
  118. package/card-link/types.d.ts +0 -14
  119. package/dropdown/index.d.ts +0 -12
  120. package/dropdown/index.js +0 -415
  121. package/dropdown/types.d.ts +0 -30
  122. package/dropdown-text-option/index.js +0 -104
  123. package/dropdown-text-option/types.d.ts +0 -16
  124. package/search/index.d.ts +0 -14
  125. package/search/index.js +0 -523
  126. package/search/types.d.ts +0 -25
  127. package/search-option/index.d.ts +0 -11
  128. package/search-option/index.js +0 -55
  129. package/search-option/types.d.ts +0 -9
  130. package/select/index.d.ts +0 -13
  131. package/select/index.js +0 -316
  132. package/select/types.d.ts +0 -53
  133. package/select-option/index.d.ts +0 -11
  134. package/select-option/index.js +0 -8
  135. package/tag/utils.d.ts +0 -2
  136. package/tag/utils.js +0 -1
  137. package/tag-close/index.d.ts +0 -12
  138. package/tag-close/index.js +0 -38
  139. package/tag-close/types.d.ts +0 -3
  140. package/tag-close/types.js +0 -1
  141. /package/{card-button → chip}/types.js +0 -0
  142. /package/{card-link → color-menu}/types.js +0 -0
  143. /package/{dropdown-text-option → color-swatch}/types.js +0 -0
  144. /package/{dropdown → select-button}/types.js +0 -0
  145. /package/{search → select-menu}/types.js +0 -0
  146. /package/{search-option → select-menu-option}/types.js +0 -0
  147. /package/{select → toast}/types.js +0 -0
  148. /package/{select-option → toast-manager}/types.js +0 -0
@@ -1,295 +1,251 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$optionSlot, _$listbox, _$popover, _onListboxKeyDown, _getFirstOption, _getLastOption, _getNextOption, _getPrevOption, _selectOption, _getOptionElements, _findSelectedOption, _getEnabledOptionElements, _onClose, _onReactClose;
5
-
6
- function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
-
8
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
9
-
10
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
11
-
12
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
13
-
14
- import { orientationValues } from '../popover/utils';
15
- import '../popover';
16
- import { attrValueToPixels, defineCustomElement, getBooleanAttribute, getIntegerAttribute, getLiteralAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateIntegerAttribute, updateLiteralAttribute } from '../utils';
17
- const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{width:100%;--sinch-popover-shape-radius:var(--sinch-shape-radius-s)}#listbox{overflow-y:auto}</style><sinch-popover id="wrapper"><slot name="target" slot="target"></slot><div id="listbox" slot="content"><slot name="option"></slot></div></sinch-popover>';
1
+ import { isSinchActionMenuOption } from '../action-menu-option/utils';
2
+ import { attrValueToPixels, defineCustomElement, getBooleanAttribute, getIntegerAttribute, NectaryElement, updateBooleanAttribute, updateIntegerAttribute } from '../utils';
3
+ const templateHTML = '<style>:host{display:block;outline:0}#listbox{overflow-y:auto}</style><div id="listbox" role="presentation"><slot></slot></div>';
18
4
  const ITEM_HEIGHT = 40;
19
5
  const template = document.createElement('template');
20
6
  template.innerHTML = templateHTML;
21
- defineCustomElement('sinch-action-menu', (_$optionSlot = new WeakMap(), _$listbox = new WeakMap(), _$popover = new WeakMap(), _onListboxKeyDown = new WeakMap(), _getFirstOption = new WeakSet(), _getLastOption = new WeakSet(), _getNextOption = new WeakSet(), _getPrevOption = new WeakSet(), _selectOption = new WeakSet(), _getOptionElements = new WeakSet(), _findSelectedOption = new WeakSet(), _getEnabledOptionElements = new WeakSet(), _onClose = new WeakMap(), _onReactClose = new WeakMap(), class extends NectaryElement {
7
+ defineCustomElement('sinch-action-menu', class extends NectaryElement {
8
+ #$optionSlot;
9
+ #$listbox;
10
+ #controller = new AbortController();
11
+
22
12
  constructor() {
23
13
  super();
24
-
25
- _classPrivateMethodInitSpec(this, _getEnabledOptionElements);
26
-
27
- _classPrivateMethodInitSpec(this, _findSelectedOption);
28
-
29
- _classPrivateMethodInitSpec(this, _getOptionElements);
30
-
31
- _classPrivateMethodInitSpec(this, _selectOption);
32
-
33
- _classPrivateMethodInitSpec(this, _getPrevOption);
34
-
35
- _classPrivateMethodInitSpec(this, _getNextOption);
36
-
37
- _classPrivateMethodInitSpec(this, _getLastOption);
38
-
39
- _classPrivateMethodInitSpec(this, _getFirstOption);
40
-
41
- _classPrivateFieldInitSpec(this, _$optionSlot, {
42
- writable: true,
43
- value: void 0
44
- });
45
-
46
- _classPrivateFieldInitSpec(this, _$listbox, {
47
- writable: true,
48
- value: void 0
49
- });
50
-
51
- _classPrivateFieldInitSpec(this, _$popover, {
52
- writable: true,
53
- value: void 0
54
- });
55
-
56
- _classPrivateFieldInitSpec(this, _onListboxKeyDown, {
57
- writable: true,
58
- value: e => {
59
- switch (e.code) {
60
- case 'Enter':
61
- {
62
- const $opt = _classPrivateMethodGet(this, _findSelectedOption, _findSelectedOption2).call(this, _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this));
63
-
64
- if ($opt !== null) {
65
- e.preventDefault();
66
- $opt.click();
67
- }
68
-
69
- break;
70
- }
71
-
72
- case 'ArrowUp':
73
- {
74
- e.preventDefault();
75
-
76
- _classPrivateMethodGet(this, _selectOption, _selectOption2).call(this, _classPrivateMethodGet(this, _getPrevOption, _getPrevOption2).call(this));
77
-
78
- break;
79
- }
80
-
81
- case 'ArrowDown':
82
- {
83
- e.preventDefault();
84
-
85
- _classPrivateMethodGet(this, _selectOption, _selectOption2).call(this, _classPrivateMethodGet(this, _getNextOption, _getNextOption2).call(this));
86
-
87
- break;
88
- }
89
- }
90
- }
91
- });
92
-
93
- _classPrivateFieldInitSpec(this, _onClose, {
94
- writable: true,
95
- value: () => {
96
- this.dispatchEvent(new CustomEvent('-close'));
97
- }
98
- });
99
-
100
- _classPrivateFieldInitSpec(this, _onReactClose, {
101
- writable: true,
102
- value: e => {
103
- getReactEventHandler(this, 'onClose')?.();
104
- getReactEventHandler(this, 'on-close')?.(e);
105
- }
106
- });
107
-
108
14
  const shadowRoot = this.attachShadow();
109
15
  shadowRoot.appendChild(template.content.cloneNode(true));
110
-
111
- _classPrivateFieldSet(this, _$optionSlot, shadowRoot.querySelector('slot[name="option"]'));
112
-
113
- _classPrivateFieldSet(this, _$listbox, shadowRoot.querySelector('#listbox'));
114
-
115
- _classPrivateFieldSet(this, _$popover, shadowRoot.querySelector('sinch-popover'));
16
+ this.#$optionSlot = shadowRoot.querySelector('slot');
17
+ this.#$listbox = shadowRoot.querySelector('#listbox');
116
18
  }
117
19
 
118
20
  connectedCallback() {
21
+ const {
22
+ signal
23
+ } = this.#controller;
119
24
  this.setAttribute('role', 'listbox');
120
- this.addEventListener('-close', _classPrivateFieldGet(this, _onReactClose));
25
+ this.setAttribute('tabindex', '0');
26
+ this.addEventListener('-keydown', this.#onContextKeyDown, {
27
+ signal
28
+ });
29
+ this.addEventListener('-visibility', this.#onContextVisibility, {
30
+ signal
31
+ });
32
+ this.addEventListener('keydown', this.#onListboxKeyDown, {
33
+ signal
34
+ });
35
+ this.addEventListener('blur', this.#onListboxBlur, {
36
+ signal
37
+ });
38
+ this.#$listbox.addEventListener('click', this.#onListboxClick, {
39
+ signal
40
+ });
41
+ this.dispatchEvent(new CustomEvent('-context-connect-keydown', {
42
+ bubbles: true
43
+ }));
44
+ this.dispatchEvent(new CustomEvent('-context-connect-visibility', {
45
+ bubbles: true
46
+ }));
121
47
  }
122
48
 
123
49
  disconnectedCallback() {
124
- this.removeEventListener('-close', _classPrivateFieldGet(this, _onReactClose));
50
+ this.dispatchEvent(new CustomEvent('-context-disconnect-keydown', {
51
+ bubbles: true
52
+ }));
53
+ this.dispatchEvent(new CustomEvent('-context-disconnect-visibility', {
54
+ bubbles: true
55
+ }));
56
+ this.#controller.abort();
125
57
  }
126
58
 
127
59
  static get observedAttributes() {
128
- return ['open', 'orientation', 'maxvisibleitems', 'modal'];
129
- }
130
-
131
- get nodeName() {
132
- return 'select';
133
- }
134
-
135
- set maxVisibleItems(value) {
136
- updateIntegerAttribute(this, 'maxvisibleitems', value);
137
- }
138
-
139
- get maxVisibleItems() {
140
- return getIntegerAttribute(this, 'maxvisibleitems', null);
60
+ return ['rows'];
141
61
  }
142
62
 
143
- get orientation() {
144
- return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom-right');
63
+ set rows(value) {
64
+ updateIntegerAttribute(this, 'rows', value);
145
65
  }
146
66
 
147
- set orientation(value) {
148
- updateLiteralAttribute(this, orientationValues, 'orientation', value);
149
- }
150
-
151
- set open(isOpen) {
152
- updateBooleanAttribute(this, 'open', isOpen);
153
- }
154
-
155
- get open() {
156
- return getBooleanAttribute(this, 'open');
157
- }
158
-
159
- set modal(isModal) {
160
- updateBooleanAttribute(this, 'modal', isModal);
161
- }
162
-
163
- get modal() {
164
- return getBooleanAttribute(this, 'modal');
165
- }
166
-
167
- get dropdownRect() {
168
- return _classPrivateFieldGet(this, _$popover).popoverRect;
67
+ get rows() {
68
+ return getIntegerAttribute(this, 'rows', null);
169
69
  }
170
70
 
171
71
  attributeChangedCallback(name, oldVal, newVal) {
72
+ if (oldVal === newVal) {
73
+ return;
74
+ }
75
+
172
76
  switch (name) {
173
- case 'open':
77
+ case 'rows':
174
78
  {
175
- updateAttribute(_classPrivateFieldGet(this, _$popover), 'open', newVal);
176
-
177
- if (isAttrTrue(newVal)) {
178
- _classPrivateFieldGet(this, _$popover).addEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
79
+ this.#$listbox.style.maxHeight = attrValueToPixels(newVal, {
80
+ min: 1,
81
+ itemSizeMultiplier: ITEM_HEIGHT
82
+ });
83
+ break;
84
+ }
85
+ }
86
+ }
179
87
 
180
- _classPrivateFieldGet(this, _$popover).addEventListener('-close', _classPrivateFieldGet(this, _onClose));
181
- } else {
182
- _classPrivateFieldGet(this, _$popover).removeEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
88
+ #onListboxBlur = () => {
89
+ this.#selectOption(null);
90
+ };
91
+ #onListboxClick = e => {
92
+ if (isSinchActionMenuOption(e.target)) {
93
+ this.#selectOption(e.target);
94
+ }
95
+ };
96
+ #onListboxKeyDown = e => {
97
+ this.#handleKeydown(e);
98
+ };
99
+ #onContextKeyDown = e => {
100
+ this.#handleKeydown(e.detail);
101
+ };
102
+ #onContextVisibility = e => {
103
+ if (!e.detail) {
104
+ this.#selectOption(null);
105
+ this.#$listbox.scrollTo({
106
+ top: 0,
107
+ behavior: 'auto'
108
+ });
109
+ }
110
+ };
183
111
 
184
- _classPrivateFieldGet(this, _$popover).removeEventListener('-close', _classPrivateFieldGet(this, _onClose));
112
+ #handleKeydown(e) {
113
+ switch (e.code) {
114
+ case 'Enter':
115
+ {
116
+ const $opt = this.#findSelectedOption();
185
117
 
186
- _classPrivateMethodGet(this, _selectOption, _selectOption2).call(this, null);
118
+ if ($opt !== null) {
119
+ e.preventDefault();
120
+ $opt.click();
187
121
  }
188
122
 
189
123
  break;
190
124
  }
191
125
 
192
- case 'orientation':
126
+ case 'ArrowUp':
193
127
  {
194
- updateAttribute(_classPrivateFieldGet(this, _$popover), 'orientation', newVal);
195
- break;
196
- }
197
-
198
- case 'maxvisibleitems':
199
- {
200
- if (newVal === '0') {
201
- _classPrivateFieldGet(this, _$listbox).style.maxHeight = 'unset';
202
- } else {
203
- _classPrivateFieldGet(this, _$listbox).style.maxHeight = attrValueToPixels(newVal, {
204
- min: 2,
205
- multiplier: ITEM_HEIGHT
206
- });
207
- }
208
-
128
+ e.preventDefault();
129
+ this.#selectOption(this.#getPrevOption());
209
130
  break;
210
131
  }
211
132
 
212
- case 'modal':
133
+ case 'ArrowDown':
213
134
  {
214
- updateBooleanAttribute(_classPrivateFieldGet(this, _$popover), 'modal', isAttrTrue(newVal));
135
+ e.preventDefault();
136
+ this.#selectOption(this.#getNextOption());
215
137
  break;
216
138
  }
217
139
  }
218
140
  }
219
141
 
220
- }));
142
+ #getFirstOption() {
143
+ const $options = this.#getOptionElements();
221
144
 
222
- function _getFirstOption2() {
223
- return _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this)[0] ?? null;
224
- }
145
+ for (let i = 0; i < $options.length; i++) {
146
+ const el = $options[i];
225
147
 
226
- function _getLastOption2() {
227
- return _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this).reverse()[0] ?? null;
228
- }
148
+ if (!getBooleanAttribute(el, 'disabled')) {
149
+ return el;
150
+ }
151
+ }
229
152
 
230
- function _getNextOption2() {
231
- const $options = _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this);
153
+ return null;
154
+ }
232
155
 
233
- const $selectedOption = _classPrivateMethodGet(this, _findSelectedOption, _findSelectedOption2).call(this, $options);
156
+ #getLastOption() {
157
+ const $options = this.#getOptionElements();
234
158
 
235
- const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
159
+ for (let i = $options.length - 1; i >= 0; i--) {
160
+ const el = $options[i];
236
161
 
237
- if (currentIndex < 0) {
238
- return _classPrivateMethodGet(this, _getFirstOption, _getFirstOption2).call(this);
162
+ if (!getBooleanAttribute(el, 'disabled')) {
163
+ return el;
164
+ }
165
+ }
166
+
167
+ return null;
239
168
  }
240
169
 
241
- return $options[(currentIndex + 1) % $options.length];
242
- }
170
+ #getNextOption() {
171
+ const index = this.#getSelectedOptionIndex();
243
172
 
244
- function _getPrevOption2() {
245
- const $options = _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this);
173
+ if (index !== null) {
174
+ const $options = this.#getOptionElements();
246
175
 
247
- const $selectedOption = _classPrivateMethodGet(this, _findSelectedOption, _findSelectedOption2).call(this, $options);
176
+ for (let i = 1; i <= $options.length; i++) {
177
+ const el = $options[(i + index) % $options.length];
248
178
 
249
- const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
179
+ if (!getBooleanAttribute(el, 'disabled')) {
180
+ return el;
181
+ }
182
+ }
183
+ }
250
184
 
251
- if (currentIndex < 0) {
252
- return _classPrivateMethodGet(this, _getLastOption, _getLastOption2).call(this);
185
+ return this.#getFirstOption();
253
186
  }
254
187
 
255
- return $options[(currentIndex - 1 + $options.length) % $options.length];
256
- }
188
+ #getPrevOption() {
189
+ const index = this.#getSelectedOptionIndex();
257
190
 
258
- function _selectOption2($option) {
259
- const hasMaxVisibleItems = this.hasAttribute('maxvisibleitems');
191
+ if (index !== null) {
192
+ const $options = this.#getOptionElements();
260
193
 
261
- for (const $op of _classPrivateMethodGet(this, _getOptionElements, _getOptionElements2).call(this)) {
262
- const isSelected = $op === $option;
263
- updateBooleanAttribute($op, 'data-selected', isSelected);
194
+ for (let i = 1; i <= $options.length; i++) {
195
+ const el = $options[(index - i + $options.length) % $options.length];
264
196
 
265
- if (isSelected && hasMaxVisibleItems) {
266
- $op.scrollIntoView?.({
267
- block: 'nearest'
268
- });
197
+ if (!getBooleanAttribute(el, 'disabled')) {
198
+ return el;
199
+ }
200
+ }
269
201
  }
202
+
203
+ return this.#getLastOption();
270
204
  }
271
- }
272
205
 
273
- function _getOptionElements2() {
274
- let $elements = _classPrivateFieldGet(this, _$optionSlot).assignedElements();
206
+ #selectOption($option) {
207
+ const hasRows = this.hasAttribute('rows');
275
208
 
276
- if ($elements.length === 1 && $elements[0].tagName === 'SLOT') {
277
- $elements = $elements[0].assignedElements();
209
+ for (const $op of this.#getOptionElements()) {
210
+ const isSelected = $op === $option;
211
+ updateBooleanAttribute($op, 'data-selected', isSelected);
212
+
213
+ if (isSelected && hasRows) {
214
+ $op.scrollIntoView?.({
215
+ block: 'nearest'
216
+ });
217
+ }
218
+ }
278
219
  }
279
220
 
280
- return $elements;
281
- }
221
+ #getOptionElements() {
222
+ return this.#$optionSlot.assignedElements();
223
+ }
282
224
 
283
- function _findSelectedOption2(elements) {
284
- for (const el of elements) {
285
- if (getBooleanAttribute(el, 'data-selected')) {
286
- return el;
225
+ #getSelectedOptionIndex() {
226
+ const elements = this.#getOptionElements();
227
+
228
+ for (let i = 0; i < elements.length; i++) {
229
+ const el = elements[i];
230
+
231
+ if (!getBooleanAttribute(el, 'disabled') && getBooleanAttribute(el, 'data-selected')) {
232
+ return i;
233
+ }
287
234
  }
235
+
236
+ return null;
288
237
  }
289
238
 
290
- return null;
291
- }
239
+ #findSelectedOption() {
240
+ const elements = this.#getOptionElements();
241
+
242
+ for (const el of elements) {
243
+ if (getBooleanAttribute(el, 'data-selected')) {
244
+ return el;
245
+ }
246
+ }
247
+
248
+ return null;
249
+ }
292
250
 
293
- function _getEnabledOptionElements2() {
294
- return _classPrivateMethodGet(this, _getOptionElements, _getOptionElements2).call(this).filter(opt => opt.disabled !== true);
295
- }
251
+ });
@@ -1,23 +1,13 @@
1
- import type { TSinchPopoverOrientation } from '../popover/types';
2
- import type { TRect, TSinchElementReact } from '../types';
1
+ import type { TSinchElementReact } from '../types';
3
2
  export declare type TSinchActionMenuElement = HTMLElement & {
4
- open: boolean;
5
- orientation: TSinchPopoverOrientation;
6
- maxVisibleItems: number | null;
7
- modal: boolean;
8
- readonly dropdownRect: TRect;
9
- addEventListener(type: '-close', listener: (e: CustomEvent<void>) => void): void;
10
- setAttribute(name: 'open', value: ''): void;
11
- setAttribute(name: 'orientation', value: TSinchPopoverOrientation): void;
12
- setAttribute(name: 'maxvisibleitems', value: string): void;
13
- setAttribute(name: 'modal', value: boolean): void;
3
+ /** How many rows to show and scroll the rest */
4
+ rows: number | null;
5
+ /** How many rows to show and scroll the rest */
6
+ setAttribute(name: 'rows', value: string): void;
14
7
  };
15
8
  export declare type TSinchActionMenuReact = TSinchElementReact<TSinchActionMenuElement> & {
16
- open: boolean;
17
- orientation?: TSinchPopoverOrientation;
18
- maxVisibleItems?: number;
19
- modal?: boolean;
9
+ /** How many rows to show and scroll the rest */
10
+ rows?: number;
11
+ /** Label that is used for a11y */
20
12
  'aria-label': string;
21
- onClose?: () => void;
22
- 'on-close'?: (e: CustomEvent<void>) => void;
23
13
  };
@@ -1,3 +1,4 @@
1
+ import '../text';
1
2
  import type { TSinchActionMenuOptionElement, TSinchActionMenuOptionReact } from './types';
2
3
  declare global {
3
4
  namespace JSX {
@@ -1,79 +1,40 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$wrapper, _$content, _onClick, _onMouseDown, _onClickReactHandler;
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, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
11
- const templateHTML = '<style>:host{display:block}#wrapper{all:initial;display:flex;position:relative;box-sizing:border-box;height:40px;width:100%;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;font:inherit;color:inherit;--sinch-size-icon:24px}#content{flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host(:hover)>#wrapper,:host([data-selected])>#wrapper{background-color:var(--sinch-color-snow-500)}:host([disabled]:not([disabled=false]))>#wrapper{color:var(--sinch-color-stormy-100);cursor:initial;pointer-events:none;--sinch-color-icon:var(--sinch-color-stormy-100)}::slotted(*){margin-left:-6px}</style><div id="wrapper"><slot name="icon"></slot><span id="content"></span></div>';
1
+ import '../text';
2
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
3
+ const templateHTML = '<style>:host{display:block}#wrapper{all:initial;display:flex;position:relative;box-sizing:border-box;height:40px;width:100%;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;color:var(--sinch-color-text-default);--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:24px}#content{flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host(:hover:not([disabled]))>#wrapper,:host([data-selected])>#wrapper{background-color:var(--sinch-color-snow-400)}:host([disabled])>#wrapper{cursor:initial;pointer-events:none;color:var(--sinch-color-text-disabled);--sinch-color-icon:var(--sinch-color-stormy-100)}::slotted(*){margin-left:-6px}</style><div id="wrapper"><slot name="icon"></slot><sinch-text id="content" type="m" ellipsis></sinch-text></div>';
12
4
  const template = document.createElement('template');
13
5
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-action-menu-option', (_$wrapper = new WeakMap(), _$content = new WeakMap(), _onClick = new WeakMap(), _onMouseDown = new WeakMap(), _onClickReactHandler = new WeakMap(), class ActionMenuOption extends NectaryElement {
6
+ defineCustomElement('sinch-action-menu-option', class ActionMenuOption extends NectaryElement {
7
+ #$wrapper;
8
+ #$content;
9
+ #controller = new AbortController();
10
+
15
11
  constructor() {
16
12
  super();
17
-
18
- _classPrivateFieldInitSpec(this, _$wrapper, {
19
- writable: true,
20
- value: void 0
21
- });
22
-
23
- _classPrivateFieldInitSpec(this, _$content, {
24
- writable: true,
25
- value: void 0
26
- });
27
-
28
- _classPrivateFieldInitSpec(this, _onClick, {
29
- writable: true,
30
- value: () => {
31
- this.dispatchEvent(new CustomEvent('-click'));
32
- }
33
- });
34
-
35
- _classPrivateFieldInitSpec(this, _onMouseDown, {
36
- writable: true,
37
- value: e => {
38
- e.preventDefault();
39
- e.stopPropagation();
40
- this.click();
41
- }
42
- });
43
-
44
- _classPrivateFieldInitSpec(this, _onClickReactHandler, {
45
- writable: true,
46
- value: e => {
47
- getReactEventHandler(this, 'on-click')?.(e);
48
- }
49
- });
50
-
51
13
  const shadowRoot = this.attachShadow();
52
14
  shadowRoot.appendChild(template.content.cloneNode(true));
53
-
54
- _classPrivateFieldSet(this, _$wrapper, shadowRoot.querySelector('#wrapper'));
55
-
56
- _classPrivateFieldSet(this, _$content, shadowRoot.querySelector('#content'));
15
+ this.#$wrapper = shadowRoot.querySelector('#wrapper');
16
+ this.#$content = shadowRoot.querySelector('#content');
57
17
  }
58
18
 
59
19
  connectedCallback() {
20
+ const {
21
+ signal
22
+ } = this.#controller;
60
23
  this.setAttribute('role', 'option');
61
-
62
- _classPrivateFieldGet(this, _$wrapper).addEventListener('mousedown', _classPrivateFieldGet(this, _onMouseDown));
63
-
64
- this.addEventListener('-click', _classPrivateFieldGet(this, _onClickReactHandler));
65
- this.addEventListener('click', _classPrivateFieldGet(this, _onClick));
24
+ this.#$wrapper.addEventListener('mousedown', this.#onMouseDown, {
25
+ signal
26
+ });
27
+ this.addEventListener('-click', this.#onClickReactHandler, {
28
+ signal
29
+ });
66
30
  }
67
31
 
68
32
  disconnectedCallback() {
69
- _classPrivateFieldGet(this, _$wrapper).removeEventListener('mousedown', _classPrivateFieldGet(this, _onMouseDown));
70
-
71
- this.removeEventListener('-click', _classPrivateFieldGet(this, _onClickReactHandler));
72
- this.removeEventListener('click', _classPrivateFieldGet(this, _onClick));
33
+ this.#controller.abort();
73
34
  }
74
35
 
75
36
  static get observedAttributes() {
76
- return ['text', 'disabled'];
37
+ return ['text', 'disabled', 'data-selected'];
77
38
  }
78
39
 
79
40
  attributeChangedCallback(name, oldVal, newVal) {
@@ -84,7 +45,7 @@ defineCustomElement('sinch-action-menu-option', (_$wrapper = new WeakMap(), _$co
84
45
  switch (name) {
85
46
  case 'text':
86
47
  {
87
- _classPrivateFieldGet(this, _$content).textContent = newVal;
48
+ this.#$content.textContent = newVal;
88
49
  break;
89
50
  }
90
51
 
@@ -93,6 +54,19 @@ defineCustomElement('sinch-action-menu-option', (_$wrapper = new WeakMap(), _$co
93
54
  updateBooleanAttribute(this, 'disabled', isAttrTrue(newVal));
94
55
  break;
95
56
  }
57
+
58
+ case 'data-selected':
59
+ {
60
+ const isDisabled = getBooleanAttribute(this, 'disabled');
61
+
62
+ if (isDisabled) {
63
+ updateBooleanAttribute(this, 'aria-selected', false);
64
+ } else {
65
+ updateExplicitBooleanAttribute(this, 'aria-selected', isAttrTrue(newVal));
66
+ }
67
+
68
+ break;
69
+ }
96
70
  }
97
71
  }
98
72
 
@@ -112,4 +86,19 @@ defineCustomElement('sinch-action-menu-option', (_$wrapper = new WeakMap(), _$co
112
86
  return getBooleanAttribute(this, 'disabled');
113
87
  }
114
88
 
115
- }));
89
+ click() {
90
+ this.#dispatchClickEvent();
91
+ }
92
+
93
+ #onMouseDown = () => {
94
+ this.#dispatchClickEvent();
95
+ };
96
+
97
+ #dispatchClickEvent() {
98
+ this.dispatchEvent(new CustomEvent('-click'));
99
+ }
100
+
101
+ #onClickReactHandler = e => {
102
+ getReactEventHandler(this, 'on-click')?.(e);
103
+ };
104
+ });