@nectary/components 0.39.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-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.js +21 -59
- 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 +161 -292
- package/dialog/index.js +70 -142
- 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 +29 -81
- 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/popover/index.js +224 -294
- package/progress/index.js +9 -28
- package/radio/index.js +103 -169
- package/radio-option/index.js +24 -48
- package/segment/index.js +49 -130
- package/segment-collapse/index.js +24 -49
- package/segmented-control/index.js +36 -73
- package/segmented-control-option/index.js +41 -87
- package/segmented-icon-control/index.js +47 -84
- 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/select-menu/types.js +1 -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-option/index.js +20 -44
- package/tag/index.d.ts +0 -1
- package/tag/index.js +37 -38
- 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 +216 -368
- package/title/index.js +6 -20
- package/toast/index.js +32 -70
- package/toast-manager/index.js +141 -217
- package/toggle/index.js +54 -106
- 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} +17 -9
- package/{utils.js → utils/index.js} +96 -39
- package/vertical-stepper/index.js +29 -50
- package/vertical-stepper-item/index.js +13 -37
- package/dropdown/index.d.ts +0 -12
- package/dropdown/index.js +0 -415
- package/dropdown/types.d.ts +0 -32
- package/dropdown-text-option/index.js +0 -104
- package/dropdown-text-option/types.d.ts +0 -16
- 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 -5
- package/tag/utils.js +0 -6
- package/tag-close/index.d.ts +0 -12
- package/tag-close/index.js +0 -42
- package/tag-close/types.d.ts +0 -5
- /package/{dropdown-text-option → chip}/types.js +0 -0
- /package/{dropdown → color-menu}/types.js +0 -0
- /package/{select-option → color-swatch}/types.js +0 -0
- /package/{select → select-button}/types.js +0 -0
- /package/{tag-close → select-menu-option}/types.js +0 -0
package/tabs/index.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$slot, _onOptionKeyDown, _onSlotChange, _onOptionChange, _onValueChange, _dispatchChangeEvent, _getFirstOption, _getLastOption, _getNextOption, _getPrevOption, _getEnabledRadioElements, _onChangeReactHandler;
|
|
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
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
15
2
|
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>';
|
|
16
3
|
|
|
@@ -20,117 +7,29 @@ const findSelectedOption = elements => {
|
|
|
20
7
|
|
|
21
8
|
const template = document.createElement('template');
|
|
22
9
|
template.innerHTML = templateHTML;
|
|
23
|
-
defineCustomElement('sinch-tabs',
|
|
10
|
+
defineCustomElement('sinch-tabs', class extends NectaryElement {
|
|
11
|
+
#$slot;
|
|
12
|
+
|
|
24
13
|
constructor() {
|
|
25
14
|
super();
|
|
26
|
-
|
|
27
|
-
_classPrivateMethodInitSpec(this, _getEnabledRadioElements);
|
|
28
|
-
|
|
29
|
-
_classPrivateMethodInitSpec(this, _getPrevOption);
|
|
30
|
-
|
|
31
|
-
_classPrivateMethodInitSpec(this, _getNextOption);
|
|
32
|
-
|
|
33
|
-
_classPrivateMethodInitSpec(this, _getLastOption);
|
|
34
|
-
|
|
35
|
-
_classPrivateMethodInitSpec(this, _getFirstOption);
|
|
36
|
-
|
|
37
|
-
_classPrivateMethodInitSpec(this, _dispatchChangeEvent);
|
|
38
|
-
|
|
39
|
-
_classPrivateMethodInitSpec(this, _onValueChange);
|
|
40
|
-
|
|
41
|
-
_classPrivateFieldInitSpec(this, _$slot, {
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
_classPrivateFieldInitSpec(this, _onOptionKeyDown, {
|
|
47
|
-
writable: true,
|
|
48
|
-
value: e => {
|
|
49
|
-
switch (e.code) {
|
|
50
|
-
case 'ArrowUp':
|
|
51
|
-
case 'ArrowLeft':
|
|
52
|
-
{
|
|
53
|
-
e.preventDefault();
|
|
54
|
-
|
|
55
|
-
const $option = _classPrivateMethodGet(this, _getPrevOption, _getPrevOption2).call(this);
|
|
56
|
-
|
|
57
|
-
if ($option !== null) {
|
|
58
|
-
$option.focus();
|
|
59
|
-
|
|
60
|
-
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, $option.value);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
case 'ArrowDown':
|
|
67
|
-
case 'ArrowRight':
|
|
68
|
-
{
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
|
|
71
|
-
const $option = _classPrivateMethodGet(this, _getNextOption, _getNextOption2).call(this);
|
|
72
|
-
|
|
73
|
-
if ($option !== null) {
|
|
74
|
-
$option.focus();
|
|
75
|
-
|
|
76
|
-
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, $option.value);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
_classPrivateFieldInitSpec(this, _onSlotChange, {
|
|
86
|
-
writable: true,
|
|
87
|
-
value: () => {
|
|
88
|
-
_classPrivateMethodGet(this, _onValueChange, _onValueChange2).call(this, this.value);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
_classPrivateFieldInitSpec(this, _onOptionChange, {
|
|
93
|
-
writable: true,
|
|
94
|
-
value: e => {
|
|
95
|
-
e.stopPropagation();
|
|
96
|
-
|
|
97
|
-
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, e.detail);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
_classPrivateFieldInitSpec(this, _onChangeReactHandler, {
|
|
102
|
-
writable: true,
|
|
103
|
-
value: e => {
|
|
104
|
-
getReactEventHandler(this, 'on-change')?.(e);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
15
|
const shadowRoot = this.attachShadow();
|
|
109
16
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
110
|
-
|
|
111
|
-
_classPrivateFieldSet(this, _$slot, shadowRoot.querySelector('slot'));
|
|
17
|
+
this.#$slot = shadowRoot.querySelector('slot');
|
|
112
18
|
}
|
|
113
19
|
|
|
114
20
|
connectedCallback() {
|
|
115
21
|
this.setAttribute('role', 'tablist');
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
_classPrivateFieldGet(this, _$slot).addEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
|
|
122
|
-
|
|
123
|
-
this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
|
|
22
|
+
this.#$slot.addEventListener('keydown', this.#onOptionKeyDown);
|
|
23
|
+
this.#$slot.addEventListener('option-change', this.#onOptionChange);
|
|
24
|
+
this.#$slot.addEventListener('slotchange', this.#onSlotChange);
|
|
25
|
+
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
124
26
|
}
|
|
125
27
|
|
|
126
28
|
disconnectedCallback() {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
_classPrivateFieldGet(this, _$slot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onSlotChange));
|
|
132
|
-
|
|
133
|
-
this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
|
|
29
|
+
this.#$slot.removeEventListener('keydown', this.#onOptionKeyDown);
|
|
30
|
+
this.#$slot.removeEventListener('option-change', this.#onOptionChange);
|
|
31
|
+
this.#$slot.removeEventListener('slotchange', this.#onSlotChange);
|
|
32
|
+
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
134
33
|
}
|
|
135
34
|
|
|
136
35
|
static get observedAttributes() {
|
|
@@ -153,78 +52,117 @@ defineCustomElement('sinch-tabs', (_$slot = new WeakMap(), _onOptionKeyDown = ne
|
|
|
153
52
|
switch (name) {
|
|
154
53
|
case 'value':
|
|
155
54
|
{
|
|
156
|
-
|
|
157
|
-
|
|
55
|
+
this.#onValueChange(newVal);
|
|
158
56
|
break;
|
|
159
57
|
}
|
|
160
58
|
}
|
|
161
59
|
}
|
|
162
60
|
|
|
163
|
-
|
|
61
|
+
#onOptionKeyDown = e => {
|
|
62
|
+
switch (e.code) {
|
|
63
|
+
case 'ArrowUp':
|
|
64
|
+
case 'ArrowLeft':
|
|
65
|
+
{
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
const $option = this.#getPrevOption();
|
|
68
|
+
|
|
69
|
+
if ($option !== null) {
|
|
70
|
+
$option.focus();
|
|
71
|
+
this.#dispatchChangeEvent($option.value);
|
|
72
|
+
}
|
|
164
73
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
case 'ArrowDown':
|
|
78
|
+
case 'ArrowRight':
|
|
79
|
+
{
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
const $option = this.#getNextOption();
|
|
82
|
+
|
|
83
|
+
if ($option !== null) {
|
|
84
|
+
$option.focus();
|
|
85
|
+
this.#dispatchChangeEvent($option.value);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
#onSlotChange = () => {
|
|
93
|
+
this.#onValueChange(this.value);
|
|
94
|
+
};
|
|
95
|
+
#onOptionChange = e => {
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
this.#dispatchChangeEvent(e.detail);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
#onValueChange(value) {
|
|
101
|
+
for (const $option of this.#$slot.assignedElements()) {
|
|
102
|
+
const isChecked = !getBooleanAttribute($option, 'disabled') && value === getAttribute($option, 'value', '');
|
|
103
|
+
updateBooleanAttribute($option, 'checked', isChecked);
|
|
186
104
|
}
|
|
187
105
|
}
|
|
188
106
|
|
|
189
|
-
|
|
190
|
-
|
|
107
|
+
#dispatchChangeEvent(value) {
|
|
108
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
109
|
+
detail: value,
|
|
110
|
+
bubbles: true
|
|
111
|
+
}));
|
|
112
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
113
|
+
detail: value
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
191
116
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
117
|
+
#getFirstOption() {
|
|
118
|
+
for (const $option of this.#$slot.assignedElements()) {
|
|
119
|
+
if ($option.disabled !== true) {
|
|
120
|
+
return $option;
|
|
121
|
+
}
|
|
196
122
|
}
|
|
123
|
+
|
|
124
|
+
return null;
|
|
197
125
|
}
|
|
198
126
|
|
|
199
|
-
|
|
200
|
-
|
|
127
|
+
#getLastOption() {
|
|
128
|
+
for (const $option of this.#$slot.assignedElements().reverse()) {
|
|
129
|
+
if ($option.disabled !== true) {
|
|
130
|
+
return $option;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
201
133
|
|
|
202
|
-
|
|
203
|
-
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
204
136
|
|
|
205
|
-
|
|
206
|
-
|
|
137
|
+
#getNextOption() {
|
|
138
|
+
const $options = this.#getEnabledRadioElements();
|
|
139
|
+
const $selectedOption = findSelectedOption($options);
|
|
140
|
+
const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
|
|
207
141
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
142
|
+
if (currentIndex < 0) {
|
|
143
|
+
return this.#getFirstOption();
|
|
144
|
+
}
|
|
211
145
|
|
|
212
|
-
|
|
213
|
-
}
|
|
146
|
+
return $options[(currentIndex + 1) % $options.length];
|
|
147
|
+
}
|
|
214
148
|
|
|
215
|
-
|
|
216
|
-
|
|
149
|
+
#getPrevOption() {
|
|
150
|
+
const $options = this.#getEnabledRadioElements();
|
|
151
|
+
const $selectedOption = findSelectedOption($options);
|
|
152
|
+
const currentIndex = $selectedOption !== null ? $options.indexOf($selectedOption) : -1;
|
|
217
153
|
|
|
218
|
-
|
|
219
|
-
|
|
154
|
+
if (currentIndex < 0) {
|
|
155
|
+
return this.#getLastOption();
|
|
156
|
+
}
|
|
220
157
|
|
|
221
|
-
|
|
222
|
-
return _classPrivateMethodGet(this, _getLastOption, _getLastOption2).call(this);
|
|
158
|
+
return $options[(currentIndex - 1 + $options.length) % $options.length];
|
|
223
159
|
}
|
|
224
160
|
|
|
225
|
-
|
|
226
|
-
|
|
161
|
+
#getEnabledRadioElements() {
|
|
162
|
+
return this.#$slot.assignedElements().filter(opt => opt.disabled !== true);
|
|
163
|
+
}
|
|
227
164
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
165
|
+
#onChangeReactHandler = e => {
|
|
166
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
167
|
+
};
|
|
168
|
+
});
|
package/tabs-option/index.js
CHANGED
|
@@ -1,57 +1,26 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$button, _$label, _onClick;
|
|
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
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
11
2
|
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>';
|
|
12
3
|
const template = document.createElement('template');
|
|
13
4
|
template.innerHTML = templateHTML;
|
|
14
|
-
defineCustomElement('sinch-tabs-option',
|
|
5
|
+
defineCustomElement('sinch-tabs-option', class extends NectaryElement {
|
|
6
|
+
#$button;
|
|
7
|
+
#$label;
|
|
8
|
+
|
|
15
9
|
constructor() {
|
|
16
10
|
super();
|
|
17
|
-
|
|
18
|
-
_classPrivateFieldInitSpec(this, _$button, {
|
|
19
|
-
writable: true,
|
|
20
|
-
value: void 0
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
_classPrivateFieldInitSpec(this, _$label, {
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
_classPrivateFieldInitSpec(this, _onClick, {
|
|
29
|
-
writable: true,
|
|
30
|
-
value: e => {
|
|
31
|
-
e.stopPropagation();
|
|
32
|
-
this.dispatchEvent(new CustomEvent('option-change', {
|
|
33
|
-
bubbles: true,
|
|
34
|
-
detail: this.value
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
11
|
const shadowRoot = this.attachShadow();
|
|
40
12
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
_classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#content'));
|
|
13
|
+
this.#$button = shadowRoot.querySelector('#button');
|
|
14
|
+
this.#$label = shadowRoot.querySelector('#content');
|
|
45
15
|
}
|
|
46
16
|
|
|
47
17
|
connectedCallback() {
|
|
48
18
|
this.setAttribute('role', 'tab');
|
|
49
|
-
|
|
50
|
-
_classPrivateFieldGet(this, _$button).addEventListener('click', _classPrivateFieldGet(this, _onClick));
|
|
19
|
+
this.#$button.addEventListener('click', this.#onClick);
|
|
51
20
|
}
|
|
52
21
|
|
|
53
22
|
disconnectedCallback() {
|
|
54
|
-
|
|
23
|
+
this.#$button.removeEventListener('click', this.#onClick);
|
|
55
24
|
}
|
|
56
25
|
|
|
57
26
|
static get observedAttributes() {
|
|
@@ -94,7 +63,7 @@ defineCustomElement('sinch-tabs-option', (_$button = new WeakMap(), _$label = ne
|
|
|
94
63
|
switch (name) {
|
|
95
64
|
case 'text':
|
|
96
65
|
{
|
|
97
|
-
|
|
66
|
+
this.#$label.textContent = newVal;
|
|
98
67
|
break;
|
|
99
68
|
}
|
|
100
69
|
|
|
@@ -107,7 +76,7 @@ defineCustomElement('sinch-tabs-option', (_$button = new WeakMap(), _$label = ne
|
|
|
107
76
|
case 'disabled':
|
|
108
77
|
{
|
|
109
78
|
const isDisabled = isAttrTrue(newVal);
|
|
110
|
-
|
|
79
|
+
this.#$button.disabled = isDisabled;
|
|
111
80
|
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
112
81
|
break;
|
|
113
82
|
}
|
|
@@ -115,11 +84,18 @@ defineCustomElement('sinch-tabs-option', (_$button = new WeakMap(), _$label = ne
|
|
|
115
84
|
}
|
|
116
85
|
|
|
117
86
|
focus() {
|
|
118
|
-
|
|
87
|
+
this.#$button.focus();
|
|
119
88
|
}
|
|
120
89
|
|
|
121
90
|
blur() {
|
|
122
|
-
|
|
91
|
+
this.#$button.blur();
|
|
123
92
|
}
|
|
124
93
|
|
|
125
|
-
|
|
94
|
+
#onClick = e => {
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
this.dispatchEvent(new CustomEvent('option-change', {
|
|
97
|
+
bubbles: true,
|
|
98
|
+
detail: this.value
|
|
99
|
+
}));
|
|
100
|
+
};
|
|
101
|
+
});
|
package/tag/index.d.ts
CHANGED
package/tag/index.js
CHANGED
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$text;
|
|
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 '../icons/cancel';
|
|
11
1
|
import '../text';
|
|
12
|
-
import { defineCustomElement, getBooleanAttribute, getAttribute, getLiteralAttribute, updateBooleanAttribute, updateAttribute, updateLiteralAttribute, NectaryElement } from '../utils';
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
import { defineCustomElement, getBooleanAttribute, getAttribute, getLiteralAttribute, updateBooleanAttribute, updateAttribute, updateLiteralAttribute, NectaryElement, setClass } from '../utils';
|
|
3
|
+
import { assertColorNameValue, colorMap, colorNameValues, NO_COLOR } from '../utils/colors';
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;align-items:center;gap:4px;width:100%;height:24px;padding:0 12px;border-radius:12px;color:var(--sinch-color-text-default);box-sizing:border-box;--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:16px}#wrapper.no-color{background-color:var(--sinch-color-snow-500)}#wrapper.inverted{color:var(--sinch-color-text-inverted);--sinch-color-icon:var(--sinch-color-snow-100)}#text{flex:1}:host([small]:not([small=false])) #wrapper{height:20px;border-radius:10px;padding:0 8px}::slotted(*){margin-left:-4px}:host([small]:not([small=false])) ::slotted(*){margin-left:-2px}</style><div id="wrapper"><slot name="icon"></slot><sinch-text id="text" type="xs" ellipsis></sinch-text></div>';
|
|
15
5
|
const template = document.createElement('template');
|
|
16
6
|
template.innerHTML = templateHTML;
|
|
17
|
-
defineCustomElement('sinch-tag',
|
|
7
|
+
defineCustomElement('sinch-tag', class extends NectaryElement {
|
|
8
|
+
#$text;
|
|
9
|
+
#$wrapper;
|
|
10
|
+
|
|
18
11
|
constructor() {
|
|
19
12
|
super();
|
|
20
|
-
|
|
21
|
-
_classPrivateFieldInitSpec(this, _$text, {
|
|
22
|
-
writable: true,
|
|
23
|
-
value: void 0
|
|
24
|
-
});
|
|
25
|
-
|
|
26
13
|
const shadowRoot = this.attachShadow();
|
|
27
14
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
15
|
+
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
16
|
+
this.#$text = shadowRoot.querySelector('#text');
|
|
17
|
+
}
|
|
28
18
|
|
|
29
|
-
|
|
19
|
+
connectedCallback() {
|
|
20
|
+
this.#updateColor();
|
|
30
21
|
}
|
|
31
22
|
|
|
32
|
-
get
|
|
33
|
-
return getLiteralAttribute(this,
|
|
23
|
+
get color() {
|
|
24
|
+
return getLiteralAttribute(this, colorNameValues, 'color', null);
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
set
|
|
37
|
-
updateLiteralAttribute(this,
|
|
27
|
+
set color(value) {
|
|
28
|
+
updateLiteralAttribute(this, colorNameValues, 'color', value);
|
|
38
29
|
}
|
|
39
30
|
|
|
40
31
|
get text() {
|
|
@@ -45,14 +36,6 @@ defineCustomElement('sinch-tag', (_$text = new WeakMap(), class extends NectaryE
|
|
|
45
36
|
updateAttribute(this, 'text', value);
|
|
46
37
|
}
|
|
47
38
|
|
|
48
|
-
get inverted() {
|
|
49
|
-
return getBooleanAttribute(this, 'inverted');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
set inverted(isInverted) {
|
|
53
|
-
updateBooleanAttribute(this, 'inverted', isInverted);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
39
|
get small() {
|
|
57
40
|
return getBooleanAttribute(this, 'small');
|
|
58
41
|
}
|
|
@@ -62,23 +45,39 @@ defineCustomElement('sinch-tag', (_$text = new WeakMap(), class extends NectaryE
|
|
|
62
45
|
}
|
|
63
46
|
|
|
64
47
|
static get observedAttributes() {
|
|
65
|
-
return ['text', '
|
|
48
|
+
return ['text', 'color'];
|
|
66
49
|
}
|
|
67
50
|
|
|
68
51
|
attributeChangedCallback(name, _, newVal) {
|
|
69
52
|
switch (name) {
|
|
70
|
-
case '
|
|
53
|
+
case 'color':
|
|
71
54
|
{
|
|
72
|
-
|
|
55
|
+
assertColorNameValue(newVal);
|
|
56
|
+
this.#updateColor();
|
|
73
57
|
break;
|
|
74
58
|
}
|
|
75
59
|
|
|
76
60
|
case 'text':
|
|
77
61
|
{
|
|
78
|
-
|
|
62
|
+
this.#$text.textContent = newVal;
|
|
79
63
|
break;
|
|
80
64
|
}
|
|
81
65
|
}
|
|
82
66
|
}
|
|
83
67
|
|
|
84
|
-
|
|
68
|
+
#updateColor() {
|
|
69
|
+
const colorName = this.color ?? NO_COLOR;
|
|
70
|
+
const {
|
|
71
|
+
value,
|
|
72
|
+
isInverted
|
|
73
|
+
} = colorMap[colorName];
|
|
74
|
+
|
|
75
|
+
if (value !== NO_COLOR) {
|
|
76
|
+
this.#$wrapper.style.backgroundColor = `var(--sinch-color-${value})`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setClass(this.#$wrapper, 'no-color', value === NO_COLOR);
|
|
80
|
+
setClass(this.#$wrapper, 'inverted', isInverted);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
});
|
package/tag/types.d.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import type { TSinchElementReact } from '../types';
|
|
2
|
-
|
|
2
|
+
import type { TSinchColorName } from '../utils/colors';
|
|
3
3
|
export declare type TSinchTagElement = HTMLElement & {
|
|
4
|
-
|
|
4
|
+
/** Text */
|
|
5
5
|
text: string;
|
|
6
|
-
|
|
6
|
+
/** Color, gray by default */
|
|
7
|
+
color: TSinchColorName | null;
|
|
8
|
+
/** Small */
|
|
7
9
|
small: boolean;
|
|
8
|
-
|
|
10
|
+
/** Text */
|
|
9
11
|
setAttribute(name: 'text', value: string): void;
|
|
10
|
-
|
|
12
|
+
/** Color, gray by default */
|
|
13
|
+
setAttribute(name: 'color', value: TSinchColorName): void;
|
|
14
|
+
/** Small */
|
|
11
15
|
setAttribute(name: 'small', value: ''): void;
|
|
12
16
|
};
|
|
13
17
|
export declare type TSinchTagReact = TSinchElementReact<TSinchTagElement> & {
|
|
14
|
-
|
|
18
|
+
/** Text */
|
|
15
19
|
text: string;
|
|
16
|
-
|
|
20
|
+
/** Color, gray by default */
|
|
21
|
+
color?: TSinchColorName;
|
|
22
|
+
/** Small */
|
|
17
23
|
small?: boolean;
|
|
18
24
|
};
|