@nectary/components 0.39.0 → 0.41.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 (142) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion-item/index.js +30 -53
  3. package/action-menu/index.d.ts +0 -1
  4. package/action-menu/index.js +177 -223
  5. package/action-menu/types.d.ts +8 -18
  6. package/action-menu-option/index.d.ts +1 -0
  7. package/action-menu-option/index.js +52 -62
  8. package/action-menu-option/types.d.ts +9 -0
  9. package/action-menu-option/utils.d.ts +2 -0
  10. package/action-menu-option/utils.js +3 -0
  11. package/alert/index.js +6 -20
  12. package/avatar/index.js +12 -31
  13. package/avatar-badge/index.js +8 -22
  14. package/avatar-status/index.js +1 -1
  15. package/button/index.js +46 -92
  16. package/button/types.d.ts +1 -1
  17. package/card/index.js +21 -59
  18. package/chat-avatar/index.js +8 -22
  19. package/chat-block/index.js +29 -69
  20. package/chat-bubble/index.js +6 -20
  21. package/checkbox/index.js +59 -107
  22. package/chip/index.d.ts +13 -0
  23. package/chip/index.js +140 -0
  24. package/chip/types.d.ts +37 -0
  25. package/color-menu/index.d.ts +14 -0
  26. package/color-menu/index.js +450 -0
  27. package/color-menu/types.d.ts +36 -0
  28. package/color-menu/utils.d.ts +1 -0
  29. package/color-menu/utils.js +15 -0
  30. package/color-swatch/index.d.ts +13 -0
  31. package/color-swatch/index.js +60 -0
  32. package/color-swatch/types.d.ts +11 -0
  33. package/colors.json +61 -49
  34. package/date-picker/index.js +162 -293
  35. package/dialog/index.js +70 -142
  36. package/field/index.js +44 -65
  37. package/file-drop/index.js +123 -200
  38. package/file-picker/index.d.ts +0 -1
  39. package/file-picker/index.js +55 -108
  40. package/file-status/index.js +15 -39
  41. package/help-tooltip/index.js +11 -28
  42. package/horizontal-stepper/index.js +33 -59
  43. package/horizontal-stepper-item/index.js +13 -37
  44. package/icon-button/index.d.ts +1 -0
  45. package/icon-button/index.js +51 -85
  46. package/icon-button/types.d.ts +16 -2
  47. package/icons-channel/notify/index.d.ts +11 -0
  48. package/icons-channel/notify/index.js +4 -0
  49. package/illustrations/create-illustration-class.js +1 -1
  50. package/inline-alert/index.js +29 -81
  51. package/input/index.js +117 -222
  52. package/link/index.js +51 -97
  53. package/list-item/index.js +1 -1
  54. package/package.json +12 -14
  55. package/pagination/index.js +113 -163
  56. package/pop/index.d.ts +11 -0
  57. package/pop/index.js +391 -0
  58. package/pop/types.d.ts +35 -0
  59. package/pop/utils.d.ts +7 -0
  60. package/pop/utils.js +18 -0
  61. package/popover/index.d.ts +1 -0
  62. package/popover/index.js +105 -314
  63. package/popover/types.d.ts +8 -1
  64. package/popover/utils.d.ts +5 -0
  65. package/popover/utils.js +17 -1
  66. package/progress/index.js +9 -28
  67. package/radio/index.js +103 -169
  68. package/radio-option/index.js +28 -48
  69. package/segment/index.js +49 -130
  70. package/segment-collapse/index.js +28 -49
  71. package/segmented-control/index.js +36 -73
  72. package/segmented-control-option/index.js +45 -87
  73. package/segmented-icon-control/index.js +47 -84
  74. package/segmented-icon-control-option/index.js +42 -79
  75. package/select-button/index.d.ts +13 -0
  76. package/select-button/index.js +158 -0
  77. package/select-button/types.d.ts +43 -0
  78. package/select-menu/index.d.ts +11 -0
  79. package/select-menu/index.js +345 -0
  80. package/select-menu/types.d.ts +29 -0
  81. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  82. package/select-menu-option/index.js +76 -0
  83. package/{select-option → select-menu-option}/types.d.ts +8 -9
  84. package/stop-events/index.js +7 -20
  85. package/table-head-cell/index.js +7 -21
  86. package/tabs/index.js +103 -165
  87. package/tabs-option/index.js +24 -44
  88. package/tag/index.d.ts +0 -1
  89. package/tag/index.js +35 -38
  90. package/tag/types.d.ts +12 -7
  91. package/textarea/index.js +96 -167
  92. package/theme.css +146 -49
  93. package/tile-control/index.js +55 -96
  94. package/tile-control-option/index.js +45 -87
  95. package/time-picker/index.js +216 -368
  96. package/title/index.js +6 -20
  97. package/toast/index.js +32 -70
  98. package/toast-manager/index.js +141 -217
  99. package/toggle/index.js +59 -107
  100. package/tooltip/index.d.ts +2 -0
  101. package/tooltip/index.js +160 -17
  102. package/tooltip/types.d.ts +13 -0
  103. package/tooltip/utils.d.ts +5 -0
  104. package/tooltip/utils.js +25 -1
  105. package/utils/animation.d.ts +17 -0
  106. package/utils/animation.js +142 -0
  107. package/utils/colors.d.ts +5 -0
  108. package/utils/colors.js +5 -0
  109. package/utils/context.d.ts +15 -0
  110. package/utils/context.js +57 -0
  111. package/{utils.d.ts → utils/index.d.ts} +15 -11
  112. package/{utils.js → utils/index.js} +104 -48
  113. package/vertical-stepper/index.js +29 -50
  114. package/vertical-stepper-item/index.js +13 -37
  115. package/dropdown/index.d.ts +0 -12
  116. package/dropdown/index.js +0 -415
  117. package/dropdown/types.d.ts +0 -32
  118. package/dropdown-checkbox-option/index.d.ts +0 -11
  119. package/dropdown-checkbox-option/index.js +0 -88
  120. package/dropdown-checkbox-option/types.d.ts +0 -15
  121. package/dropdown-radio-option/index.d.ts +0 -11
  122. package/dropdown-radio-option/index.js +0 -88
  123. package/dropdown-radio-option/types.d.ts +0 -15
  124. package/dropdown-text-option/index.js +0 -104
  125. package/dropdown-text-option/types.d.ts +0 -16
  126. package/select/index.d.ts +0 -13
  127. package/select/index.js +0 -316
  128. package/select/types.d.ts +0 -53
  129. package/select-option/index.d.ts +0 -11
  130. package/select-option/index.js +0 -8
  131. package/tag/utils.d.ts +0 -5
  132. package/tag/utils.js +0 -6
  133. package/tag-close/index.d.ts +0 -12
  134. package/tag-close/index.js +0 -42
  135. package/tag-close/types.d.ts +0 -5
  136. /package/{dropdown-checkbox-option → chip}/types.js +0 -0
  137. /package/{dropdown-radio-option → color-menu}/types.js +0 -0
  138. /package/{dropdown-text-option → color-swatch}/types.js +0 -0
  139. /package/{dropdown → pop}/types.js +0 -0
  140. /package/{select-option → select-button}/types.js +0 -0
  141. /package/{tag-close → select-menu}/types.js +0 -0
  142. /package/{select → select-menu-option}/types.js +0 -0
@@ -1,295 +1,249 @@
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
+ import { dispatchContextConnectEvent, dispatchContextDisconnectEvent } from '../utils/context';
4
+ const templateHTML = '<style>:host{display:block;outline:0}#listbox{overflow-y:auto}</style><div id="listbox" role="presentation"><slot></slot></div>';
18
5
  const ITEM_HEIGHT = 40;
19
6
  const template = document.createElement('template');
20
7
  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 {
8
+ defineCustomElement('sinch-action-menu', class extends NectaryElement {
9
+ #$optionSlot;
10
+ #$listbox;
11
+ #controller = null;
12
+
22
13
  constructor() {
23
14
  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
15
  const shadowRoot = this.attachShadow();
109
16
  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'));
17
+ this.#$optionSlot = shadowRoot.querySelector('slot');
18
+ this.#$listbox = shadowRoot.querySelector('#listbox');
116
19
  }
117
20
 
118
21
  connectedCallback() {
22
+ this.#controller = new AbortController();
23
+ const {
24
+ signal
25
+ } = this.#controller;
119
26
  this.setAttribute('role', 'listbox');
120
- this.addEventListener('-close', _classPrivateFieldGet(this, _onReactClose));
27
+ this.setAttribute('tabindex', '0');
28
+ this.addEventListener('-keydown', this.#onContextKeyDown, {
29
+ signal
30
+ });
31
+ this.addEventListener('-visibility', this.#onContextVisibility, {
32
+ signal
33
+ });
34
+ this.addEventListener('keydown', this.#onListboxKeyDown, {
35
+ signal
36
+ });
37
+ this.addEventListener('blur', this.#onListboxBlur, {
38
+ signal
39
+ });
40
+ this.#$listbox.addEventListener('click', this.#onListboxClick, {
41
+ signal
42
+ });
43
+ dispatchContextConnectEvent(this, 'keydown');
44
+ dispatchContextConnectEvent(this, 'visibility');
121
45
  }
122
46
 
123
47
  disconnectedCallback() {
124
- this.removeEventListener('-close', _classPrivateFieldGet(this, _onReactClose));
48
+ dispatchContextDisconnectEvent(this, 'keydown');
49
+ dispatchContextDisconnectEvent(this, 'visibility');
50
+ this.#controller.abort();
125
51
  }
126
52
 
127
53
  static get observedAttributes() {
128
- return ['open', 'orientation', 'maxvisibleitems', 'modal'];
54
+ return ['rows'];
129
55
  }
130
56
 
131
- get nodeName() {
132
- return 'select';
57
+ set rows(value) {
58
+ updateIntegerAttribute(this, 'rows', value);
133
59
  }
134
60
 
135
- set maxVisibleItems(value) {
136
- updateIntegerAttribute(this, 'maxvisibleitems', value);
137
- }
138
-
139
- get maxVisibleItems() {
140
- return getIntegerAttribute(this, 'maxvisibleitems', null);
141
- }
142
-
143
- get orientation() {
144
- return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom-right');
145
- }
146
-
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;
61
+ get rows() {
62
+ return getIntegerAttribute(this, 'rows', null);
169
63
  }
170
64
 
171
65
  attributeChangedCallback(name, oldVal, newVal) {
66
+ if (oldVal === newVal) {
67
+ return;
68
+ }
69
+
172
70
  switch (name) {
173
- case 'open':
71
+ case 'rows':
174
72
  {
175
- updateAttribute(_classPrivateFieldGet(this, _$popover), 'open', newVal);
176
-
177
- if (isAttrTrue(newVal)) {
178
- _classPrivateFieldGet(this, _$popover).addEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
73
+ this.#$listbox.style.maxHeight = attrValueToPixels(newVal, {
74
+ min: 1,
75
+ itemSizeMultiplier: ITEM_HEIGHT
76
+ });
77
+ break;
78
+ }
79
+ }
80
+ }
179
81
 
180
- _classPrivateFieldGet(this, _$popover).addEventListener('-close', _classPrivateFieldGet(this, _onClose));
181
- } else {
182
- _classPrivateFieldGet(this, _$popover).removeEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
82
+ #onListboxBlur = () => {
83
+ this.#selectOption(null);
84
+ };
85
+ #onListboxClick = e => {
86
+ if (isSinchActionMenuOption(e.target)) {
87
+ this.#selectOption(e.target);
88
+ }
89
+ };
90
+ #onListboxKeyDown = e => {
91
+ this.#handleKeydown(e);
92
+ };
93
+ #onContextKeyDown = e => {
94
+ this.#handleKeydown(e.detail);
95
+ };
96
+ #onContextVisibility = e => {
97
+ if (!e.detail) {
98
+ this.#selectOption(null);
99
+ this.#$listbox.scrollTo({
100
+ top: 0,
101
+ behavior: 'auto'
102
+ });
103
+ }
104
+ };
183
105
 
184
- _classPrivateFieldGet(this, _$popover).removeEventListener('-close', _classPrivateFieldGet(this, _onClose));
106
+ #handleKeydown(e) {
107
+ switch (e.code) {
108
+ case 'Enter':
109
+ {
110
+ const $opt = this.#findSelectedOption();
185
111
 
186
- _classPrivateMethodGet(this, _selectOption, _selectOption2).call(this, null);
112
+ if ($opt !== null) {
113
+ e.preventDefault();
114
+ $opt.click();
187
115
  }
188
116
 
189
117
  break;
190
118
  }
191
119
 
192
- case 'orientation':
120
+ case 'ArrowUp':
193
121
  {
194
- updateAttribute(_classPrivateFieldGet(this, _$popover), 'orientation', newVal);
122
+ e.preventDefault();
123
+ this.#selectOption(this.#getPrevOption());
195
124
  break;
196
125
  }
197
126
 
198
- case 'maxvisibleitems':
127
+ case 'ArrowDown':
199
128
  {
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
-
209
- break;
210
- }
211
-
212
- case 'modal':
213
- {
214
- updateBooleanAttribute(_classPrivateFieldGet(this, _$popover), 'modal', isAttrTrue(newVal));
129
+ e.preventDefault();
130
+ this.#selectOption(this.#getNextOption());
215
131
  break;
216
132
  }
217
133
  }
218
134
  }
219
135
 
220
- }));
136
+ #getFirstOption() {
137
+ const $options = this.#getOptionElements();
138
+
139
+ for (let i = 0; i < $options.length; i++) {
140
+ const el = $options[i];
221
141
 
222
- function _getFirstOption2() {
223
- return _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this)[0] ?? null;
224
- }
142
+ if (!getBooleanAttribute(el, 'disabled')) {
143
+ return el;
144
+ }
145
+ }
225
146
 
226
- function _getLastOption2() {
227
- return _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this).reverse()[0] ?? null;
228
- }
147
+ return null;
148
+ }
229
149
 
230
- function _getNextOption2() {
231
- const $options = _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this);
150
+ #getLastOption() {
151
+ const $options = this.#getOptionElements();
232
152
 
233
- const $selectedOption = _classPrivateMethodGet(this, _findSelectedOption, _findSelectedOption2).call(this, $options);
153
+ for (let i = $options.length - 1; i >= 0; i--) {
154
+ const el = $options[i];
234
155
 
235
- const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
156
+ if (!getBooleanAttribute(el, 'disabled')) {
157
+ return el;
158
+ }
159
+ }
236
160
 
237
- if (currentIndex < 0) {
238
- return _classPrivateMethodGet(this, _getFirstOption, _getFirstOption2).call(this);
161
+ return null;
239
162
  }
240
163
 
241
- return $options[(currentIndex + 1) % $options.length];
242
- }
164
+ #getNextOption() {
165
+ const index = this.#getSelectedOptionIndex();
243
166
 
244
- function _getPrevOption2() {
245
- const $options = _classPrivateMethodGet(this, _getEnabledOptionElements, _getEnabledOptionElements2).call(this);
167
+ if (index !== null) {
168
+ const $options = this.#getOptionElements();
246
169
 
247
- const $selectedOption = _classPrivateMethodGet(this, _findSelectedOption, _findSelectedOption2).call(this, $options);
170
+ for (let i = 1; i <= $options.length; i++) {
171
+ const el = $options[(i + index) % $options.length];
248
172
 
249
- const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
173
+ if (!getBooleanAttribute(el, 'disabled')) {
174
+ return el;
175
+ }
176
+ }
177
+ }
250
178
 
251
- if (currentIndex < 0) {
252
- return _classPrivateMethodGet(this, _getLastOption, _getLastOption2).call(this);
179
+ return this.#getFirstOption();
253
180
  }
254
181
 
255
- return $options[(currentIndex - 1 + $options.length) % $options.length];
256
- }
182
+ #getPrevOption() {
183
+ const index = this.#getSelectedOptionIndex();
257
184
 
258
- function _selectOption2($option) {
259
- const hasMaxVisibleItems = this.hasAttribute('maxvisibleitems');
185
+ if (index !== null) {
186
+ const $options = this.#getOptionElements();
260
187
 
261
- for (const $op of _classPrivateMethodGet(this, _getOptionElements, _getOptionElements2).call(this)) {
262
- const isSelected = $op === $option;
263
- updateBooleanAttribute($op, 'data-selected', isSelected);
188
+ for (let i = 1; i <= $options.length; i++) {
189
+ const el = $options[(index - i + $options.length) % $options.length];
264
190
 
265
- if (isSelected && hasMaxVisibleItems) {
266
- $op.scrollIntoView?.({
267
- block: 'nearest'
268
- });
191
+ if (!getBooleanAttribute(el, 'disabled')) {
192
+ return el;
193
+ }
194
+ }
269
195
  }
196
+
197
+ return this.#getLastOption();
270
198
  }
271
- }
272
199
 
273
- function _getOptionElements2() {
274
- let $elements = _classPrivateFieldGet(this, _$optionSlot).assignedElements();
200
+ #selectOption($option) {
201
+ const hasRows = this.hasAttribute('rows');
202
+
203
+ for (const $op of this.#getOptionElements()) {
204
+ const isSelected = $op === $option;
205
+ updateBooleanAttribute($op, 'data-selected', isSelected);
275
206
 
276
- if ($elements.length === 1 && $elements[0].tagName === 'SLOT') {
277
- $elements = $elements[0].assignedElements();
207
+ if (isSelected && hasRows) {
208
+ $op.scrollIntoView?.({
209
+ block: 'nearest'
210
+ });
211
+ }
212
+ }
213
+ }
214
+
215
+ #getOptionElements() {
216
+ return this.#$optionSlot.assignedElements();
278
217
  }
279
218
 
280
- return $elements;
281
- }
219
+ #getSelectedOptionIndex() {
220
+ const elements = this.#getOptionElements();
221
+
222
+ for (let i = 0; i < elements.length; i++) {
223
+ const el = elements[i];
282
224
 
283
- function _findSelectedOption2(elements) {
284
- for (const el of elements) {
285
- if (getBooleanAttribute(el, 'data-selected')) {
286
- return el;
225
+ if (!getBooleanAttribute(el, 'disabled') && getBooleanAttribute(el, 'data-selected')) {
226
+ return i;
227
+ }
287
228
  }
229
+
230
+ return null;
288
231
  }
289
232
 
290
- return null;
291
- }
233
+ #findSelectedOption() {
234
+ const elements = this.#getOptionElements();
235
+
236
+ for (const el of elements) {
237
+ if (getBooleanAttribute(el, 'data-selected')) {
238
+ return el;
239
+ }
240
+ }
241
+
242
+ return null;
243
+ }
244
+
245
+ get focusable() {
246
+ return true;
247
+ }
292
248
 
293
- function _getEnabledOptionElements2() {
294
- return _classPrivateMethodGet(this, _getOptionElements, _getOptionElements2).call(this).filter(opt => opt.disabled !== true);
295
- }
249
+ });
@@ -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,41 @@
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 = null;
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
+ this.#controller = new AbortController();
21
+ const {
22
+ signal
23
+ } = this.#controller;
60
24
  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));
25
+ this.#$wrapper.addEventListener('mousedown', this.#onMouseDown, {
26
+ signal
27
+ });
28
+ this.addEventListener('-click', this.#onClickReactHandler, {
29
+ signal
30
+ });
66
31
  }
67
32
 
68
33
  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));
34
+ this.#controller.abort();
73
35
  }
74
36
 
75
37
  static get observedAttributes() {
76
- return ['text', 'disabled'];
38
+ return ['text', 'disabled', 'data-selected'];
77
39
  }
78
40
 
79
41
  attributeChangedCallback(name, oldVal, newVal) {
@@ -84,7 +46,7 @@ defineCustomElement('sinch-action-menu-option', (_$wrapper = new WeakMap(), _$co
84
46
  switch (name) {
85
47
  case 'text':
86
48
  {
87
- _classPrivateFieldGet(this, _$content).textContent = newVal;
49
+ this.#$content.textContent = newVal;
88
50
  break;
89
51
  }
90
52
 
@@ -93,6 +55,19 @@ defineCustomElement('sinch-action-menu-option', (_$wrapper = new WeakMap(), _$co
93
55
  updateBooleanAttribute(this, 'disabled', isAttrTrue(newVal));
94
56
  break;
95
57
  }
58
+
59
+ case 'data-selected':
60
+ {
61
+ const isDisabled = getBooleanAttribute(this, 'disabled');
62
+
63
+ if (isDisabled) {
64
+ updateBooleanAttribute(this, 'aria-selected', false);
65
+ } else {
66
+ updateExplicitBooleanAttribute(this, 'aria-selected', isAttrTrue(newVal));
67
+ }
68
+
69
+ break;
70
+ }
96
71
  }
97
72
  }
98
73
 
@@ -112,4 +87,19 @@ defineCustomElement('sinch-action-menu-option', (_$wrapper = new WeakMap(), _$co
112
87
  return getBooleanAttribute(this, 'disabled');
113
88
  }
114
89
 
115
- }));
90
+ click() {
91
+ this.#dispatchClickEvent();
92
+ }
93
+
94
+ #onMouseDown = () => {
95
+ this.#dispatchClickEvent();
96
+ };
97
+
98
+ #dispatchClickEvent() {
99
+ this.dispatchEvent(new CustomEvent('-click'));
100
+ }
101
+
102
+ #onClickReactHandler = e => {
103
+ getReactEventHandler(this, 'on-click')?.(e);
104
+ };
105
+ });