@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.
- package/accordion/index.js +47 -84
- package/accordion/types.d.ts +1 -0
- package/accordion-item/index.js +26 -53
- package/action-menu/index.d.ts +0 -1
- package/action-menu/index.js +179 -223
- package/action-menu/types.d.ts +8 -18
- package/action-menu-option/index.d.ts +1 -0
- package/action-menu-option/index.js +51 -62
- package/action-menu-option/types.d.ts +9 -0
- package/action-menu-option/utils.d.ts +2 -0
- package/action-menu-option/utils.js +3 -0
- package/alert/index.js +6 -20
- package/avatar/index.js +12 -31
- package/avatar-badge/index.js +8 -22
- package/avatar-status/index.js +1 -1
- package/button/index.js +42 -92
- package/card/index.d.ts +2 -0
- package/card/index.js +24 -87
- package/chat-avatar/index.js +8 -22
- package/chat-block/index.js +29 -69
- package/chat-bubble/index.js +6 -20
- package/checkbox/index.js +55 -107
- package/chip/index.d.ts +13 -0
- package/chip/index.js +137 -0
- package/chip/types.d.ts +38 -0
- package/color-menu/index.d.ts +13 -0
- package/color-menu/index.js +464 -0
- package/color-menu/types.d.ts +37 -0
- package/color-swatch/index.d.ts +13 -0
- package/color-swatch/index.js +59 -0
- package/color-swatch/types.d.ts +12 -0
- package/colors.json +57 -49
- package/date-picker/index.js +196 -287
- package/date-picker/types.d.ts +25 -1
- package/dialog/index.d.ts +1 -0
- package/dialog/index.js +72 -143
- package/dropdown-checkbox-option/index.js +6 -20
- package/dropdown-radio-option/index.js +6 -20
- package/field/index.js +25 -63
- package/file-drop/index.js +123 -200
- package/file-picker/index.d.ts +0 -1
- package/file-picker/index.js +55 -108
- package/file-status/index.js +15 -39
- package/help-tooltip/index.js +1 -1
- package/horizontal-stepper/index.js +33 -59
- package/horizontal-stepper-item/index.js +13 -37
- package/icon-button/index.js +39 -84
- package/icons-channel/notify/index.d.ts +11 -0
- package/icons-channel/notify/index.js +4 -0
- package/illustrations/create-illustration-class.js +1 -1
- package/inline-alert/index.js +30 -82
- package/input/index.js +113 -222
- package/link/index.js +46 -96
- package/list-item/index.js +1 -1
- package/package.json +12 -14
- package/pagination/index.js +109 -163
- package/pagination/types.d.ts +1 -0
- package/popover/index.js +224 -294
- package/progress/index.js +9 -28
- package/radio/index.js +103 -169
- package/radio/types.d.ts +1 -0
- package/radio-option/index.js +24 -48
- package/segment/index.js +50 -131
- package/segment-collapse/index.js +24 -49
- package/segment-collapse/types.d.ts +1 -0
- package/segmented-control/index.js +36 -73
- package/segmented-control/types.d.ts +1 -0
- package/segmented-control-option/index.js +41 -87
- package/segmented-icon-control/index.js +47 -84
- package/segmented-icon-control/types.d.ts +1 -0
- package/segmented-icon-control-option/index.js +38 -79
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +153 -0
- package/select-button/types.d.ts +43 -0
- package/select-menu/index.d.ts +11 -0
- package/select-menu/index.js +346 -0
- package/select-menu/types.d.ts +29 -0
- package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
- package/select-menu-option/index.js +76 -0
- package/{select-option → select-menu-option}/types.d.ts +8 -9
- package/stop-events/index.js +7 -20
- package/table-head-cell/index.js +7 -21
- package/tabs/index.js +103 -165
- package/tabs/types.d.ts +1 -0
- package/tabs-option/index.js +20 -44
- package/tag/index.d.ts +1 -1
- package/tag/index.js +42 -36
- package/tag/types.d.ts +13 -7
- package/textarea/index.js +92 -167
- package/theme.css +80 -49
- package/tile-control/index.js +55 -96
- package/tile-control-option/index.js +40 -86
- package/time-picker/index.js +224 -368
- package/time-picker/types.d.ts +5 -1
- package/title/index.js +6 -20
- package/toast/index.d.ts +17 -0
- package/toast/index.js +115 -0
- package/toast/types.d.ts +28 -0
- package/toast/utils.d.ts +5 -0
- package/toast/utils.js +6 -0
- package/toast-manager/index.d.ts +17 -0
- package/toast-manager/index.js +195 -0
- package/toast-manager/types.d.ts +7 -0
- package/toggle/index.js +55 -108
- package/toggle/types.d.ts +1 -0
- package/types.d.ts +7 -0
- package/utils/colors.d.ts +10 -0
- package/utils/colors.js +121 -0
- package/{utils.d.ts → utils/index.d.ts} +18 -9
- package/{utils.js → utils/index.js} +118 -39
- package/vertical-stepper/index.js +29 -50
- package/vertical-stepper-item/index.js +13 -37
- package/card-button/index.d.ts +0 -11
- package/card-button/index.js +0 -77
- package/card-button/types.d.ts +0 -12
- package/card-link/index.d.ts +0 -12
- package/card-link/index.js +0 -115
- package/card-link/types.d.ts +0 -14
- package/dropdown/index.d.ts +0 -12
- package/dropdown/index.js +0 -415
- package/dropdown/types.d.ts +0 -30
- package/dropdown-text-option/index.js +0 -104
- package/dropdown-text-option/types.d.ts +0 -16
- package/search/index.d.ts +0 -14
- package/search/index.js +0 -523
- package/search/types.d.ts +0 -25
- package/search-option/index.d.ts +0 -11
- package/search-option/index.js +0 -55
- package/search-option/types.d.ts +0 -9
- package/select/index.d.ts +0 -13
- package/select/index.js +0 -316
- package/select/types.d.ts +0 -53
- package/select-option/index.d.ts +0 -11
- package/select-option/index.js +0 -8
- package/tag/utils.d.ts +0 -2
- package/tag/utils.js +0 -1
- package/tag-close/index.d.ts +0 -12
- package/tag-close/index.js +0 -38
- package/tag-close/types.d.ts +0 -3
- package/tag-close/types.js +0 -1
- /package/{card-button → chip}/types.js +0 -0
- /package/{card-link → color-menu}/types.js +0 -0
- /package/{dropdown-text-option → color-swatch}/types.js +0 -0
- /package/{dropdown → select-button}/types.js +0 -0
- /package/{search → select-menu}/types.js +0 -0
- /package/{search-option → select-menu-option}/types.js +0 -0
- /package/{select → toast}/types.js +0 -0
- /package/{select-option → toast-manager}/types.js +0 -0
package/action-menu/index.js
CHANGED
|
@@ -1,295 +1,251 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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',
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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 ['
|
|
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
|
-
|
|
144
|
-
|
|
63
|
+
set rows(value) {
|
|
64
|
+
updateIntegerAttribute(this, 'rows', value);
|
|
145
65
|
}
|
|
146
66
|
|
|
147
|
-
|
|
148
|
-
|
|
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 '
|
|
77
|
+
case 'rows':
|
|
174
78
|
{
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
79
|
+
this.#$listbox.style.maxHeight = attrValueToPixels(newVal, {
|
|
80
|
+
min: 1,
|
|
81
|
+
itemSizeMultiplier: ITEM_HEIGHT
|
|
82
|
+
});
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
179
87
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
112
|
+
#handleKeydown(e) {
|
|
113
|
+
switch (e.code) {
|
|
114
|
+
case 'Enter':
|
|
115
|
+
{
|
|
116
|
+
const $opt = this.#findSelectedOption();
|
|
185
117
|
|
|
186
|
-
|
|
118
|
+
if ($opt !== null) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
$opt.click();
|
|
187
121
|
}
|
|
188
122
|
|
|
189
123
|
break;
|
|
190
124
|
}
|
|
191
125
|
|
|
192
|
-
case '
|
|
126
|
+
case 'ArrowUp':
|
|
193
127
|
{
|
|
194
|
-
|
|
195
|
-
|
|
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 '
|
|
133
|
+
case 'ArrowDown':
|
|
213
134
|
{
|
|
214
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
145
|
+
for (let i = 0; i < $options.length; i++) {
|
|
146
|
+
const el = $options[i];
|
|
225
147
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
148
|
+
if (!getBooleanAttribute(el, 'disabled')) {
|
|
149
|
+
return el;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
229
152
|
|
|
230
|
-
|
|
231
|
-
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
232
155
|
|
|
233
|
-
|
|
156
|
+
#getLastOption() {
|
|
157
|
+
const $options = this.#getOptionElements();
|
|
234
158
|
|
|
235
|
-
|
|
159
|
+
for (let i = $options.length - 1; i >= 0; i--) {
|
|
160
|
+
const el = $options[i];
|
|
236
161
|
|
|
237
|
-
|
|
238
|
-
|
|
162
|
+
if (!getBooleanAttribute(el, 'disabled')) {
|
|
163
|
+
return el;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return null;
|
|
239
168
|
}
|
|
240
169
|
|
|
241
|
-
|
|
242
|
-
|
|
170
|
+
#getNextOption() {
|
|
171
|
+
const index = this.#getSelectedOptionIndex();
|
|
243
172
|
|
|
244
|
-
|
|
245
|
-
|
|
173
|
+
if (index !== null) {
|
|
174
|
+
const $options = this.#getOptionElements();
|
|
246
175
|
|
|
247
|
-
|
|
176
|
+
for (let i = 1; i <= $options.length; i++) {
|
|
177
|
+
const el = $options[(i + index) % $options.length];
|
|
248
178
|
|
|
249
|
-
|
|
179
|
+
if (!getBooleanAttribute(el, 'disabled')) {
|
|
180
|
+
return el;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
250
184
|
|
|
251
|
-
|
|
252
|
-
return _classPrivateMethodGet(this, _getLastOption, _getLastOption2).call(this);
|
|
185
|
+
return this.#getFirstOption();
|
|
253
186
|
}
|
|
254
187
|
|
|
255
|
-
|
|
256
|
-
|
|
188
|
+
#getPrevOption() {
|
|
189
|
+
const index = this.#getSelectedOptionIndex();
|
|
257
190
|
|
|
258
|
-
|
|
259
|
-
|
|
191
|
+
if (index !== null) {
|
|
192
|
+
const $options = this.#getOptionElements();
|
|
260
193
|
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
197
|
+
if (!getBooleanAttribute(el, 'disabled')) {
|
|
198
|
+
return el;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
269
201
|
}
|
|
202
|
+
|
|
203
|
+
return this.#getLastOption();
|
|
270
204
|
}
|
|
271
|
-
}
|
|
272
205
|
|
|
273
|
-
|
|
274
|
-
|
|
206
|
+
#selectOption($option) {
|
|
207
|
+
const hasRows = this.hasAttribute('rows');
|
|
275
208
|
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
|
|
281
|
-
|
|
221
|
+
#getOptionElements() {
|
|
222
|
+
return this.#$optionSlot.assignedElements();
|
|
223
|
+
}
|
|
282
224
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
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
|
-
|
|
294
|
-
return _classPrivateMethodGet(this, _getOptionElements, _getOptionElements2).call(this).filter(opt => opt.disabled !== true);
|
|
295
|
-
}
|
|
251
|
+
});
|
package/action-menu/types.d.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TRect, TSinchElementReact } from '../types';
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
3
2
|
export declare type TSinchActionMenuElement = HTMLElement & {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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,79 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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',
|
|
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
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
this.addEventListener('-click',
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
});
|