@nectary/components 0.24.0 → 0.25.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/colors.json +2 -0
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +3 -5
- package/search/index.js +37 -22
- package/segment-collapse/index.js +12 -30
- package/segmented-control/index.d.ts +20 -0
- package/segmented-control/index.js +208 -0
- package/segmented-control-option/index.d.ts +29 -0
- package/segmented-control-option/index.js +112 -0
- package/tabs/index.js +1 -1
- package/tabs-option/index.js +10 -26
package/colors.json
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"colorTropical300": "#66AAAA",
|
|
14
14
|
"colorTropical200": "#99C6C6",
|
|
15
15
|
"colorTropical100": "#CCE3E3",
|
|
16
|
+
"colorTropical50": "#E5F1F1",
|
|
16
17
|
"colorStormy600": "#061927",
|
|
17
18
|
"colorStormy500": "#0A273D",
|
|
18
19
|
"colorStormy400": "#3B5264",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"colorRaspberry300": "#EE778B",
|
|
32
33
|
"colorRaspberry200": "#F4A4B1",
|
|
33
34
|
"colorRaspberry100": "#F9D2D8",
|
|
35
|
+
"colorRaspberry50": "#FCE8EB",
|
|
34
36
|
"colorTextDefault": "#0A273D",
|
|
35
37
|
"colorTextInverted": "#FFFFFF",
|
|
36
38
|
"colorTextMuted": "#677784",
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nectary/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"theme.css",
|
|
6
6
|
"**/*/*.js",
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
"colors.json"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
17
|
-
"build": "NODE_ENV=production babel . --extensions '.ts' --ignore '*.d.ts' --out-dir .",
|
|
18
|
-
"postbuild": "tsc"
|
|
16
|
+
"build": "NODE_ENV=production babel . --extensions '.ts' --out-dir . && tsc"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
19
|
"@babel/runtime": "^7.17.0",
|
|
@@ -29,8 +27,8 @@
|
|
|
29
27
|
"@babel/preset-typescript": "^7.16.0",
|
|
30
28
|
"@types/node": "^17.0.14",
|
|
31
29
|
"@types/react": "^17.0.0",
|
|
30
|
+
"babel-plugin-html-inline-minifier": "workspace:babel-plugin-html-inline-minifier@*",
|
|
32
31
|
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
|
|
33
|
-
"rimraf": "^3.0.2",
|
|
34
32
|
"typescript": "^4.4.2"
|
|
35
33
|
}
|
|
36
34
|
}
|
package/search/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
2
|
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
3
|
|
|
4
|
-
var _$label, _$input, _selectionStart, _selectionEnd, _$optionSlot, _$listbox, _$clear, _isPendingDk, _onCompositionStart, _onInput, _onValueChange, _onClearMouseDown, _onClear, _onInputFocus, _onInputBlur, _onListboxClick,
|
|
4
|
+
var _$label, _$input, _selectionStart, _selectionEnd, _$optionSlot, _$listbox, _$clear, _isPendingDk, _sh, _onCompositionStart, _onInput, _onValueChange, _onClearMouseDown, _onClear, _onInputFocus, _onInputBlur, _onListboxClick, _onListboxKeyUp, _onListboxKeyDown, _onOptionSlotChange, _onExpand, _onCollapse, _setOpen, _isOpen, _getFirstOption, _getLastOption, _getNextOption, _getPrevOption, _selectOption, _getOptionElements;
|
|
5
5
|
|
|
6
6
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
7
7
|
|
|
@@ -12,8 +12,8 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
|
|
|
12
12
|
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
13
13
|
|
|
14
14
|
import { isSearchOptionElement } from '../search-option';
|
|
15
|
-
import { attrValueToPixels, defineCustomElement, getAttribute, getIntegerAttribute, getRect, NectaryElement, updateAttribute, updateIntegerAttribute } from '../utils';
|
|
16
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;width:100%;box-sizing:border-box;--sinch-size-icon:24px}#label{display:none;font:var(--sinch-font-title-s);color:var(--sinch-color-text-default);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:100%;height:24px;margin-bottom:2px}#input{all:initial;display:block;border:1px solid var(--sinch-color-stormy-200);box-sizing:border-box;border-radius:4px;width:100%;height:48px;padding:0 44px;padding-right:12px;font:var(--sinch-font-body);color:var(--sinch-color-text-default);caret-color:var(--sinch-caret-color,auto);background-color:var(--sinch-color-snow-100)}#input::placeholder{font:var(--sinch-font-body);color:var(--sinch-color-text-muted)}#input:focus{border-color:var(--sinch-color-stormy-600)}#icon-search{position:absolute;left:12px;top:12px;pointer-events:none;--sinch-color-icon:var(--sinch-color-stormy-500)}#clear{position:absolute;right:8px;top:8px;display:none;--sinch-color-icon:red}#clear:focus{--sinch-color-icon:var(--sinch-color-stormy-500)}:host([value]:not([value=""])) #clear{display:flex}:host([value]:not([value=""])) #input{padding-right:44px}#listbox{display:none;position:absolute;z-index:1;left:0;top:calc(100% + 8px);width:100%;box-sizing:border-box;font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);box-shadow:1px 2px 4px rgba(0,0,0,.15);overflow-y:auto
|
|
15
|
+
import { attrValueToPixels, defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, getRect, NectaryElement, updateAttribute, updateIntegerAttribute } from '../utils';
|
|
16
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;width:100%;box-sizing:border-box;--sinch-size-icon:24px}#label{display:none;font:var(--sinch-font-title-s);color:var(--sinch-color-text-default);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:100%;height:24px;margin-bottom:2px}#input{all:initial;display:block;border:1px solid var(--sinch-color-stormy-200);box-sizing:border-box;border-radius:4px;width:100%;height:48px;padding:0 44px;padding-right:12px;font:var(--sinch-font-body);color:var(--sinch-color-text-default);caret-color:var(--sinch-caret-color,auto);background-color:var(--sinch-color-snow-100)}#input::placeholder{font:var(--sinch-font-body);color:var(--sinch-color-text-muted)}#input:focus{border-color:var(--sinch-color-stormy-600)}#icon-search{position:absolute;left:12px;top:12px;pointer-events:none;--sinch-color-icon:var(--sinch-color-stormy-500)}#clear{position:absolute;right:8px;top:8px;display:none;--sinch-color-icon:red}#clear:focus{--sinch-color-icon:var(--sinch-color-stormy-500)}:host([value]:not([value=""])) #clear{display:flex}:host([value]:not([value=""])) #input{padding-right:44px}#listbox{display:none;position:absolute;z-index:1;left:0;top:calc(100% + 8px);width:100%;box-sizing:border-box;font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);box-shadow:1px 2px 4px rgba(0,0,0,.15);overflow-y:auto}:host([aria-expanded=true]) #listbox{display:block}:host([label]:not([label=""])) #label{display:block}</style><label id="label" for="input"></label><div id="wrapper"><input id="input" type="text"/><sinch-icon-search id="icon-search"></sinch-icon-search><sinch-icon-button id="clear" small><sinch-icon-close id="icon-close" slot="icon"></sinch-icon-close></sinch-icon-button><div id="listbox"><slot name="option"></slot></div></div>';
|
|
17
17
|
import '../icons/search';
|
|
18
18
|
import '../icons/close';
|
|
19
19
|
import '../icon-button';
|
|
@@ -31,7 +31,7 @@ const findSelectedOption = elements => {
|
|
|
31
31
|
|
|
32
32
|
const template = document.createElement('template');
|
|
33
33
|
template.innerHTML = templateHTML;
|
|
34
|
-
defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new WeakMap(), _selectionStart = new WeakMap(), _selectionEnd = new WeakMap(), _$optionSlot = new WeakMap(), _$listbox = new WeakMap(), _$clear = new WeakMap(), _isPendingDk = new WeakMap(), _onCompositionStart = new WeakMap(), _onInput = new WeakMap(), _onValueChange = new WeakSet(), _onClearMouseDown = new WeakMap(), _onClear = new WeakMap(), _onInputFocus = new WeakMap(), _onInputBlur = new WeakMap(), _onListboxClick = new WeakMap(),
|
|
34
|
+
defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new WeakMap(), _selectionStart = new WeakMap(), _selectionEnd = new WeakMap(), _$optionSlot = new WeakMap(), _$listbox = new WeakMap(), _$clear = new WeakMap(), _isPendingDk = new WeakMap(), _sh = new WeakMap(), _onCompositionStart = new WeakMap(), _onInput = new WeakMap(), _onValueChange = new WeakSet(), _onClearMouseDown = new WeakMap(), _onClear = new WeakMap(), _onInputFocus = new WeakMap(), _onInputBlur = new WeakMap(), _onListboxClick = new WeakMap(), _onListboxKeyUp = new WeakMap(), _onListboxKeyDown = new WeakMap(), _onOptionSlotChange = new WeakMap(), _onExpand = new WeakSet(), _onCollapse = new WeakSet(), _setOpen = new WeakSet(), _isOpen = new WeakSet(), _getFirstOption = new WeakSet(), _getLastOption = new WeakSet(), _getNextOption = new WeakSet(), _getPrevOption = new WeakSet(), _selectOption = new WeakSet(), _getOptionElements = new WeakSet(), class extends NectaryElement {
|
|
35
35
|
constructor() {
|
|
36
36
|
super();
|
|
37
37
|
|
|
@@ -47,6 +47,10 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
47
47
|
|
|
48
48
|
_classPrivateMethodInitSpec(this, _getFirstOption);
|
|
49
49
|
|
|
50
|
+
_classPrivateMethodInitSpec(this, _isOpen);
|
|
51
|
+
|
|
52
|
+
_classPrivateMethodInitSpec(this, _setOpen);
|
|
53
|
+
|
|
50
54
|
_classPrivateMethodInitSpec(this, _onCollapse);
|
|
51
55
|
|
|
52
56
|
_classPrivateMethodInitSpec(this, _onExpand);
|
|
@@ -93,6 +97,11 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
93
97
|
value: false
|
|
94
98
|
});
|
|
95
99
|
|
|
100
|
+
_classPrivateFieldInitSpec(this, _sh, {
|
|
101
|
+
writable: true,
|
|
102
|
+
value: void 0
|
|
103
|
+
});
|
|
104
|
+
|
|
96
105
|
_classPrivateFieldInitSpec(this, _onCompositionStart, {
|
|
97
106
|
writable: true,
|
|
98
107
|
value: () => {
|
|
@@ -155,7 +164,7 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
155
164
|
}
|
|
156
165
|
});
|
|
157
166
|
|
|
158
|
-
_classPrivateFieldInitSpec(this,
|
|
167
|
+
_classPrivateFieldInitSpec(this, _onListboxKeyUp, {
|
|
159
168
|
writable: true,
|
|
160
169
|
value: e => {
|
|
161
170
|
switch (e.code) {
|
|
@@ -182,8 +191,6 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
182
191
|
switch (e.code) {
|
|
183
192
|
case 'ArrowUp':
|
|
184
193
|
{
|
|
185
|
-
e.preventDefault();
|
|
186
|
-
|
|
187
194
|
_classPrivateMethodGet(this, _selectOption, _selectOption2).call(this, _classPrivateMethodGet(this, _getPrevOption, _getPrevOption2).call(this));
|
|
188
195
|
|
|
189
196
|
break;
|
|
@@ -191,8 +198,6 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
191
198
|
|
|
192
199
|
case 'ArrowDown':
|
|
193
200
|
{
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
|
|
196
201
|
_classPrivateMethodGet(this, _selectOption, _selectOption2).call(this, _classPrivateMethodGet(this, _getNextOption, _getNextOption2).call(this));
|
|
197
202
|
|
|
198
203
|
break;
|
|
@@ -213,6 +218,12 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
213
218
|
_classPrivateFieldInitSpec(this, _onOptionSlotChange, {
|
|
214
219
|
writable: true,
|
|
215
220
|
value: () => {
|
|
221
|
+
const elems = _classPrivateMethodGet(this, _getOptionElements, _getOptionElements2).call(this);
|
|
222
|
+
|
|
223
|
+
if (elems.length === 0) {
|
|
224
|
+
return _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
|
|
225
|
+
}
|
|
226
|
+
|
|
216
227
|
_classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
|
|
217
228
|
}
|
|
218
229
|
});
|
|
@@ -220,6 +231,8 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
220
231
|
const shadowRoot = this.attachShadow();
|
|
221
232
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
222
233
|
|
|
234
|
+
_classPrivateFieldSet(this, _sh, shadowRoot);
|
|
235
|
+
|
|
223
236
|
_classPrivateFieldSet(this, _$input, shadowRoot.querySelector('#input'));
|
|
224
237
|
|
|
225
238
|
_classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#label'));
|
|
@@ -246,9 +259,9 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
246
259
|
|
|
247
260
|
_classPrivateFieldGet(this, _$input).addEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
|
|
248
261
|
|
|
249
|
-
_classPrivateFieldGet(this, _$input).addEventListener('
|
|
262
|
+
_classPrivateFieldGet(this, _$input).addEventListener('keyup', _classPrivateFieldGet(this, _onListboxKeyUp));
|
|
250
263
|
|
|
251
|
-
_classPrivateFieldGet(this, _$listbox).addEventListener('
|
|
264
|
+
_classPrivateFieldGet(this, _$listbox).addEventListener('mousedown', _classPrivateFieldGet(this, _onListboxClick));
|
|
252
265
|
|
|
253
266
|
_classPrivateFieldGet(this, _$optionSlot).addEventListener('slotchange', _classPrivateFieldGet(this, _onOptionSlotChange));
|
|
254
267
|
|
|
@@ -268,9 +281,9 @@ defineCustomElement('sinch-search', (_$label = new WeakMap(), _$input = new Weak
|
|
|
268
281
|
|
|
269
282
|
_classPrivateFieldGet(this, _$input).removeEventListener('keydown', _classPrivateFieldGet(this, _onListboxKeyDown));
|
|
270
283
|
|
|
271
|
-
_classPrivateFieldGet(this, _$input).removeEventListener('
|
|
284
|
+
_classPrivateFieldGet(this, _$input).removeEventListener('keyup', _classPrivateFieldGet(this, _onListboxKeyUp));
|
|
272
285
|
|
|
273
|
-
_classPrivateFieldGet(this, _$listbox).removeEventListener('
|
|
286
|
+
_classPrivateFieldGet(this, _$listbox).removeEventListener('mousedown', _classPrivateFieldGet(this, _onListboxClick));
|
|
274
287
|
|
|
275
288
|
_classPrivateFieldGet(this, _$optionSlot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onOptionSlotChange));
|
|
276
289
|
|
|
@@ -444,21 +457,23 @@ function _onValueChange2(nextValue) {
|
|
|
444
457
|
}
|
|
445
458
|
|
|
446
459
|
function _onExpand2() {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
if (elems.length === 0 || this.getRootNode().activeElement !== this) {
|
|
450
|
-
_classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
|
|
460
|
+
if (!_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this) && _classPrivateFieldGet(this, _sh).activeElement === _classPrivateFieldGet(this, _$input)) {
|
|
461
|
+
_classPrivateMethodGet(this, _selectOption, _selectOption2).call(this, _classPrivateMethodGet(this, _getFirstOption, _getFirstOption2).call(this));
|
|
451
462
|
|
|
452
|
-
|
|
463
|
+
_classPrivateMethodGet(this, _setOpen, _setOpen2).call(this, true);
|
|
453
464
|
}
|
|
465
|
+
}
|
|
454
466
|
|
|
455
|
-
|
|
467
|
+
function _onCollapse2() {
|
|
468
|
+
_classPrivateMethodGet(this, _setOpen, _setOpen2).call(this, false);
|
|
469
|
+
}
|
|
456
470
|
|
|
457
|
-
|
|
471
|
+
function _setOpen2(isOpen) {
|
|
472
|
+
this.setAttribute('aria-expanded', String(isOpen));
|
|
458
473
|
}
|
|
459
474
|
|
|
460
|
-
function
|
|
461
|
-
this
|
|
475
|
+
function _isOpen2() {
|
|
476
|
+
return getBooleanAttribute(this, 'aria-expanded');
|
|
462
477
|
}
|
|
463
478
|
|
|
464
479
|
function _getFirstOption2() {
|
|
@@ -2,7 +2,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
2
2
|
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
3
3
|
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
4
4
|
|
|
5
|
-
var _$
|
|
5
|
+
var _$button;
|
|
6
6
|
|
|
7
7
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
8
8
|
|
|
@@ -10,27 +10,23 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
|
|
|
10
10
|
|
|
11
11
|
import '../icons/expand-less';
|
|
12
12
|
import '../icons/expand-more';
|
|
13
|
-
import { defineCustomElement, getBooleanAttribute,
|
|
14
|
-
const templateHTML = '<style>:host{display:contents;--sinch-size-icon:32px}
|
|
13
|
+
import { defineCustomElement, getBooleanAttribute, NectaryElement, updateBooleanAttribute } from '../utils';
|
|
14
|
+
const templateHTML = '<style>:host{display:contents;--sinch-size-icon:32px}button{all:initial;position:absolute;left:0;top:0;width:100%;height:100%;box-sizing:border-box;cursor:pointer}button:focus~sinch-icon-expand-less,button:focus~sinch-icon-expand-more{border-radius:4px;box-shadow:0 0 0 1px var(--sinch-color-stormy-500) inset}#up{display:block}#down{display:none}:host([value]:not([value=false])) #up{display:none}:host([value]:not([value=false])) #down{display:block}</style><button></button><sinch-icon-expand-less id="up"></sinch-icon-expand-less><sinch-icon-expand-more id="down"></sinch-icon-expand-more>';
|
|
15
15
|
const template = document.createElement('template');
|
|
16
16
|
template.innerHTML = templateHTML;
|
|
17
|
-
defineCustomElement('sinch-segment-collapse', (_$
|
|
17
|
+
defineCustomElement('sinch-segment-collapse', (_$button = new WeakMap(), class extends NectaryElement {
|
|
18
18
|
constructor() {
|
|
19
19
|
super();
|
|
20
20
|
|
|
21
|
-
_classPrivateFieldInitSpec(this, _$
|
|
21
|
+
_classPrivateFieldInitSpec(this, _$button, {
|
|
22
22
|
writable: true,
|
|
23
23
|
value: void 0
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
_defineProperty(this, '
|
|
26
|
+
_defineProperty(this, 'onClick', e => {
|
|
27
27
|
e.stopPropagation();
|
|
28
|
-
|
|
29
|
-
const isChecked = _classPrivateFieldGet(this, _$input).checked;
|
|
30
|
-
|
|
31
|
-
_classPrivateFieldGet(this, _$input).checked = this.value;
|
|
32
28
|
this.dispatchEvent(new CustomEvent('change', {
|
|
33
|
-
detail:
|
|
29
|
+
detail: !this.value,
|
|
34
30
|
bubbles: true
|
|
35
31
|
}));
|
|
36
32
|
});
|
|
@@ -38,17 +34,17 @@ defineCustomElement('sinch-segment-collapse', (_$input = new WeakMap(), class ex
|
|
|
38
34
|
const shadowRoot = this.attachShadow();
|
|
39
35
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
40
36
|
|
|
41
|
-
_classPrivateFieldSet(this, _$
|
|
37
|
+
_classPrivateFieldSet(this, _$button, shadowRoot.querySelector('button'));
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
connectedCallback() {
|
|
45
41
|
this.setAttribute('role', 'checkbox');
|
|
46
42
|
|
|
47
|
-
_classPrivateFieldGet(this, _$
|
|
43
|
+
_classPrivateFieldGet(this, _$button).addEventListener('click', this.onClick);
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
disconnectedCallback() {
|
|
51
|
-
_classPrivateFieldGet(this, _$
|
|
47
|
+
_classPrivateFieldGet(this, _$button).removeEventListener('click', this.onClick);
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
get type() {
|
|
@@ -59,20 +55,6 @@ defineCustomElement('sinch-segment-collapse', (_$input = new WeakMap(), class ex
|
|
|
59
55
|
return 'input';
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
static get observedAttributes() {
|
|
63
|
-
return ['value'];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
attributeChangedCallback(name, _, newVal) {
|
|
67
|
-
switch (name) {
|
|
68
|
-
case 'value':
|
|
69
|
-
{
|
|
70
|
-
_classPrivateFieldGet(this, _$input).checked = isAttrTrue(newVal);
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
58
|
set value(isChecked) {
|
|
77
59
|
updateBooleanAttribute(this, 'value', isChecked);
|
|
78
60
|
}
|
|
@@ -82,11 +64,11 @@ defineCustomElement('sinch-segment-collapse', (_$input = new WeakMap(), class ex
|
|
|
82
64
|
}
|
|
83
65
|
|
|
84
66
|
focus() {
|
|
85
|
-
_classPrivateFieldGet(this, _$
|
|
67
|
+
_classPrivateFieldGet(this, _$button).focus();
|
|
86
68
|
}
|
|
87
69
|
|
|
88
70
|
blur() {
|
|
89
|
-
_classPrivateFieldGet(this, _$
|
|
71
|
+
_classPrivateFieldGet(this, _$button).blur();
|
|
90
72
|
}
|
|
91
73
|
|
|
92
74
|
}));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
import type { SyntheticEvent } from 'react';
|
|
3
|
+
export declare type TSinchTabsElement = HTMLElement & {
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export declare type TSinchTabsReact = TSinchElementReact<TSinchTabsElement> & {
|
|
7
|
+
value: string;
|
|
8
|
+
'aria-label': string;
|
|
9
|
+
onChange: (event: SyntheticEvent<TSinchTabsElement, CustomEvent<string>>) => void;
|
|
10
|
+
};
|
|
11
|
+
declare global {
|
|
12
|
+
namespace JSX {
|
|
13
|
+
interface IntrinsicElements {
|
|
14
|
+
'sinch-segmented-control': TSinchTabsReact;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
interface HTMLElementTagNameMap {
|
|
18
|
+
'sinch-segmented-control': TSinchTabsElement;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
2
|
+
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
3
|
+
|
|
4
|
+
var _$slot, _onOptionKeyDown, _onSlotChange, _onOptionChange, _onValueChange, _dispatchChangeEvent, _getFirstOption, _getLastOption, _getNextOption, _getPrevOption, _getEnabledRadioElements;
|
|
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 { isSegmentedControlOptionElement } from '../segmented-control-option';
|
|
15
|
+
import { defineCustomElement, getAttribute, NectaryElement, updateAttribute } from '../utils';
|
|
16
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;width:100%;box-sizing:border-box}</style><div id="wrapper"><slot></slot></div>';
|
|
17
|
+
|
|
18
|
+
const findSelectedOption = elements => {
|
|
19
|
+
return elements.find(el => el.checked) ?? null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const template = document.createElement('template');
|
|
23
|
+
template.innerHTML = templateHTML;
|
|
24
|
+
defineCustomElement('sinch-segmented-control', (_$slot = new WeakMap(), _onOptionKeyDown = new WeakMap(), _onSlotChange = new WeakMap(), _onOptionChange = new WeakMap(), _onValueChange = new WeakSet(), _dispatchChangeEvent = new WeakSet(), _getFirstOption = new WeakSet(), _getLastOption = new WeakSet(), _getNextOption = new WeakSet(), _getPrevOption = new WeakSet(), _getEnabledRadioElements = new WeakSet(), class extends NectaryElement {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
|
|
28
|
+
_classPrivateMethodInitSpec(this, _getEnabledRadioElements);
|
|
29
|
+
|
|
30
|
+
_classPrivateMethodInitSpec(this, _getPrevOption);
|
|
31
|
+
|
|
32
|
+
_classPrivateMethodInitSpec(this, _getNextOption);
|
|
33
|
+
|
|
34
|
+
_classPrivateMethodInitSpec(this, _getLastOption);
|
|
35
|
+
|
|
36
|
+
_classPrivateMethodInitSpec(this, _getFirstOption);
|
|
37
|
+
|
|
38
|
+
_classPrivateMethodInitSpec(this, _dispatchChangeEvent);
|
|
39
|
+
|
|
40
|
+
_classPrivateMethodInitSpec(this, _onValueChange);
|
|
41
|
+
|
|
42
|
+
_classPrivateFieldInitSpec(this, _$slot, {
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
_classPrivateFieldInitSpec(this, _onOptionKeyDown, {
|
|
48
|
+
writable: true,
|
|
49
|
+
value: e => {
|
|
50
|
+
switch (e.code) {
|
|
51
|
+
case 'ArrowUp':
|
|
52
|
+
case 'ArrowLeft':
|
|
53
|
+
{
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
|
|
56
|
+
const $option = _classPrivateMethodGet(this, _getPrevOption, _getPrevOption2).call(this);
|
|
57
|
+
|
|
58
|
+
if ($option !== null) {
|
|
59
|
+
$option.focus();
|
|
60
|
+
|
|
61
|
+
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, $option.value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
case 'ArrowDown':
|
|
68
|
+
case 'ArrowRight':
|
|
69
|
+
{
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
|
|
72
|
+
const $option = _classPrivateMethodGet(this, _getNextOption, _getNextOption2).call(this);
|
|
73
|
+
|
|
74
|
+
if ($option !== null) {
|
|
75
|
+
$option.focus();
|
|
76
|
+
|
|
77
|
+
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, $option.value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
_classPrivateFieldInitSpec(this, _onSlotChange, {
|
|
87
|
+
writable: true,
|
|
88
|
+
value: () => {
|
|
89
|
+
_classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, this.value);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
_classPrivateFieldInitSpec(this, _onOptionChange, {
|
|
94
|
+
writable: true,
|
|
95
|
+
value: e => {
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
|
|
98
|
+
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, e.detail);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const shadowRoot = this.attachShadow();
|
|
103
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
104
|
+
shadowRoot.addEventListener('keydown', _classPrivateFieldGet(this, _onOptionKeyDown));
|
|
105
|
+
shadowRoot.addEventListener('change', _classPrivateFieldGet(this, _onOptionChange));
|
|
106
|
+
|
|
107
|
+
_classPrivateFieldSet(this, _$slot, shadowRoot.querySelector('slot'));
|
|
108
|
+
|
|
109
|
+
_classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
connectedCallback() {
|
|
113
|
+
this.setAttribute('role', 'tablist');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static get observedAttributes() {
|
|
117
|
+
return ['value'];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
get nodeName() {
|
|
121
|
+
return 'select';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
set value(value) {
|
|
125
|
+
updateAttribute(this, 'value', value);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
get value() {
|
|
129
|
+
return getAttribute(this, 'value', '');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
133
|
+
switch (name) {
|
|
134
|
+
case 'value':
|
|
135
|
+
{
|
|
136
|
+
_classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, newVal);
|
|
137
|
+
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
function _onValueChange2(value) {
|
|
146
|
+
for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
|
|
147
|
+
if (isSegmentedControlOptionElement($option)) {
|
|
148
|
+
$option.checked = $option.disabled !== true && $option.value === value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function _dispatchChangeEvent2(value) {
|
|
154
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
155
|
+
detail: value,
|
|
156
|
+
bubbles: true
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function _getFirstOption2() {
|
|
161
|
+
for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements()) {
|
|
162
|
+
if (isSegmentedControlOptionElement($option) && $option.disabled !== true) {
|
|
163
|
+
return $option;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function _getLastOption2() {
|
|
171
|
+
for (const $option of _classPrivateFieldGet(this, _$slot).assignedElements().reverse()) {
|
|
172
|
+
if (isSegmentedControlOptionElement($option) && $option.disabled !== true) {
|
|
173
|
+
return $option;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function _getNextOption2() {
|
|
181
|
+
const $options = _classPrivateMethodGet(this, _getEnabledRadioElements, _getEnabledRadioElements2).call(this);
|
|
182
|
+
|
|
183
|
+
const $selectedOption = findSelectedOption($options);
|
|
184
|
+
const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
|
|
185
|
+
|
|
186
|
+
if (currentIndex < 0) {
|
|
187
|
+
return _classPrivateMethodGet(this, _getFirstOption, _getFirstOption2).call(this);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return $options[(currentIndex + 1) % $options.length];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function _getPrevOption2() {
|
|
194
|
+
const $options = _classPrivateMethodGet(this, _getEnabledRadioElements, _getEnabledRadioElements2).call(this);
|
|
195
|
+
|
|
196
|
+
const $selectedOption = findSelectedOption($options);
|
|
197
|
+
const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
|
|
198
|
+
|
|
199
|
+
if (currentIndex < 0) {
|
|
200
|
+
return _classPrivateMethodGet(this, _getLastOption, _getLastOption2).call(this);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return $options[(currentIndex - 1 + $options.length) % $options.length];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function _getEnabledRadioElements2() {
|
|
207
|
+
return _classPrivateFieldGet(this, _$slot).assignedElements().filter(opt => isSegmentedControlOptionElement(opt) && opt.disabled !== true);
|
|
208
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
import type { FocusEvent } from 'react';
|
|
3
|
+
export declare const isSegmentedControlOptionElement: (element: EventTarget | Element | null) => element is TSinchSegmentedControlOptionElement;
|
|
4
|
+
export declare type TSinchSegmentedControlOptionElement = HTMLElement & {
|
|
5
|
+
value: string;
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
checked: boolean;
|
|
8
|
+
text: string;
|
|
9
|
+
focus(): void;
|
|
10
|
+
blur(): void;
|
|
11
|
+
};
|
|
12
|
+
export declare type TSinchSegmentedControlOptionReact = TSinchElementReact<TSinchSegmentedControlOptionElement> & {
|
|
13
|
+
value: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
text: string;
|
|
16
|
+
'aria-label': string;
|
|
17
|
+
onFocus?: (e: FocusEvent<TSinchSegmentedControlOptionElement>) => void;
|
|
18
|
+
onBlur?: (e: FocusEvent<TSinchSegmentedControlOptionElement>) => void;
|
|
19
|
+
};
|
|
20
|
+
declare global {
|
|
21
|
+
namespace JSX {
|
|
22
|
+
interface IntrinsicElements {
|
|
23
|
+
'sinch-segmented-control-option': TSinchSegmentedControlOptionReact;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
interface HTMLElementTagNameMap {
|
|
27
|
+
'sinch-segmented-control-option': TSinchSegmentedControlOptionElement;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
+
|
|
3
|
+
var _onClick;
|
|
4
|
+
|
|
5
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
6
|
+
|
|
7
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
8
|
+
|
|
9
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
10
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;position:relative;flex-direction:row;align-items:center;gap:12px;width:100%;height:42px;padding:8px 20px;box-sizing:border-box;border:1px solid var(--sinch-color-stormy-100);border-left-width:0;border-right-width:0;color:var(--sinch-color-stormy-500);background-color:var(--sinch-color-snow-100);--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:16px}#wrapper:hover{background-color:var(--sinch-color-snow-500)}:host(:first-child) #wrapper{border-left-width:1px;border-top-left-radius:4px;border-bottom-left-radius:4px}:host(:last-child) #wrapper{border-right-width:1px;border-top-right-radius:4px;border-bottom-right-radius:4px}#content{font:var(--sinch-font-title-s);flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host([checked]:not([checked=false])) #wrapper{border-color:var(--sinch-color-stormy-500)}:host([checked]:not([checked=false]):not(:first-child)) #wrapper::before{content:"";width:1px;background-color:var(--sinch-color-stormy-500);position:absolute;left:0;top:-1px;bottom:-1px}:host([checked]:not([checked=false]):not(:last-child)) #wrapper::after{content:"";width:1px;background-color:var(--sinch-color-stormy-500);position:absolute;right:0;top:-1px;bottom:-1px}#button{all:initial;position:absolute;left:0;top:0;box-sizing:border-box;width:100%;height:100%;cursor:pointer;z-index:1}#button:focus::before{content:"";position:absolute;left:-3px;right:-3px;top:-4px;bottom:-4px;border:2px solid var(--sinch-color-aqua-400)}#button:disabled{cursor:unset}:host(:first-child) #button:focus::before{left:-4px;border-top-left-radius:6px;border-bottom-left-radius:6px}:host(:last-child) #button:focus::before{right:-4px;border-top-right-radius:6px;border-bottom-right-radius:6px}:host([disabled]:not([disabled=false])) #wrapper{background-color:var(--sinch-color-snow-100);color:var(--sinch-color-stormy-100);--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><slot name="icon"></slot><label for="button" id="content"></label> <button id="button"></button></div>';
|
|
11
|
+
export const isSegmentedControlOptionElement = element => {
|
|
12
|
+
return element instanceof Element && element.tagName === 'SINCH-SEGMENTED-CONTROL-OPTION';
|
|
13
|
+
};
|
|
14
|
+
const template = document.createElement('template');
|
|
15
|
+
template.innerHTML = templateHTML;
|
|
16
|
+
defineCustomElement('sinch-segmented-control-option', (_onClick = new WeakMap(), class extends NectaryElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
_classPrivateFieldInitSpec(this, _onClick, {
|
|
21
|
+
writable: true,
|
|
22
|
+
value: e => {
|
|
23
|
+
e.stopPropagation();
|
|
24
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
25
|
+
bubbles: true,
|
|
26
|
+
detail: this.value
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const shadowRoot = this.attachShadow();
|
|
32
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
33
|
+
this.$button = shadowRoot.querySelector('#button');
|
|
34
|
+
this.$label = shadowRoot.querySelector('#content');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
this.setAttribute('role', 'tab');
|
|
39
|
+
this.$button.addEventListener('click', _classPrivateFieldGet(this, _onClick));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
disconnectedCallback() {
|
|
43
|
+
this.$button.removeEventListener('click', _classPrivateFieldGet(this, _onClick));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static get observedAttributes() {
|
|
47
|
+
return ['checked', 'disabled', 'text', 'value'];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
set checked(isChecked) {
|
|
51
|
+
updateBooleanAttribute(this, 'checked', isChecked);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get checked() {
|
|
55
|
+
return getBooleanAttribute(this, 'checked');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
set value(value) {
|
|
59
|
+
updateAttribute(this, 'value', value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get value() {
|
|
63
|
+
return getAttribute(this, 'value', '');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
set disabled(isDisabled) {
|
|
67
|
+
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get disabled() {
|
|
71
|
+
return getBooleanAttribute(this, 'disabled');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
set text(value) {
|
|
75
|
+
updateAttribute(this, 'text', value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get text() {
|
|
79
|
+
return getAttribute(this, 'text', '');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
attributeChangedCallback(name, _, newVal) {
|
|
83
|
+
switch (name) {
|
|
84
|
+
case 'text':
|
|
85
|
+
{
|
|
86
|
+
this.$label.textContent = newVal;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
case 'checked':
|
|
91
|
+
{
|
|
92
|
+
updateAttribute(this, 'aria-selected', isAttrTrue(newVal));
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
case 'disabled':
|
|
97
|
+
{
|
|
98
|
+
this.$button.disabled = isAttrTrue(newVal);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
focus() {
|
|
105
|
+
this.$button.focus();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
blur() {
|
|
109
|
+
this.$button.blur();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
}));
|
package/tabs/index.js
CHANGED
|
@@ -13,7 +13,7 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
|
|
|
13
13
|
|
|
14
14
|
import { isTabsOptionElement } from '../tabs-option';
|
|
15
15
|
import { defineCustomElement, getAttribute, NectaryElement, updateAttribute } from '../utils';
|
|
16
|
-
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;height:
|
|
16
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row;height:44px;width:100%;box-sizing:border-box}</style><div id="wrapper"><slot></slot></div>';
|
|
17
17
|
|
|
18
18
|
const findSelectedOption = elements => {
|
|
19
19
|
return elements.find(el => el.checked) ?? null;
|
package/tabs-option/index.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _onClick;
|
|
4
4
|
|
|
5
5
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
6
6
|
|
|
7
7
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
8
8
|
|
|
9
9
|
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
10
|
-
const templateHTML = '<style>:host{display:
|
|
10
|
+
const templateHTML = '<style>:host{display:block;outline:0}:host()>*{pointer-events:none}#wrapper{display:flex;flex-direction:row;align-items:center;gap:12px;position:relative;width:100%;height:42px;padding:8px 20px;box-sizing:border-box;box-shadow:0 1px 0 0 var(--sinch-color-stormy-100);color:var(--sinch-color-stormy-500);background-color:var(--sinch-color-snow-100);--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:16px}#content{font:var(--sinch-font-title-s);flex-shrink:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host([checked]:not([checked=false])) #wrapper{box-shadow:0 2px 0 0 var(--sinch-color-stormy-500)}#button{all:initial;position:absolute;left:0;top:0;box-sizing:border-box;width:100%;height:100%;cursor:pointer}#button:disabled{cursor:unset}:host([disabled]:not([disabled=false])) #wrapper{color:var(--sinch-color-stormy-100);--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><slot name="icon"></slot><label for="input" id="content"></label> <button id="button" type="radio"/></div>';
|
|
11
11
|
export const isTabsOptionElement = element => {
|
|
12
12
|
return element instanceof Element && element.tagName === 'SINCH-TABS-OPTION';
|
|
13
13
|
};
|
|
14
14
|
const template = document.createElement('template');
|
|
15
15
|
template.innerHTML = templateHTML;
|
|
16
|
-
defineCustomElement('sinch-tabs-option', (
|
|
16
|
+
defineCustomElement('sinch-tabs-option', (_onClick = new WeakMap(), class extends NectaryElement {
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
19
19
|
|
|
20
|
-
_classPrivateFieldInitSpec(this,
|
|
20
|
+
_classPrivateFieldInitSpec(this, _onClick, {
|
|
21
21
|
writable: true,
|
|
22
22
|
value: e => {
|
|
23
23
|
e.stopPropagation();
|
|
24
|
-
this.$input.checked = false;
|
|
25
24
|
this.dispatchEvent(new CustomEvent('change', {
|
|
26
25
|
bubbles: true,
|
|
27
26
|
detail: this.value
|
|
@@ -31,17 +30,17 @@ defineCustomElement('sinch-tabs-option', (_onInput = new WeakMap(), class extend
|
|
|
31
30
|
|
|
32
31
|
const shadowRoot = this.attachShadow();
|
|
33
32
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
34
|
-
this.$
|
|
33
|
+
this.$button = shadowRoot.querySelector('#button');
|
|
35
34
|
this.$label = shadowRoot.querySelector('#content');
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
connectedCallback() {
|
|
39
38
|
this.setAttribute('role', 'tab');
|
|
40
|
-
this.$
|
|
39
|
+
this.$button.addEventListener('click', _classPrivateFieldGet(this, _onClick));
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
disconnectedCallback() {
|
|
44
|
-
this.$
|
|
43
|
+
this.$button.removeEventListener('click', _classPrivateFieldGet(this, _onClick));
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
static get observedAttributes() {
|
|
@@ -90,39 +89,24 @@ defineCustomElement('sinch-tabs-option', (_onInput = new WeakMap(), class extend
|
|
|
90
89
|
|
|
91
90
|
case 'checked':
|
|
92
91
|
{
|
|
93
|
-
const isChecked = isAttrTrue(newVal);
|
|
94
|
-
this.$input.checked = isChecked;
|
|
95
|
-
|
|
96
|
-
if (isChecked) {
|
|
97
|
-
this.scrollIntoView?.({
|
|
98
|
-
block: 'nearest'
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
92
|
updateAttribute(this, 'aria-selected', isAttrTrue(newVal));
|
|
103
93
|
break;
|
|
104
94
|
}
|
|
105
95
|
|
|
106
96
|
case 'disabled':
|
|
107
97
|
{
|
|
108
|
-
this.$
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
case 'value':
|
|
113
|
-
{
|
|
114
|
-
this.$input.value = newVal ?? '';
|
|
98
|
+
this.$button.disabled = isAttrTrue(newVal);
|
|
115
99
|
break;
|
|
116
100
|
}
|
|
117
101
|
}
|
|
118
102
|
}
|
|
119
103
|
|
|
120
104
|
focus() {
|
|
121
|
-
this.$
|
|
105
|
+
this.$button.focus();
|
|
122
106
|
}
|
|
123
107
|
|
|
124
108
|
blur() {
|
|
125
|
-
this.$
|
|
109
|
+
this.$button.blur();
|
|
126
110
|
}
|
|
127
111
|
|
|
128
112
|
}));
|