@nectary/components 0.44.0 → 0.45.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-item/index.js +1 -1
- package/action-menu/index.js +3 -11
- package/alert/index.js +3 -1
- package/avatar/index.js +12 -13
- package/avatar/types.d.ts +4 -4
- package/avatar/utils.d.ts +1 -4
- package/avatar/utils.js +4 -7
- package/badge/index.js +9 -7
- package/badge/types.d.ts +4 -4
- package/badge/utils.d.ts +1 -4
- package/badge/utils.js +0 -6
- package/button/index.js +88 -23
- package/button/types.d.ts +12 -11
- package/button/utils.d.ts +4 -1
- package/button/utils.js +9 -1
- package/card-container/index.js +1 -1
- package/chat-block/index.js +1 -1
- package/chat-bubble/index.js +1 -1
- package/checkbox/index.js +4 -2
- package/chip/index.js +7 -6
- package/color-menu/index.js +9 -18
- package/color-swatch/index.js +5 -7
- package/date-picker/index.js +1 -1
- package/dialog/index.js +4 -7
- package/emoji/index.js +2 -6
- package/emoji-picker/data.json +1 -0
- package/emoji-picker/index.js +6 -14
- package/field/index.js +1 -1
- package/file-status/index.js +4 -2
- package/flag/index.d.ts +11 -0
- package/flag/index.js +43 -0
- package/flag/types.d.ts +11 -0
- package/flag/types.js +1 -0
- package/flag/utils.d.ts +1 -0
- package/flag/utils.js +19 -0
- package/icon/index.js +1 -1
- package/icon-button/index.js +77 -9
- package/icon-button/types.d.ts +14 -6
- package/icon-button/utils.d.ts +5 -0
- package/icon-button/utils.js +9 -0
- package/icons/create-icon-class.js +1 -1
- package/inline-alert/index.js +3 -1
- package/input/index.d.ts +3 -0
- package/input/index.js +148 -71
- package/input/types.d.ts +7 -0
- package/link/index.js +1 -1
- package/package.json +4 -6
- package/pagination/index.js +1 -1
- package/pop/index.js +15 -37
- package/popover/index.js +7 -9
- package/radio-option/index.js +1 -1
- package/segment/index.js +10 -6
- package/segment/types.d.ts +4 -4
- package/segment/utils.d.ts +3 -5
- package/segment/utils.js +14 -4
- package/segment-collapse/index.js +1 -1
- package/segmented-control-option/index.js +1 -1
- package/segmented-icon-control-option/index.js +1 -1
- package/select-button/index.js +93 -28
- package/select-button/types.d.ts +8 -1
- package/select-menu/index.d.ts +5 -0
- package/select-menu/index.js +46 -17
- package/select-menu-option/index.d.ts +1 -0
- package/select-menu-option/index.js +3 -0
- package/select-menu-option/types.d.ts +1 -0
- package/spinner/index.js +52 -7
- package/spinner/types.d.ts +4 -5
- package/stop-events/index.js +9 -5
- package/table/index.js +1 -1
- package/tag/index.js +2 -6
- package/text/index.js +3 -1
- package/textarea/index.js +1 -1
- package/theme/button.css +146 -0
- package/{theme.css → theme/contextual.css} +3 -25
- package/theme/elevation.css +1 -1
- package/theme/flag.css +4 -0
- package/theme/fonts.css +0 -33
- package/theme/fonts.json +0 -33
- package/theme/icon-button.css +68 -0
- package/theme/index.css +4 -0
- package/theme/index.d.ts +21 -0
- package/theme/index.js +21 -0
- package/theme/input.css +7 -0
- package/theme/select-button.css +7 -0
- package/theme/shapes.css +4 -3
- package/theme/size.css +9 -0
- package/theme/spinner.css +7 -0
- package/theme/typography.css +7 -7
- package/tile-control-option/index.js +1 -1
- package/time-picker/index.js +1 -1
- package/title/index.js +7 -3
- package/toast/index.js +3 -1
- package/toggle/index.js +1 -1
- package/tooltip/index.js +8 -6
- package/utils/context.d.ts +14 -9
- package/utils/context.js +60 -26
- package/utils/countries.d.ts +5 -0
- package/utils/countries.js +2 -0
- package/utils/countries.json +998 -0
- package/utils/debounce.d.ts +4 -0
- package/utils/debounce.js +21 -0
- package/utils/element.d.ts +4 -0
- package/utils/element.js +10 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/size.d.ts +10 -0
- package/utils/size.js +19 -0
- package/utils/throttle.d.ts +2 -2
- package/utils/throttle.js +4 -9
- package/spinner/utils.d.ts +0 -2
- package/spinner/utils.js +0 -1
package/input/index.js
CHANGED
|
@@ -1,57 +1,132 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import '../icon-button';
|
|
2
|
+
import '../icons/close';
|
|
3
|
+
import '../stop-events';
|
|
4
|
+
import { Context, defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getReactEventHandler, isAttrTrue, NectaryElement, setClass, subscribeContext, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
5
|
+
import { assertSize, DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
6
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}:host([data-size="l"]){--sinch-size:var(--sinch-size-l);--sinch-size-icon:var(--sinch-input-icon-size-l);--sinch-shape-radius:var(--sinch-shape-radius-l)}:host([data-size="m"]){--sinch-size:var(--sinch-size-m);--sinch-size-icon:var(--sinch-input-icon-size-m);--sinch-shape-radius:var(--sinch-shape-radius-m)}:host([data-size="s"]){--sinch-size:var(--sinch-size-s);--sinch-size-icon:var(--sinch-input-icon-size-s);--sinch-shape-radius:var(--sinch-shape-radius-s)}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;box-sizing:border-box;border-radius:var(--sinch-shape-radius);width:100%;height:var(--sinch-size);background-color:var(--sinch-color-bg-primary-light)}#input{all:initial;flex:1;min-width:0;height:100%;padding:0 12px 0 40px;font:var(--sinch-font-text-m);color:var(--sinch-color-text-default)}:host([data-size="s"]) #input{padding-left:32px}#input::placeholder{font:var(--sinch-font-text-m);color:var(--sinch-color-text-muted);opacity:1}#border{position:absolute;border:1px solid var(--sinch-color-border-dark);border-radius:var(--sinch-shape-radius);inset:0;pointer-events:none}:host([invalid]:not([invalid=false]):not([disabled])) #border{border-color:var(--sinch-color-text-invalid)}#input:disabled{color:var(--sinch-color-text-disabled)}#input:disabled::placeholder{color:var(--sinch-color-text-disabled)}#input:disabled+#border{border-color:var(--sinch-color-border-disabled)}#input:focus+#border{border-color:var(--sinch-color-border-focus);border-width:2px}#input[type=password]{font-size:1.5em;letter-spacing:.1em}#icon-wrapper{position:relative;height:100%}#icon{position:absolute;display:flex;align-items:center;left:10px;top:0;bottom:0;pointer-events:none;--sinch-color-icon:var(--sinch-color-stormy-500)}:host([disabled]:not([disabled=false])) #icon{--sinch-color-icon:var(--sinch-color-border-disabled)}#icon-wrapper.empty{display:none}#icon-wrapper.empty~#input{padding-left:12px}#clear{display:none;--sinch-icon-button-color-icon:var(--sinch-color-text-muted)}#clear.active{display:block}:host([disabled]:not([disabled=false])) #clear{display:none}#wrapper:focus-within #clear{--sinch-icon-button-color-icon:var(--sinch-color-stormy-500)}#right{display:flex;flex-direction:row;align-self:stretch;align-items:center;gap:4px;padding-right:4px}#right.empty{display:none}#left{display:flex;flex-direction:row;align-self:stretch;align-items:center;gap:4px;padding-left:4px}#left.empty{display:none}</style><div id="wrapper"><div id="left"><slot name="left"></slot></div><div id="icon-wrapper"><div id="icon"><slot name="icon"></slot></div></div><input id="input" type="text"/><div id="border"></div><div id="right"><sinch-stop-events events="keydown"><sinch-icon-button id="clear" aria-label="Clear input value"><sinch-icon-close slot="icon"></sinch-icon-close></sinch-icon-button></sinch-stop-events><slot name="right"></slot></div></div>';
|
|
3
7
|
import { inputTypes } from './utils';
|
|
4
8
|
const template = document.createElement('template');
|
|
5
9
|
template.innerHTML = templateHTML;
|
|
6
10
|
defineCustomElement('sinch-input', class extends NectaryElement {
|
|
7
11
|
#$input;
|
|
12
|
+
#$clear;
|
|
8
13
|
#$iconSlot;
|
|
9
14
|
#$iconWrapper;
|
|
10
15
|
#$rightSlot;
|
|
11
16
|
#$rightWrapper;
|
|
17
|
+
#$leftSlot;
|
|
18
|
+
#$leftWrapper;
|
|
19
|
+
#$wrapper;
|
|
12
20
|
#cursorPos = null;
|
|
13
21
|
#isPendingDk = false;
|
|
22
|
+
#controller = null;
|
|
23
|
+
#sizeContext;
|
|
14
24
|
constructor() {
|
|
15
25
|
super();
|
|
16
|
-
const shadowRoot = this.attachShadow(
|
|
26
|
+
const shadowRoot = this.attachShadow({
|
|
27
|
+
delegatesFocus: true
|
|
28
|
+
});
|
|
17
29
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
18
30
|
this.#$input = shadowRoot.querySelector('#input');
|
|
19
31
|
this.#$iconSlot = shadowRoot.querySelector('slot[name="icon"]');
|
|
20
|
-
this.#$iconWrapper = shadowRoot.querySelector('#icon');
|
|
32
|
+
this.#$iconWrapper = shadowRoot.querySelector('#icon-wrapper');
|
|
21
33
|
this.#$rightSlot = shadowRoot.querySelector('slot[name="right"]');
|
|
22
34
|
this.#$rightWrapper = shadowRoot.querySelector('#right');
|
|
35
|
+
this.#$leftSlot = shadowRoot.querySelector('slot[name="left"]');
|
|
36
|
+
this.#$leftWrapper = shadowRoot.querySelector('#left');
|
|
37
|
+
this.#$clear = shadowRoot.querySelector('#clear');
|
|
38
|
+
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
39
|
+
this.#sizeContext = new Context(this.#$wrapper, 'size');
|
|
23
40
|
}
|
|
24
41
|
connectedCallback() {
|
|
42
|
+
super.connectedCallback();
|
|
25
43
|
this.setAttribute('role', 'textbox');
|
|
26
|
-
this
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.#$input.addEventListener('
|
|
31
|
-
this.#$input.addEventListener('
|
|
32
|
-
this.#$
|
|
33
|
-
this.#$
|
|
34
|
-
this.addEventListener('
|
|
35
|
-
this.addEventListener('
|
|
36
|
-
this.addEventListener('
|
|
44
|
+
this.#controller = new AbortController();
|
|
45
|
+
const options = {
|
|
46
|
+
signal: this.#controller.signal
|
|
47
|
+
};
|
|
48
|
+
this.#$input.addEventListener('input', this.#onInput, options);
|
|
49
|
+
this.#$input.addEventListener('compositionstart', this.#onCompositionStart, options);
|
|
50
|
+
this.#$input.addEventListener('mousedown', this.#onSelectionChange, options);
|
|
51
|
+
this.#$input.addEventListener('keydown', this.#onSelectionChange, options);
|
|
52
|
+
this.#$input.addEventListener('focus', this.#onInputFocus, options);
|
|
53
|
+
this.#$input.addEventListener('blur', this.#onInputBlur, options);
|
|
54
|
+
this.#$clear.addEventListener('click', this.#onClear, options);
|
|
55
|
+
this.#$iconSlot.addEventListener('slotchange', this.#onIconSlotChange, options);
|
|
56
|
+
this.#$leftSlot.addEventListener('slotchange', this.#onLeftSlotChange, options);
|
|
57
|
+
this.#$rightSlot.addEventListener('slotchange', this.#onRightSlotChange, options);
|
|
58
|
+
this.addEventListener('-change', this.#onChangeReactHandler, options);
|
|
59
|
+
this.addEventListener('-focus', this.#onFocusReactHandler, options);
|
|
60
|
+
this.addEventListener('-blur', this.#onBlurReactHandler, options);
|
|
61
|
+
this.#sizeContext.listen(this.#controller.signal);
|
|
62
|
+
subscribeContext(this, 'size', this.#onContextSize, this.#controller.signal);
|
|
37
63
|
this.#onIconSlotChange();
|
|
64
|
+
this.#onLeftSlotChange();
|
|
38
65
|
this.#onRightSlotChange();
|
|
66
|
+
this.#onSizeUpdate();
|
|
39
67
|
}
|
|
40
68
|
disconnectedCallback() {
|
|
41
|
-
|
|
42
|
-
this
|
|
43
|
-
this.#$input.removeEventListener('mousedown', this.#onSelectionChange);
|
|
44
|
-
this.#$input.removeEventListener('keydown', this.#onSelectionChange);
|
|
45
|
-
this.#$input.removeEventListener('focus', this.#onInputFocus);
|
|
46
|
-
this.#$input.removeEventListener('blur', this.#onInputBlur);
|
|
47
|
-
this.#$iconSlot.removeEventListener('slotchange', this.#onIconSlotChange);
|
|
48
|
-
this.#$rightSlot.removeEventListener('slotchange', this.#onRightSlotChange);
|
|
49
|
-
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
50
|
-
this.removeEventListener('-focus', this.#onFocusReactHandler);
|
|
51
|
-
this.removeEventListener('-blur', this.#onBlurReactHandler);
|
|
69
|
+
super.disconnectedCallback();
|
|
70
|
+
this.#controller.abort();
|
|
52
71
|
}
|
|
53
72
|
static get observedAttributes() {
|
|
54
|
-
return ['type', 'value', 'placeholder', 'invalid', 'disabled'];
|
|
73
|
+
return ['type', 'value', 'placeholder', 'invalid', 'disabled', 'size', 'data-size'];
|
|
74
|
+
}
|
|
75
|
+
attributeChangedCallback(name, _, newVal) {
|
|
76
|
+
switch (name) {
|
|
77
|
+
case 'type':
|
|
78
|
+
{
|
|
79
|
+
updateLiteralAttribute(this.#$input, inputTypes, 'type', newVal);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 'value':
|
|
83
|
+
{
|
|
84
|
+
const nextVal = newVal ?? '';
|
|
85
|
+
const prevVal = this.#$input.value;
|
|
86
|
+
if (nextVal !== prevVal) {
|
|
87
|
+
const prevCursorPos = this.#$input.selectionEnd;
|
|
88
|
+
const isPrevCursorEnd = prevCursorPos === prevVal.length;
|
|
89
|
+
this.#$input.value = nextVal;
|
|
90
|
+
if (!isPrevCursorEnd) {
|
|
91
|
+
this.#$input.setSelectionRange(this.#cursorPos, this.#cursorPos);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
setClass(this.#$clear, 'active', nextVal.length > 0);
|
|
95
|
+
this.#onRightSlotChange();
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'placeholder':
|
|
99
|
+
{
|
|
100
|
+
this.#$input.placeholder = newVal ?? '';
|
|
101
|
+
updateAttribute(this, 'aria-placeholder', newVal);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case 'invalid':
|
|
105
|
+
{
|
|
106
|
+
updateExplicitBooleanAttribute(this, 'aria-invalid', isAttrTrue(newVal));
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'disabled':
|
|
110
|
+
{
|
|
111
|
+
const isDisabled = isAttrTrue(newVal);
|
|
112
|
+
this.#$input.disabled = isDisabled;
|
|
113
|
+
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case 'size':
|
|
117
|
+
{
|
|
118
|
+
updateAttribute(this, 'data-size', newVal);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case 'data-size':
|
|
122
|
+
{
|
|
123
|
+
if ('production' !== 'production') {
|
|
124
|
+
assertSize(newVal, 'sinch-input');
|
|
125
|
+
}
|
|
126
|
+
this.#onSizeUpdate();
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
55
130
|
}
|
|
56
131
|
get nodeName() {
|
|
57
132
|
return 'input';
|
|
@@ -86,6 +161,12 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
86
161
|
get disabled() {
|
|
87
162
|
return getBooleanAttribute(this, 'disabled');
|
|
88
163
|
}
|
|
164
|
+
set size(size) {
|
|
165
|
+
updateLiteralAttribute(this, sizeValues, 'size', size);
|
|
166
|
+
}
|
|
167
|
+
get size() {
|
|
168
|
+
return getLiteralAttribute(this, sizeValues, 'size', DEFAULT_SIZE);
|
|
169
|
+
}
|
|
89
170
|
get selectionStart() {
|
|
90
171
|
return this.#$input.selectionStart;
|
|
91
172
|
}
|
|
@@ -104,47 +185,6 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
104
185
|
set selectionDirection(value) {
|
|
105
186
|
this.#$input.selectionDirection = value;
|
|
106
187
|
}
|
|
107
|
-
attributeChangedCallback(name, _, newVal) {
|
|
108
|
-
switch (name) {
|
|
109
|
-
case 'type':
|
|
110
|
-
{
|
|
111
|
-
updateLiteralAttribute(this.#$input, inputTypes, 'type', newVal);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case 'value':
|
|
115
|
-
{
|
|
116
|
-
const nextVal = newVal ?? '';
|
|
117
|
-
const prevVal = this.#$input.value;
|
|
118
|
-
if (nextVal !== prevVal) {
|
|
119
|
-
const prevCursorPos = this.#$input.selectionEnd;
|
|
120
|
-
const isPrevCursorEnd = prevCursorPos === prevVal.length;
|
|
121
|
-
this.#$input.value = nextVal;
|
|
122
|
-
if (!isPrevCursorEnd) {
|
|
123
|
-
this.#$input.setSelectionRange(this.#cursorPos, this.#cursorPos);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
case 'placeholder':
|
|
129
|
-
{
|
|
130
|
-
this.#$input.placeholder = newVal ?? '';
|
|
131
|
-
updateAttribute(this, 'aria-placeholder', newVal);
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case 'invalid':
|
|
135
|
-
{
|
|
136
|
-
updateExplicitBooleanAttribute(this, 'aria-invalid', isAttrTrue(newVal));
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
case 'disabled':
|
|
140
|
-
{
|
|
141
|
-
const isDisabled = isAttrTrue(newVal);
|
|
142
|
-
this.#$input.disabled = isDisabled;
|
|
143
|
-
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
188
|
get focusable() {
|
|
149
189
|
return true;
|
|
150
190
|
}
|
|
@@ -162,6 +202,25 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
162
202
|
};
|
|
163
203
|
#onInput = e => {
|
|
164
204
|
e.stopPropagation();
|
|
205
|
+
this.#handleInput();
|
|
206
|
+
};
|
|
207
|
+
#onContextSize = e => {
|
|
208
|
+
if (this.hasAttribute('size')) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
switch (e.detail) {
|
|
212
|
+
case 'l':
|
|
213
|
+
{
|
|
214
|
+
this.setAttribute('data-size', 'm');
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
default:
|
|
218
|
+
{
|
|
219
|
+
this.setAttribute('data-size', 's');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
#handleInput() {
|
|
165
224
|
const nextValue = this.#$input.value;
|
|
166
225
|
const prevValue = this.value;
|
|
167
226
|
if (prevValue !== nextValue) {
|
|
@@ -184,12 +243,18 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
184
243
|
detail: nextValue
|
|
185
244
|
}));
|
|
186
245
|
}
|
|
187
|
-
}
|
|
246
|
+
}
|
|
188
247
|
#onIconSlotChange = () => {
|
|
189
|
-
|
|
248
|
+
const isEmpty = this.#$iconSlot.assignedElements().length === 0;
|
|
249
|
+
setClass(this.#$iconWrapper, 'empty', isEmpty);
|
|
250
|
+
};
|
|
251
|
+
#onLeftSlotChange = () => {
|
|
252
|
+
const isEmpty = this.#$leftSlot.assignedElements().length === 0;
|
|
253
|
+
setClass(this.#$leftWrapper, 'empty', isEmpty);
|
|
190
254
|
};
|
|
191
255
|
#onRightSlotChange = () => {
|
|
192
|
-
|
|
256
|
+
const isEmpty = this.#$rightSlot.assignedElements().length === 0 && this.value.length === 0;
|
|
257
|
+
setClass(this.#$rightWrapper, 'empty', isEmpty);
|
|
193
258
|
};
|
|
194
259
|
#onInputFocus = () => {
|
|
195
260
|
this.dispatchEvent(new CustomEvent('-focus'));
|
|
@@ -197,6 +262,18 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
197
262
|
#onInputBlur = () => {
|
|
198
263
|
this.dispatchEvent(new CustomEvent('-blur'));
|
|
199
264
|
};
|
|
265
|
+
#onClear = () => {
|
|
266
|
+
this.#$input.value = '';
|
|
267
|
+
this.#$input.focus();
|
|
268
|
+
this.#handleInput();
|
|
269
|
+
};
|
|
270
|
+
#onSizeUpdate() {
|
|
271
|
+
if (!this.isConnected) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const size = this.getAttribute('data-size') ?? DEFAULT_SIZE;
|
|
275
|
+
this.#sizeContext.dispatch(size);
|
|
276
|
+
}
|
|
200
277
|
#onChangeReactHandler = e => {
|
|
201
278
|
getReactEventHandler(this, 'on-change')?.(e);
|
|
202
279
|
};
|
package/input/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TSinchElementReact } from '../types';
|
|
2
|
+
import type { TSinchSize } from '../utils/size';
|
|
2
3
|
import type { SyntheticEvent } from 'react';
|
|
3
4
|
export declare type TSinchInputType = 'text' | 'password';
|
|
4
5
|
export declare type TSinchInputElement = HTMLElement & {
|
|
@@ -12,6 +13,8 @@ export declare type TSinchInputElement = HTMLElement & {
|
|
|
12
13
|
invalid: boolean;
|
|
13
14
|
/** Disabled */
|
|
14
15
|
disabled: boolean;
|
|
16
|
+
/** Size, `m` by default */
|
|
17
|
+
size: TSinchSize;
|
|
15
18
|
selectionStart: number | null;
|
|
16
19
|
selectionEnd: number | null;
|
|
17
20
|
selectionDirection: 'forward' | 'backward' | 'none' | null;
|
|
@@ -31,6 +34,8 @@ export declare type TSinchInputElement = HTMLElement & {
|
|
|
31
34
|
setAttribute(name: 'invalid', value: ''): void;
|
|
32
35
|
/** Disabled */
|
|
33
36
|
setAttribute(name: 'disabled', value: ''): void;
|
|
37
|
+
/** Size, `m` by default */
|
|
38
|
+
setAttribute(name: 'size', value: TSinchSize): void;
|
|
34
39
|
};
|
|
35
40
|
export declare type TSinchInputReact = TSinchElementReact<TSinchInputElement> & {
|
|
36
41
|
/** Controlled value, doesn't change on its own and requres an onChange-value state loop */
|
|
@@ -45,6 +50,8 @@ export declare type TSinchInputReact = TSinchElementReact<TSinchInputElement> &
|
|
|
45
50
|
invalid?: boolean;
|
|
46
51
|
/** Disabled */
|
|
47
52
|
disabled?: boolean;
|
|
53
|
+
/** Size, `m` by default */
|
|
54
|
+
size?: TSinchSize;
|
|
48
55
|
/** @deprecated Change value handler */
|
|
49
56
|
onChange?: (e: SyntheticEvent<TSinchInputElement, CustomEvent<string>>) => void;
|
|
50
57
|
/** Change value handler */
|
package/link/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../icons/open-in-new';
|
|
2
2
|
import '../icons/arrow-forward';
|
|
3
3
|
import { defineCustomElement, getBooleanAttribute, getAttribute, updateBooleanAttribute, updateAttribute, NectaryElement, isAttrTrue, getReactEventHandler } from '../utils';
|
|
4
|
-
const templateHTML = '<style>:host{display:inline}a{font:var(--sinch-font-text-m);font-size:inherit;line-height:inherit;color:var(--sinch-color-tropical-500);border-radius:.5em;--sinch-size-icon:1em;--sinch-color-icon:var(--sinch-color-tropical-500)}a:hover{color:var(--sinch-color-tropical-600);--sinch-color-icon:var(--sinch-color-tropical-600)}a:focus-visible{outline:2px solid var(--sinch-color-border-focus);outline-offset:2px}
|
|
4
|
+
const templateHTML = '<style>:host{display:inline}a{font:var(--sinch-font-text-m);font-size:inherit;line-height:inherit;color:var(--sinch-color-tropical-500);border-radius:.5em;--sinch-size-icon:1em;--sinch-color-icon:var(--sinch-color-tropical-500)}a:hover{color:var(--sinch-color-tropical-600);--sinch-color-icon:var(--sinch-color-tropical-600)}a:focus-visible{outline:2px solid var(--sinch-color-border-focus);outline-offset:2px}#external-icon{display:none;margin-right:.2em;vertical-align:-.2em}#standalone-icon{display:none}:host([external]:not([external=false])) #external-icon{display:inline-block}:host([standalone]:not([standalone=false])){display:block}:host([standalone]:not([standalone=false])) a{display:block;font:var(--sinch-font-text-m);font-weight:var(--sinch-font-weight-emphasized);text-decoration:none;border-radius:var(--sinch-shape-radius-m);width:fit-content;--sinch-size-icon:24px}:host([standalone]:not([standalone=false])) #external-icon{margin-right:8px;vertical-align:-7px}:host([standalone]:not([standalone=false]):is([external=false],:not([external]))) #standalone-icon{display:inline-block;vertical-align:-7px;margin-left:8px}:host([disabled]:not([disabled=false])) a{color:var(--sinch-color-tropical-200);pointer-events:none;cursor:initial;--sinch-color-icon:var(--sinch-color-tropical-200)}</style><a referrerpolicy="no-referer" aria-hidden="true"><sinch-icon-open-in-new id="external-icon"></sinch-icon-open-in-new><span id="content"></span><sinch-icon-arrow-forward id="standalone-icon"></sinch-icon-arrow-forward></a>';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-link', class extends NectaryElement {
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nectary/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"files": [
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"theme/*.json",
|
|
5
|
+
"**/*/*.css",
|
|
6
|
+
"**/*/*.json",
|
|
8
7
|
"**/*/*.js",
|
|
9
8
|
"**/*/*.d.ts",
|
|
10
9
|
"types.d.ts",
|
|
@@ -14,8 +13,7 @@
|
|
|
14
13
|
"build": "NODE_ENV=production babel . --extensions '.ts' --out-dir . && tsc --declaration --emitDeclarationOnly"
|
|
15
14
|
},
|
|
16
15
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "^7.19.0"
|
|
18
|
-
"dialog-polyfill": "^0.5.6"
|
|
16
|
+
"@babel/runtime": "^7.19.0"
|
|
19
17
|
},
|
|
20
18
|
"devDependencies": {
|
|
21
19
|
"@babel/cli": "^7.19.3",
|
package/pagination/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../icons/keyboard-arrow-left';
|
|
2
2
|
import '../icons/keyboard-arrow-right';
|
|
3
3
|
import { defineCustomElement, updateAttribute, getIntegerAttribute, setClass, NectaryElement, getRect, getReactEventHandler } from '../utils';
|
|
4
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;justify-content:center;gap:8px;width:100%;box-sizing:border-box}button{all:initial;width:28px;height:28px;box-sizing:border-box;cursor:pointer;text-align:center;contain:strict;--sinch-color-icon:var(--sinch-color-stormy-500)}button:disabled{--sinch-color-icon:var(--sinch-color-stormy-100);cursor:initial}button>*{pointer-events:none}.page{border-radius:50%;font:var(--sinch-font-
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;justify-content:center;gap:8px;width:100%;box-sizing:border-box}button{all:initial;width:28px;height:28px;box-sizing:border-box;cursor:pointer;text-align:center;contain:strict;--sinch-color-icon:var(--sinch-color-stormy-500)}button:disabled{--sinch-color-icon:var(--sinch-color-stormy-100);cursor:initial}button>*{pointer-events:none}.page{border-radius:50%;font:var(--sinch-font-text-m);color:var(--sinch-color-stormy-500)}.page.dots>span{display:none}.page.dots::after{content:"..."}.page.active{font-weight:var(--sinch-font-weight-emphasized);background-color:var(--sinch-color-snow-600);pointer-events:none;cursor:initial}.page.hidden{display:none}#left,#right{display:flex;padding:2px;--sinch-icon-size:24px}</style><div id="wrapper"><button id="left"><sinch-icon-keyboard-arrow-left></sinch-icon-keyboard-arrow-left></button><button class="page"><span>1</span></button><button class="page active"><span>2</span></button><button class="page"><span>3</span></button><button class="page"><span>4</span></button><button class="page"><span>5</span></button><button class="page dots"><span>6</span></button><button class="page"><span>20</span></button><button id="right"><sinch-icon-keyboard-arrow-right></sinch-icon-keyboard-arrow-right></button></div>';
|
|
5
5
|
const NUM_BUTTONS = 7;
|
|
6
6
|
const MIDDLE_BTN_INDEX = Math.floor(NUM_BUTTONS / 2);
|
|
7
7
|
const FIRST_BTN_INDEX = 0;
|
package/pop/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame, isElementFocused, updateIntegerAttribute, getIntegerAttribute, getFirstFocusableElement, getFirstSlotElement, Context, dispatchContextConnectEvent, dispatchContextDisconnectEvent } from '../utils';
|
|
1
|
+
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame, isElementFocused, updateIntegerAttribute, getIntegerAttribute, getFirstFocusableElement, getFirstSlotElement, Context, subscribeContext } from '../utils';
|
|
3
2
|
const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:1;background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:transparent}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}#content{position:relative;z-index:1}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" aria-haspopup="dialog" aria-expanded="false" name="target"></slot><div id="focus" tabindex="-1"></div><dialog id="dialog"><div id="content"><slot name="content"></slot></div><div id="target-open"><slot name="target-open"></slot></div></dialog>';
|
|
4
3
|
import { assertOrientation, disableScroll, enableScroll, orientationValues } from './utils';
|
|
5
4
|
const template = document.createElement('template');
|
|
@@ -8,7 +7,6 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
8
7
|
#$target;
|
|
9
8
|
#$focus;
|
|
10
9
|
#$dialog;
|
|
11
|
-
#isConnected;
|
|
12
10
|
#resizeThrottle;
|
|
13
11
|
#$targetSlot;
|
|
14
12
|
#$targetOpenSlot;
|
|
@@ -30,21 +28,18 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
30
28
|
this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
|
|
31
29
|
this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
|
|
32
30
|
this.#$targetOpenWrapper = shadowRoot.querySelector('#target-open');
|
|
33
|
-
this.#isConnected = false;
|
|
34
31
|
this.#resizeThrottle = throttleAnimationFrame(this.#updateOrientation);
|
|
35
32
|
this.#keydownContext = new Context(this.#$contentSlot, 'keydown');
|
|
36
33
|
this.#visibilityContext = new Context(this.#$contentSlot, 'visibility');
|
|
37
|
-
dialogPolyfill.registerDialog(this.#$dialog);
|
|
38
|
-
|
|
39
|
-
dialogPolyfill.dm.handleFocus_ = function () {};
|
|
40
34
|
}
|
|
41
35
|
connectedCallback() {
|
|
36
|
+
super.connectedCallback();
|
|
42
37
|
this.#controller = new AbortController();
|
|
43
38
|
const {
|
|
44
39
|
signal
|
|
45
40
|
} = this.#controller;
|
|
46
|
-
this.#keydownContext.
|
|
47
|
-
this.#visibilityContext.
|
|
41
|
+
this.#keydownContext.listen(signal);
|
|
42
|
+
this.#visibilityContext.listen(signal);
|
|
48
43
|
this.setAttribute('role', 'dialog');
|
|
49
44
|
this.#$dialog.addEventListener('cancel', this.#onCancel, {
|
|
50
45
|
signal
|
|
@@ -55,22 +50,15 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
55
50
|
this.addEventListener('-close', this.#onCloseReactHandler, {
|
|
56
51
|
signal
|
|
57
52
|
});
|
|
58
|
-
this
|
|
59
|
-
signal
|
|
60
|
-
});
|
|
61
|
-
dispatchContextConnectEvent(this, 'visibility');
|
|
62
|
-
this.#isConnected = true;
|
|
53
|
+
subscribeContext(this, 'visibility', this.#onContextVisibility, signal);
|
|
63
54
|
if (getBooleanAttribute(this, 'open')) {
|
|
64
55
|
this.#onExpand();
|
|
65
56
|
}
|
|
66
57
|
}
|
|
67
58
|
disconnectedCallback() {
|
|
59
|
+
super.disconnectedCallback();
|
|
68
60
|
this.#controller.abort();
|
|
69
|
-
this.#keydownContext.unsubscribe();
|
|
70
|
-
this.#visibilityContext.unsubscribe();
|
|
71
|
-
dispatchContextDisconnectEvent(this, 'visibility');
|
|
72
61
|
this.#onCollapse();
|
|
73
|
-
this.#isConnected = false;
|
|
74
62
|
}
|
|
75
63
|
static get observedAttributes() {
|
|
76
64
|
return ['orientation', 'open'];
|
|
@@ -124,7 +112,9 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
124
112
|
}
|
|
125
113
|
case 'orientation':
|
|
126
114
|
{
|
|
127
|
-
|
|
115
|
+
if ('production' !== 'production') {
|
|
116
|
+
assertOrientation(newVal);
|
|
117
|
+
}
|
|
128
118
|
if (this.#isOpen()) {
|
|
129
119
|
this.#updateOrientation();
|
|
130
120
|
}
|
|
@@ -153,7 +143,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
153
143
|
return item;
|
|
154
144
|
}
|
|
155
145
|
#onExpand() {
|
|
156
|
-
if (!this
|
|
146
|
+
if (!this.isConnected || this.#isOpen()) {
|
|
157
147
|
return;
|
|
158
148
|
}
|
|
159
149
|
|
|
@@ -356,27 +346,15 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
356
346
|
e.stopPropagation();
|
|
357
347
|
};
|
|
358
348
|
#dispatchContentVisibility(isVisible) {
|
|
359
|
-
|
|
360
|
-
$el.dispatchEvent(new CustomEvent('-visibility', {
|
|
361
|
-
detail: isVisible
|
|
362
|
-
}));
|
|
363
|
-
}
|
|
349
|
+
this.#visibilityContext.dispatch(isVisible);
|
|
364
350
|
}
|
|
365
351
|
#onTargetKeydown = e => {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
detail: {
|
|
370
|
-
code: e.code,
|
|
371
|
-
preventDefault: () => {
|
|
372
|
-
isPrevented = true;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}));
|
|
376
|
-
if (isPrevented) {
|
|
352
|
+
this.#keydownContext.dispatch({
|
|
353
|
+
code: e.code,
|
|
354
|
+
preventDefault: () => {
|
|
377
355
|
e.preventDefault();
|
|
378
356
|
}
|
|
379
|
-
}
|
|
357
|
+
});
|
|
380
358
|
};
|
|
381
359
|
#onContextVisibility = e => {
|
|
382
360
|
if (!e.detail) {
|
package/popover/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../pop';
|
|
2
|
-
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateBooleanAttribute, NectaryElement, updateAttribute, getReactEventHandler, isAttrTrue, setClass, rectOverlap,
|
|
3
|
-
const templateHTML = '<style>:host{display:contents}#content-wrapper{position:relative;padding-top:4px}#content{font:var(--sinch-font-
|
|
2
|
+
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateBooleanAttribute, NectaryElement, updateAttribute, getReactEventHandler, isAttrTrue, setClass, rectOverlap, subscribeContext } from '../utils';
|
|
3
|
+
const templateHTML = '<style>:host{display:contents}#content-wrapper{position:relative;padding-top:4px}#content{font:var(--sinch-font-text-m);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);border:1px solid var(--sinch-color-snow-500);border-radius:var(--sinch-shape-radius-m);box-shadow:var(--sinch-elevation-level-2);overflow:hidden}#tip{position:absolute;left:50%;top:13px;transform:translateX(-50%) rotate(180deg);transform-origin:top center;fill:var(--sinch-color-snow-100);stroke:var(--sinch-color-snow-500);stroke-linecap:square;pointer-events:none;display:none}:host([orientation^=top]) #tip{transform:translateX(-50%) rotate(0);top:calc(100% - 13px)}:host([tip]) #tip:not(.hidden){display:block}:host([tip]) #content{box-shadow:none}:host([tip]) #content-wrapper{padding-top:12px;filter:drop-shadow(var(--sinch-elevation-level-2))}:host([orientation^=top]) #content-wrapper{padding-top:0;padding-bottom:4px}:host([orientation^=top][tip]) #content-wrapper{padding-top:0;padding-bottom:12px}</style><sinch-pop id="pop" inset="4"><slot name="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><slot name="content"></slot></div><svg id="tip" width="16" height="9" aria-hidden="true"><path d="m0 0 8 8 8 -8"/></svg></div></sinch-pop>';
|
|
4
4
|
import { assertOrientation, getPopOrientation, orientationValues } from './utils';
|
|
5
5
|
const TIP_SIZE = 16;
|
|
6
6
|
const template = document.createElement('template');
|
|
@@ -29,14 +29,10 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
29
29
|
this.#$pop.addEventListener('-close', this.#onPopClose, {
|
|
30
30
|
signal
|
|
31
31
|
});
|
|
32
|
-
this
|
|
33
|
-
signal
|
|
34
|
-
});
|
|
35
|
-
dispatchContextConnectEvent(this.#$content, 'visibility');
|
|
32
|
+
subscribeContext(this, 'visibility', this.#onContextVisibility, signal);
|
|
36
33
|
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
37
34
|
}
|
|
38
35
|
disconnectedCallback() {
|
|
39
|
-
dispatchContextDisconnectEvent(this.#$content, 'visibility');
|
|
40
36
|
this.#controller.abort();
|
|
41
37
|
}
|
|
42
38
|
#onPopClose = () => {
|
|
@@ -89,8 +85,10 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
89
85
|
switch (name) {
|
|
90
86
|
case 'orientation':
|
|
91
87
|
{
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
if ('production' !== 'production') {
|
|
89
|
+
assertOrientation(newVal);
|
|
90
|
+
}
|
|
91
|
+
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
94
92
|
if (this.#isOpen()) {
|
|
95
93
|
this.#updateTipOrientation();
|
|
96
94
|
}
|
package/radio-option/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{--sinch-color-radio-outer-circle:var(--sinch-color-transparent);--sinch-color-radio-background:var(--sinch-color-snow-100);--sinch-color-radio-border:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-checked:var(--sinch-color-transparent);--sinch-color-radio-border-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-hover:var(--sinch-color-snow-500);--sinch-color-radio-border-hover:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-hover-checked:var(--sinch-color-tropical-100);--sinch-color-radio-border-hover-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-focus:var(--sinch-color-snow-700);--sinch-color-radio-border-focus:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-focus-checked:var(--sinch-color-tropical-200);--sinch-color-radio-border-focus-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-active:var(--sinch-color-stormy-100);--sinch-color-radio-border-active:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-active-checked:var(--sinch-color-tropical-300);--sinch-color-radio-border-active-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-disabled:var(--sinch-color-transparent);--sinch-color-radio-border-disabled:var(--sinch-color-stormy-100);--sinch-color-radio-outer-circle-disabled-checked:var(--sinch-color-transparent);--sinch-color-radio-border-disabled-checked:var(--sinch-color-stormy-100);display:block;outline:0}#wrapper{display:flex;height:32px;box-sizing:border-box;width:100%}#input{all:initial;display:block;width:32px;height:32px;cursor:pointer}#input:disabled{cursor:initial}#icon-container{position:relative;width:32px;height:32px}#input::before{content:"";position:absolute;top:0;left:0;width:32px;height:32px;border-radius:50%;pointer-events:none;background-color:var(--sinch-color-radio-outer-circle);transition:background-color .1s linear}#input::after{content:"";position:absolute;top:6px;left:6px;width:20px;height:20px;border-radius:50%;pointer-events:none;background-color:var(--sinch-color-radio-background);border:2px solid var(--sinch-color-radio-border);transition:background-color .1s linear;box-sizing:border-box}#icon-knob{position:absolute;left:11px;top:11px;width:10px;height:10px;border-radius:50%;transition:opacity .1s linear;opacity:0;background-color:var(--sinch-color-radio-border);pointer-events:none}@media (prefers-reduced-motion){#icon-knob,#input::after,#input::before{transition:none}}#label{align-self:center;flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:8px;font:var(--sinch-font-
|
|
2
|
+
const templateHTML = '<style>:host{--sinch-color-radio-outer-circle:var(--sinch-color-transparent);--sinch-color-radio-background:var(--sinch-color-snow-100);--sinch-color-radio-border:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-checked:var(--sinch-color-transparent);--sinch-color-radio-border-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-hover:var(--sinch-color-snow-500);--sinch-color-radio-border-hover:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-hover-checked:var(--sinch-color-tropical-100);--sinch-color-radio-border-hover-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-focus:var(--sinch-color-snow-700);--sinch-color-radio-border-focus:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-focus-checked:var(--sinch-color-tropical-200);--sinch-color-radio-border-focus-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-active:var(--sinch-color-stormy-100);--sinch-color-radio-border-active:var(--sinch-color-stormy-300);--sinch-color-radio-outer-circle-active-checked:var(--sinch-color-tropical-300);--sinch-color-radio-border-active-checked:var(--sinch-color-tropical-500);--sinch-color-radio-outer-circle-disabled:var(--sinch-color-transparent);--sinch-color-radio-border-disabled:var(--sinch-color-stormy-100);--sinch-color-radio-outer-circle-disabled-checked:var(--sinch-color-transparent);--sinch-color-radio-border-disabled-checked:var(--sinch-color-stormy-100);display:block;outline:0}#wrapper{display:flex;height:32px;box-sizing:border-box;width:100%}#input{all:initial;display:block;width:32px;height:32px;cursor:pointer}#input:disabled{cursor:initial}#icon-container{position:relative;width:32px;height:32px}#input::before{content:"";position:absolute;top:0;left:0;width:32px;height:32px;border-radius:50%;pointer-events:none;background-color:var(--sinch-color-radio-outer-circle);transition:background-color .1s linear}#input::after{content:"";position:absolute;top:6px;left:6px;width:20px;height:20px;border-radius:50%;pointer-events:none;background-color:var(--sinch-color-radio-background);border:2px solid var(--sinch-color-radio-border);transition:background-color .1s linear;box-sizing:border-box}#icon-knob{position:absolute;left:11px;top:11px;width:10px;height:10px;border-radius:50%;transition:opacity .1s linear;opacity:0;background-color:var(--sinch-color-radio-border);pointer-events:none}@media (prefers-reduced-motion){#icon-knob,#input::after,#input::before{transition:none}}#label{align-self:center;flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:8px;font:var(--sinch-font-text-m);color:var(--sinch-color-text-default)}:host([disabled]:not([disabled=false])) #label{color:var(--sinch-color-stormy-200)}#input:checked::before{background-color:var(--sinch-color-radio-outer-circle-checked)}#input:checked::after{border-color:var(--sinch-color-radio-border-checked)}#input:checked~#icon-knob{opacity:1;background-color:var(--sinch-color-radio-border-checked)}#input:focus::before{background-color:var(--sinch-color-radio-outer-circle-focus)}#input:focus::after{border-color:var(--sinch-color-radio-border-focus)}#input:focus~#icon-knob{background-color:var(--sinch-color-radio-border-focus)}#input:hover::before{background-color:var(--sinch-color-radio-outer-circle-hover)}#input:hover::after{border-color:var(--sinch-color-radio-border-hover)}#input:hover~#icon-knob{background-color:var(--sinch-color-radio-border-hover)}#input:active::before{background-color:var(--sinch-color-radio-outer-circle-active)}#input:active::after{border-color:var(--sinch-color-radio-border-active)}#input:active~#icon-knob{background-color:var(--sinch-color-radio-border-active)}#input:disabled::before{background-color:var(--sinch-color-radio-outer-circle-disabled)}#input:disabled::after{border-color:var(--sinch-color-radio-border-disabled)}#input:disabled~#icon-knob{background-color:var(--sinch-color-radio-border-disabled)}#input:focus:checked::before{background-color:var(--sinch-color-radio-outer-circle-focus-checked)}#input:focus:checked::after{border-color:var(--sinch-color-radio-border-focus-checked)}#input:focus:checked~#icon-knob{opacity:1;background-color:var(--sinch-color-radio-border-focus-checked)}#input:hover:checked::before{background-color:var(--sinch-color-radio-outer-circle-hover-checked)}#input:hover:checked::after{border-color:var(--sinch-color-radio-border-hover-checked)}#input:hover:checked~#icon-knob{opacity:1;background-color:var(--sinch-color-radio-border-hover-checked)}#input:active:checked::before{background-color:var(--sinch-color-radio-outer-circle-active-checked)}#input:active:checked::after{border-color:var(--sinch-color-radio-border-active-checked)}#input:active:checked~#icon-knob{opacity:1;background-color:var(--sinch-color-radio-border-active-checked)}#input:disabled:checked::before{background-color:var(--sinch-color-radio-outer-circle-disabled-checked)}#input:disabled:checked::after{border-color:var(--sinch-color-radio-border-disabled-checked)}#input:disabled:checked~#icon-knob{opacity:1;background-color:var(--sinch-color-radio-border-disabled-checked)}</style><div id="wrapper"><div id="icon-container"><input id="input" type="radio"/><div id="icon-knob"></div></div><label for="input" id="label"></label></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-radio-option', class extends NectaryElement {
|
package/segment/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import '../title';
|
|
2
2
|
import { getTitleLevelFromType } from '../title/utils';
|
|
3
3
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute, updateLiteralAttribute } from '../utils';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { assertSize, DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
5
|
+
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;gap:12px;width:100%;height:100%;border:1px solid var(--sinch-color-snow-700);border-radius:var(--sinch-shape-radius-l);box-sizing:border-box;background-color:var(--sinch-color-snow-100);color:var(--sinch-color-text-default);font:var(--sinch-font-text-m);padding:8px 0 16px}#header{display:flex;flex-direction:row;align-items:center;height:48px;gap:8px;padding:0 24px;--sinch-size-icon:32px}#caption{color:var(--sinch-color-text-default);min-width:1em}#info{display:flex;flex-direction:row;align-items:center;gap:8px;margin-left:auto;align-self:stretch}#info.empty{display:none}#preview{flex:1;flex-basis:auto;height:48px;min-width:0;overflow:hidden;margin-left:24px}#preview.empty{display:none}#info.empty+#collapse{margin-left:auto}#collapse.empty{display:none}#preview:not(.empty)+#info.empty+#collapse:not(.empty),#preview:not(.empty)+#info:not(.empty){margin-left:24px}#content-wrapper{flex:1;min-height:0;overflow-y:auto;padding:4px 24px}#action{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;padding:0 24px}#action.empty{display:none}:host([collapsed]:not([collapsed=false])) :is(#content-wrapper,#action){display:none}:host([collapsed]:not([collapsed=false])) #wrapper{padding-bottom:8px}::slotted([slot=icon]){margin-right:8px}</style><div id="wrapper"><div id="header"><slot name="icon"></slot><sinch-title id="caption" level="3" type="m" ellipsis></sinch-title><div id="preview"><slot name="preview"></slot></div><div id="info"><slot name="info"></slot></div><div id="collapse"><slot name="collapse"></slot></div></div><div id="content-wrapper"><slot name="content"></slot></div><div id="action"><slot name="action"></slot></div></div>';
|
|
6
|
+
import { getTitleTypeFromSize } from './utils';
|
|
6
7
|
const template = document.createElement('template');
|
|
7
8
|
template.innerHTML = templateHTML;
|
|
8
9
|
defineCustomElement('sinch-segment', class extends NectaryElement {
|
|
@@ -62,9 +63,12 @@ defineCustomElement('sinch-segment', class extends NectaryElement {
|
|
|
62
63
|
}
|
|
63
64
|
case 'size':
|
|
64
65
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
if ('production' !== 'production') {
|
|
67
|
+
assertSize(newVal, 'sinch-segment');
|
|
68
|
+
}
|
|
69
|
+
const titleType = getTitleTypeFromSize(this.size);
|
|
70
|
+
updateAttribute(this.#$caption, 'type', titleType);
|
|
71
|
+
updateAttribute(this.#$caption, 'level', getTitleLevelFromType(titleType));
|
|
68
72
|
break;
|
|
69
73
|
}
|
|
70
74
|
}
|
|
@@ -82,7 +86,7 @@ defineCustomElement('sinch-segment', class extends NectaryElement {
|
|
|
82
86
|
return getBooleanAttribute(this, 'collapsed');
|
|
83
87
|
}
|
|
84
88
|
get size() {
|
|
85
|
-
return getLiteralAttribute(this, sizeValues, 'size',
|
|
89
|
+
return getLiteralAttribute(this, sizeValues, 'size', DEFAULT_SIZE);
|
|
86
90
|
}
|
|
87
91
|
set size(value) {
|
|
88
92
|
updateLiteralAttribute(this, sizeValues, 'size', value);
|
package/segment/types.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { TRect, TSinchElementReact } from '../types';
|
|
2
|
-
|
|
2
|
+
import type { TSinchSize } from '../utils/size';
|
|
3
3
|
export declare type TSinchSegmentElement = HTMLElement & {
|
|
4
4
|
caption: string;
|
|
5
5
|
collapsed: boolean;
|
|
6
|
-
size:
|
|
6
|
+
size: TSinchSize;
|
|
7
7
|
readonly collapseButtonRect: TRect | null;
|
|
8
8
|
setAttribute(name: 'caption', value: string): void;
|
|
9
9
|
setAttribute(name: 'collapsed', value: ''): void;
|
|
10
|
-
setAttribute(name: 'size', value:
|
|
10
|
+
setAttribute(name: 'size', value: TSinchSize): void;
|
|
11
11
|
};
|
|
12
12
|
export declare type TSinchSegmentReact = TSinchElementReact<TSinchSegmentElement> & {
|
|
13
13
|
caption: string;
|
|
14
14
|
collapsed?: boolean;
|
|
15
|
-
size?:
|
|
15
|
+
size?: TSinchSize;
|
|
16
16
|
};
|