@nectary/components 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accordion/index.js +47 -84
- package/accordion-item/index.js +30 -53
- package/action-menu/index.d.ts +0 -1
- package/action-menu/index.js +177 -223
- package/action-menu/types.d.ts +8 -18
- package/action-menu-option/index.d.ts +1 -0
- package/action-menu-option/index.js +52 -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 +46 -92
- package/button/types.d.ts +1 -1
- 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 +59 -107
- package/chip/index.d.ts +13 -0
- package/chip/index.js +140 -0
- package/chip/types.d.ts +37 -0
- package/color-menu/index.d.ts +14 -0
- package/color-menu/index.js +450 -0
- package/color-menu/types.d.ts +36 -0
- package/color-menu/utils.d.ts +1 -0
- package/color-menu/utils.js +15 -0
- package/color-swatch/index.d.ts +13 -0
- package/color-swatch/index.js +60 -0
- package/color-swatch/types.d.ts +11 -0
- package/colors.json +61 -49
- package/date-picker/index.js +162 -293
- package/dialog/index.js +70 -142
- package/field/index.js +44 -65
- 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 +11 -28
- package/horizontal-stepper/index.js +33 -59
- package/horizontal-stepper-item/index.js +13 -37
- package/icon-button/index.d.ts +1 -0
- package/icon-button/index.js +51 -85
- package/icon-button/types.d.ts +16 -2
- 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 +117 -222
- package/link/index.js +51 -97
- package/list-item/index.js +1 -1
- package/package.json +12 -14
- package/pagination/index.js +113 -163
- package/pop/index.d.ts +11 -0
- package/pop/index.js +391 -0
- package/pop/types.d.ts +35 -0
- package/pop/utils.d.ts +7 -0
- package/pop/utils.js +18 -0
- package/popover/index.d.ts +1 -0
- package/popover/index.js +105 -314
- package/popover/types.d.ts +8 -1
- package/popover/utils.d.ts +5 -0
- package/popover/utils.js +17 -1
- package/progress/index.js +9 -28
- package/radio/index.js +103 -169
- package/radio-option/index.js +28 -48
- package/segment/index.js +49 -130
- package/segment-collapse/index.js +28 -49
- package/segmented-control/index.js +36 -73
- package/segmented-control-option/index.js +45 -87
- package/segmented-icon-control/index.js +47 -84
- package/segmented-icon-control-option/index.js +42 -79
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +158 -0
- package/select-button/types.d.ts +43 -0
- package/select-menu/index.d.ts +11 -0
- package/select-menu/index.js +345 -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-option/index.js +24 -44
- package/tag/index.d.ts +0 -1
- package/tag/index.js +35 -38
- package/tag/types.d.ts +12 -7
- package/textarea/index.js +96 -167
- package/theme.css +146 -49
- package/tile-control/index.js +55 -96
- package/tile-control-option/index.js +45 -87
- 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 +59 -107
- package/tooltip/index.d.ts +2 -0
- package/tooltip/index.js +160 -17
- package/tooltip/types.d.ts +13 -0
- package/tooltip/utils.d.ts +5 -0
- package/tooltip/utils.js +25 -1
- package/utils/animation.d.ts +17 -0
- package/utils/animation.js +142 -0
- package/utils/colors.d.ts +5 -0
- package/utils/colors.js +5 -0
- package/utils/context.d.ts +15 -0
- package/utils/context.js +57 -0
- package/{utils.d.ts → utils/index.d.ts} +15 -11
- package/{utils.js → utils/index.js} +104 -48
- 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-checkbox-option/index.d.ts +0 -11
- package/dropdown-checkbox-option/index.js +0 -88
- package/dropdown-checkbox-option/types.d.ts +0 -15
- package/dropdown-radio-option/index.d.ts +0 -11
- package/dropdown-radio-option/index.js +0 -88
- package/dropdown-radio-option/types.d.ts +0 -15
- 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-checkbox-option → chip}/types.js +0 -0
- /package/{dropdown-radio-option → color-menu}/types.js +0 -0
- /package/{dropdown-text-option → color-swatch}/types.js +0 -0
- /package/{dropdown → pop}/types.js +0 -0
- /package/{select-option → select-button}/types.js +0 -0
- /package/{tag-close → select-menu}/types.js +0 -0
- /package/{select → select-menu-option}/types.js +0 -0
package/dialog/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 _$dialog, _$closeButton, _$caption, _isConnected, _prevOverflowValue, _onCancel, _onCloseClick, _onBackdropClick, _onCloseReactHandler, _dispatchCloseEvent, _setOpen;
|
|
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 dialogPolyfill from 'dialog-polyfill';
|
|
15
2
|
import '../icon-button';
|
|
16
3
|
import '../icons/close';
|
|
@@ -20,119 +7,40 @@ import { defineCustomElement, getAttribute, getBooleanAttribute, getRect, isAttr
|
|
|
20
7
|
const templateHTML = '<style>:host{display:inline-block}dialog{position:fixed;left:0;right:0;margin:auto;display:flex;flex-direction:column;padding:24px;max-width:var(--sinch-dialog-max-width,512px);max-height:unset;border-radius:var(--sinch-shape-radius-l);box-sizing:border-box;contain:content;background-color:var(--sinch-color-snow-100);color:var(--sinch-color-text-default);font:var(--sinch-font-body);border:none;box-shadow:var(--sinch-elevation-level-3)}dialog:not([open]){display:none}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:#000;opacity:.55}dialog::backdrop{background-color:#000;opacity:.55}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}#header{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;margin-bottom:16px}#caption{color:var(--sinch-color-text-default)}#content{min-height:0;overflow:auto;max-height:var(--sinch-dialog-max-height,50vh)}#buttons{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;margin-top:24px}sinch-icon-button{transform:translate(4px,-4px)}</style><dialog><div id="header"><sinch-title id="caption" type="m" level="3" ellipsis></sinch-title><sinch-icon-button id="close" small tabindex="0"><sinch-icon-close slot="icon"></sinch-icon-close></sinch-icon-button></div><div id="content"><sinch-stop-events events="close"><slot name="content"></slot></sinch-stop-events></div><div id="buttons"><sinch-stop-events events="close"><slot name="buttons"></slot></sinch-stop-events></div></dialog>';
|
|
21
8
|
const template = document.createElement('template');
|
|
22
9
|
template.innerHTML = templateHTML;
|
|
23
|
-
defineCustomElement('sinch-dialog',
|
|
10
|
+
defineCustomElement('sinch-dialog', class extends NectaryElement {
|
|
11
|
+
#$dialog;
|
|
12
|
+
#$closeButton;
|
|
13
|
+
#$caption;
|
|
14
|
+
#isConnected = false;
|
|
15
|
+
#prevOverflowValue = '';
|
|
16
|
+
|
|
24
17
|
constructor() {
|
|
25
18
|
super();
|
|
26
|
-
|
|
27
|
-
_classPrivateMethodInitSpec(this, _setOpen);
|
|
28
|
-
|
|
29
|
-
_classPrivateMethodInitSpec(this, _dispatchCloseEvent);
|
|
30
|
-
|
|
31
|
-
_classPrivateFieldInitSpec(this, _$dialog, {
|
|
32
|
-
writable: true,
|
|
33
|
-
value: void 0
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
_classPrivateFieldInitSpec(this, _$closeButton, {
|
|
37
|
-
writable: true,
|
|
38
|
-
value: void 0
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
_classPrivateFieldInitSpec(this, _$caption, {
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
_classPrivateFieldInitSpec(this, _isConnected, {
|
|
47
|
-
writable: true,
|
|
48
|
-
value: false
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
_classPrivateFieldInitSpec(this, _prevOverflowValue, {
|
|
52
|
-
writable: true,
|
|
53
|
-
value: ''
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
_classPrivateFieldInitSpec(this, _onCancel, {
|
|
57
|
-
writable: true,
|
|
58
|
-
value: e => {
|
|
59
|
-
e.preventDefault();
|
|
60
|
-
|
|
61
|
-
_classPrivateMethodGet(this, _dispatchCloseEvent, _dispatchCloseEvent2).call(this);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
_classPrivateFieldInitSpec(this, _onCloseClick, {
|
|
66
|
-
writable: true,
|
|
67
|
-
value: () => {
|
|
68
|
-
_classPrivateMethodGet(this, _dispatchCloseEvent, _dispatchCloseEvent2).call(this);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
_classPrivateFieldInitSpec(this, _onBackdropClick, {
|
|
73
|
-
writable: true,
|
|
74
|
-
value: e => {
|
|
75
|
-
if (e.target !== _classPrivateFieldGet(this, _$dialog)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const rect = this.dialogRect;
|
|
80
|
-
const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
|
|
81
|
-
|
|
82
|
-
if (!isInside) {
|
|
83
|
-
_classPrivateMethodGet(this, _dispatchCloseEvent, _dispatchCloseEvent2).call(this);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
_classPrivateFieldInitSpec(this, _onCloseReactHandler, {
|
|
89
|
-
writable: true,
|
|
90
|
-
value: e => {
|
|
91
|
-
getReactEventHandler(this, 'onClose')?.();
|
|
92
|
-
getReactEventHandler(this, 'on-close')?.(e);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
19
|
const shadowRoot = this.attachShadow();
|
|
97
20
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
_classPrivateFieldSet(this, _$caption, shadowRoot.querySelector('#caption'));
|
|
104
|
-
|
|
105
|
-
dialogPolyfill.registerDialog(_classPrivateFieldGet(this, _$dialog));
|
|
21
|
+
this.#$dialog = shadowRoot.querySelector('dialog');
|
|
22
|
+
this.#$closeButton = shadowRoot.querySelector('#close');
|
|
23
|
+
this.#$caption = shadowRoot.querySelector('#caption');
|
|
24
|
+
dialogPolyfill.registerDialog(this.#$dialog);
|
|
106
25
|
}
|
|
107
26
|
|
|
108
27
|
connectedCallback() {
|
|
109
28
|
this.setAttribute('role', 'dialog');
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.addEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
|
|
118
|
-
|
|
119
|
-
_classPrivateFieldSet(this, _isConnected, true);
|
|
120
|
-
|
|
121
|
-
_classPrivateMethodGet(this, _setOpen, _setOpen2).call(this, getBooleanAttribute(this, 'open'));
|
|
29
|
+
this.#$closeButton.addEventListener('click', this.#onCloseClick);
|
|
30
|
+
this.#$dialog.addEventListener('mousedown', this.#onBackdropClick);
|
|
31
|
+
this.#$dialog.addEventListener('cancel', this.#onCancel);
|
|
32
|
+
this.addEventListener('-close', this.#onCloseReactHandler);
|
|
33
|
+
this.#isConnected = true;
|
|
34
|
+
this.#setOpen(getBooleanAttribute(this, 'open'));
|
|
122
35
|
}
|
|
123
36
|
|
|
124
37
|
disconnectedCallback() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.removeEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
|
|
132
|
-
|
|
133
|
-
_classPrivateMethodGet(this, _setOpen, _setOpen2).call(this, false);
|
|
134
|
-
|
|
135
|
-
_classPrivateFieldSet(this, _isConnected, false);
|
|
38
|
+
this.#$closeButton.removeEventListener('click', this.#onCloseClick);
|
|
39
|
+
this.#$dialog.removeEventListener('mousedown', this.#onBackdropClick);
|
|
40
|
+
this.#$dialog.removeEventListener('cancel', this.#onCancel);
|
|
41
|
+
this.removeEventListener('-close', this.#onCloseReactHandler);
|
|
42
|
+
this.#setOpen(false);
|
|
43
|
+
this.#isConnected = false;
|
|
136
44
|
}
|
|
137
45
|
|
|
138
46
|
static get observedAttributes() {
|
|
@@ -143,23 +51,21 @@ defineCustomElement('sinch-dialog', (_$dialog = new WeakMap(), _$closeButton = n
|
|
|
143
51
|
switch (name) {
|
|
144
52
|
case 'caption':
|
|
145
53
|
{
|
|
146
|
-
updateAttribute(
|
|
54
|
+
updateAttribute(this.#$caption, 'text', newVal);
|
|
147
55
|
break;
|
|
148
56
|
}
|
|
149
57
|
|
|
150
58
|
case 'open':
|
|
151
59
|
{
|
|
152
60
|
const shouldOpen = isAttrTrue(newVal);
|
|
153
|
-
|
|
154
|
-
_classPrivateMethodGet(this, _setOpen, _setOpen2).call(this, shouldOpen);
|
|
155
|
-
|
|
61
|
+
this.#setOpen(shouldOpen);
|
|
156
62
|
updateBooleanAttribute(this, 'open', shouldOpen);
|
|
157
63
|
break;
|
|
158
64
|
}
|
|
159
65
|
|
|
160
66
|
case 'close-aria-label':
|
|
161
67
|
{
|
|
162
|
-
updateAttribute(
|
|
68
|
+
updateAttribute(this.#$closeButton, 'aria-label', newVal);
|
|
163
69
|
break;
|
|
164
70
|
}
|
|
165
71
|
}
|
|
@@ -173,31 +79,53 @@ defineCustomElement('sinch-dialog', (_$dialog = new WeakMap(), _$closeButton = n
|
|
|
173
79
|
return getAttribute(this, 'caption', '');
|
|
174
80
|
}
|
|
175
81
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
82
|
+
#onCancel = e => {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
this.#dispatchCloseEvent();
|
|
85
|
+
};
|
|
86
|
+
#onCloseClick = () => {
|
|
87
|
+
this.#dispatchCloseEvent();
|
|
88
|
+
};
|
|
89
|
+
#onBackdropClick = e => {
|
|
90
|
+
if (e.target !== this.#$dialog) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
183
93
|
|
|
184
|
-
|
|
94
|
+
const rect = this.dialogRect;
|
|
95
|
+
const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
|
|
185
96
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
97
|
+
if (!isInside) {
|
|
98
|
+
this.#dispatchCloseEvent();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
#onCloseReactHandler = e => {
|
|
102
|
+
getReactEventHandler(this, 'onClose')?.();
|
|
103
|
+
getReactEventHandler(this, 'on-close')?.(e);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
#dispatchCloseEvent() {
|
|
107
|
+
this.dispatchEvent(new CustomEvent('-close'));
|
|
108
|
+
}
|
|
189
109
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
110
|
+
#setOpen(shouldOpen) {
|
|
111
|
+
if (shouldOpen) {
|
|
112
|
+
if (this.#isConnected && !getBooleanAttribute(this.#$dialog, 'open')) {
|
|
113
|
+
this.#prevOverflowValue = document.body.style.overflow;
|
|
114
|
+
document.body.style.overflow = 'hidden';
|
|
115
|
+
this.#$dialog.showModal();
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
this.#$dialog.close?.();
|
|
119
|
+
document.body.style.overflow = this.#prevOverflowValue;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
194
122
|
|
|
195
|
-
|
|
123
|
+
get dialogRect() {
|
|
124
|
+
return getRect(this.#$dialog);
|
|
125
|
+
}
|
|
196
126
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
} else {
|
|
200
|
-
_classPrivateFieldGet(this, _$dialog).close?.();
|
|
201
|
-
document.body.style.overflow = _classPrivateFieldGet(this, _prevOverflowValue);
|
|
127
|
+
get closeButtonRect() {
|
|
128
|
+
return getRect(this.#$closeButton);
|
|
202
129
|
}
|
|
203
|
-
|
|
130
|
+
|
|
131
|
+
});
|
package/field/index.js
CHANGED
|
@@ -1,72 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _$label, _$optionalText, _$additionalText, _$invalidText, _$inputSlot, _onLabelClick;
|
|
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, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
11
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{display:flex;flex-direction:column;width:100%}#bottom,#top{display:flex;align-items:baseline}#top{height:24px;margin-bottom:2px;--sinch-color-icon:var(--sinch-color-stormy-500)}#additional,#invalid,#label,#optional{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#label{font:var(--sinch-font-title-s);color:var(--sinch-color-text-default)}#optional{flex:1;text-align:right;font:var(--sinch-font-small-text);color:var(--sinch-color-text-muted)}#additional{flex:1;text-align:right;font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-muted);line-height:20px;margin-top:2px}#additional:empty{display:none}#invalid{font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-invalid);line-height:20px;margin-top:2px}#invalid:empty{display:none}::slotted(sinch-help-tooltip){align-self:center;margin:0 8px}:host([disabled]:not([disabled=false])) :is(#label,#additional,#optional,#invalid){color:var(--sinch-color-stormy-100)}:host([disabled]:not([disabled=false])) #top{--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><div id="top"><label id="label" for="input"></label><slot name="tooltip"></slot><span id="optional"></span></div><slot name="input"></slot><div id="bottom"><div id="invalid"></div><div id="additional"></div></div></div>';
|
|
1
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getFirstSlotElement, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{display:flex;flex-direction:column;width:100%}#bottom,#top{display:flex;align-items:baseline}#top{height:24px;margin-bottom:2px;--sinch-color-icon:var(--sinch-color-stormy-500)}#additional,#invalid,#label,#optional{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#label{font:var(--sinch-font-title-s);color:var(--sinch-color-text-default)}#optional{flex:1;text-align:right;font:var(--sinch-font-small-text);color:var(--sinch-color-text-muted)}#additional{flex:1;text-align:right;font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-muted);line-height:20px;margin-top:2px}#additional:empty{display:none}#invalid{font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-invalid);line-height:20px;margin-top:2px}#invalid:empty{display:none}#tooltip{align-self:center;margin:0 8px;display:flex}#tooltip.empty{display:none}:host([disabled]:not([disabled=false])) :is(#label,#additional,#optional,#invalid){color:var(--sinch-color-stormy-100)}:host([disabled]:not([disabled=false])) #top{--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><div id="top"><label id="label" for="input"></label><div id="tooltip"><slot name="tooltip"></slot></div><span id="optional"></span></div><slot name="input"></slot><div id="bottom"><div id="invalid"></div><div id="additional"></div></div></div>';
|
|
12
3
|
const template = document.createElement('template');
|
|
13
4
|
template.innerHTML = templateHTML;
|
|
14
|
-
defineCustomElement('sinch-field',
|
|
5
|
+
defineCustomElement('sinch-field', class extends NectaryElement {
|
|
6
|
+
#$label;
|
|
7
|
+
#$optionalText;
|
|
8
|
+
#$additionalText;
|
|
9
|
+
#$invalidText;
|
|
10
|
+
#$inputSlot;
|
|
11
|
+
#$tooltipWrapper;
|
|
12
|
+
#$tooltipSlot;
|
|
13
|
+
#controller = null;
|
|
14
|
+
|
|
15
15
|
constructor() {
|
|
16
16
|
super();
|
|
17
|
-
|
|
18
|
-
_classPrivateFieldInitSpec(this, _$label, {
|
|
19
|
-
writable: true,
|
|
20
|
-
value: void 0
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
_classPrivateFieldInitSpec(this, _$optionalText, {
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
_classPrivateFieldInitSpec(this, _$additionalText, {
|
|
29
|
-
writable: true,
|
|
30
|
-
value: void 0
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
_classPrivateFieldInitSpec(this, _$invalidText, {
|
|
34
|
-
writable: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
_classPrivateFieldInitSpec(this, _$inputSlot, {
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
_classPrivateFieldInitSpec(this, _onLabelClick, {
|
|
44
|
-
writable: true,
|
|
45
|
-
value: () => {
|
|
46
|
-
_classPrivateFieldGet(this, _$inputSlot).assignedElements()[0]?.focus?.();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
17
|
const shadowRoot = this.attachShadow();
|
|
51
18
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
_classPrivateFieldSet(this, _$invalidText, shadowRoot.querySelector('#invalid'));
|
|
60
|
-
|
|
61
|
-
_classPrivateFieldSet(this, _$inputSlot, shadowRoot.querySelector('slot[name="input"]'));
|
|
19
|
+
this.#$label = shadowRoot.querySelector('#label');
|
|
20
|
+
this.#$optionalText = shadowRoot.querySelector('#optional');
|
|
21
|
+
this.#$additionalText = shadowRoot.querySelector('#additional');
|
|
22
|
+
this.#$invalidText = shadowRoot.querySelector('#invalid');
|
|
23
|
+
this.#$inputSlot = shadowRoot.querySelector('slot[name="input"]');
|
|
24
|
+
this.#$tooltipSlot = shadowRoot.querySelector('slot[name="tooltip"]');
|
|
25
|
+
this.#$tooltipWrapper = shadowRoot.querySelector('#tooltip');
|
|
62
26
|
}
|
|
63
27
|
|
|
64
28
|
connectedCallback() {
|
|
65
|
-
|
|
29
|
+
this.#controller = new AbortController();
|
|
30
|
+
const {
|
|
31
|
+
signal
|
|
32
|
+
} = this.#controller;
|
|
33
|
+
this.#$label.addEventListener('click', this.#onLabelClick, {
|
|
34
|
+
signal
|
|
35
|
+
});
|
|
36
|
+
this.#$tooltipSlot.addEventListener('slotchange', this.#onTooltipSlotChange, {
|
|
37
|
+
signal
|
|
38
|
+
});
|
|
66
39
|
}
|
|
67
40
|
|
|
68
41
|
disconnectedCallback() {
|
|
69
|
-
|
|
42
|
+
this.#controller.abort();
|
|
70
43
|
}
|
|
71
44
|
|
|
72
45
|
static get observedAttributes() {
|
|
@@ -86,7 +59,7 @@ defineCustomElement('sinch-field', (_$label = new WeakMap(), _$optionalText = ne
|
|
|
86
59
|
}
|
|
87
60
|
|
|
88
61
|
get optionalText() {
|
|
89
|
-
return getAttribute(this, 'optionaltext'
|
|
62
|
+
return getAttribute(this, 'optionaltext');
|
|
90
63
|
}
|
|
91
64
|
|
|
92
65
|
set additionalText(value) {
|
|
@@ -94,7 +67,7 @@ defineCustomElement('sinch-field', (_$label = new WeakMap(), _$optionalText = ne
|
|
|
94
67
|
}
|
|
95
68
|
|
|
96
69
|
get additionalText() {
|
|
97
|
-
return getAttribute(this, 'additionaltext'
|
|
70
|
+
return getAttribute(this, 'additionaltext');
|
|
98
71
|
}
|
|
99
72
|
|
|
100
73
|
set invalidText(value) {
|
|
@@ -102,7 +75,7 @@ defineCustomElement('sinch-field', (_$label = new WeakMap(), _$optionalText = ne
|
|
|
102
75
|
}
|
|
103
76
|
|
|
104
77
|
get invalidText() {
|
|
105
|
-
return getAttribute(this, 'invalidtext'
|
|
78
|
+
return getAttribute(this, 'invalidtext');
|
|
106
79
|
}
|
|
107
80
|
|
|
108
81
|
set disabled(isDisabled) {
|
|
@@ -117,28 +90,34 @@ defineCustomElement('sinch-field', (_$label = new WeakMap(), _$optionalText = ne
|
|
|
117
90
|
switch (name) {
|
|
118
91
|
case 'label':
|
|
119
92
|
{
|
|
120
|
-
|
|
93
|
+
this.#$label.textContent = newVal;
|
|
121
94
|
break;
|
|
122
95
|
}
|
|
123
96
|
|
|
124
97
|
case 'optionaltext':
|
|
125
98
|
{
|
|
126
|
-
|
|
99
|
+
this.#$optionalText.textContent = newVal;
|
|
127
100
|
break;
|
|
128
101
|
}
|
|
129
102
|
|
|
130
103
|
case 'additionaltext':
|
|
131
104
|
{
|
|
132
|
-
|
|
105
|
+
this.#$additionalText.textContent = newVal;
|
|
133
106
|
break;
|
|
134
107
|
}
|
|
135
108
|
|
|
136
109
|
case 'invalidtext':
|
|
137
110
|
{
|
|
138
|
-
|
|
111
|
+
this.#$invalidText.textContent = newVal;
|
|
139
112
|
break;
|
|
140
113
|
}
|
|
141
114
|
}
|
|
142
115
|
}
|
|
143
116
|
|
|
144
|
-
|
|
117
|
+
#onLabelClick = () => {
|
|
118
|
+
getFirstSlotElement(this.#$inputSlot)?.focus?.();
|
|
119
|
+
};
|
|
120
|
+
#onTooltipSlotChange = () => {
|
|
121
|
+
setClass(this.#$tooltipWrapper, 'empty', this.#$tooltipSlot.assignedElements().length === 0);
|
|
122
|
+
};
|
|
123
|
+
});
|