@nectary/components 2.8.4 → 2.8.6
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/dialog/index.js +1 -1
- package/field/index.js +10 -2
- package/field/types.d.ts +2 -2
- package/input/index.js +17 -1
- package/input/types.d.ts +6 -0
- package/package.json +1 -1
- package/utils/debounce.js +2 -2
- package/utils/throttle.js +1 -1
package/dialog/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import '../icon';
|
|
|
3
3
|
import '../stop-events';
|
|
4
4
|
import '../title';
|
|
5
5
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getRect, isAttrTrue, updateAttribute, getReactEventHandler, NectaryElement, updateBooleanAttribute, setClass, isTargetEqual, isAttrEqual } from '../utils';
|
|
6
|
-
const templateHTML = '<style>:host{display:contents;--sinch-comp-dialog-max-width:512px;--sinch-comp-dialog-max-height:90vh}#dialog{position:fixed;left:0;right:0;margin:auto;display:flex;flex-direction:column;padding:24px 0;max-width:var(--sinch-comp-dialog-max-width);max-height:var(--sinch-comp-dialog-max-height);border-radius:var(--sinch-comp-dialog-shape-radius);box-sizing:border-box;contain:content;background-color:var(--sinch-comp-dialog-color-default-background-initial);border:none;box-shadow:var(--sinch-comp-dialog-shadow);outline:0}#dialog:not([open]){display:none}dialog::backdrop{background-color:#000;opacity:.55}#header{display:flex;flex-direction:row;align-items:flex-start;margin-bottom:12px;padding:0 24px;gap:8px;--sinch-global-size-icon:24px;--sinch-global-color-icon:var(--sinch-comp-dialog-color-default-icon-initial)}#caption{--sinch-global-color-text:var(--sinch-comp-dialog-color-default-title-initial);--sinch-comp-title-font:var(--sinch-comp-dialog-font-title)}#content{min-height:0;overflow:auto;padding:4px 24px}#action{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;margin-top:20px;padding:0 24px}#action.empty{display:none}#close{position:relative;left:4px;top:-4px;margin-left:auto}</style><dialog id="dialog"><div id="header"><slot id="icon" name="icon"></slot><sinch-title id="caption" type="m" level="3"></sinch-title><sinch-icon-button id="close" size="s"><sinch-icon id="icon-close" slot="icon" name="close"></sinch-icon></sinch-icon-button></div><div id="content"><sinch-stop-events events="close"><slot name="content"></slot></sinch-stop-events></div><div id="action"><sinch-stop-events events="close"><slot name="buttons"></slot></sinch-stop-events></div></dialog>';
|
|
6
|
+
const templateHTML = '<style>:host{display:contents;--sinch-comp-dialog-max-width:512px;--sinch-comp-dialog-max-height:90vh;--sinch-comp-dialog-width:fit-content}#dialog{position:fixed;left:0;right:0;margin:auto;display:flex;flex-direction:column;padding:24px 0;width:var(--sinch-comp-dialog-width);max-width:var(--sinch-comp-dialog-max-width);max-height:var(--sinch-comp-dialog-max-height);border-radius:var(--sinch-comp-dialog-shape-radius);box-sizing:border-box;contain:content;background-color:var(--sinch-comp-dialog-color-default-background-initial);border:none;box-shadow:var(--sinch-comp-dialog-shadow);outline:0}#dialog:not([open]){display:none}dialog::backdrop{background-color:#000;opacity:.55}#header{display:flex;flex-direction:row;align-items:flex-start;margin-bottom:12px;padding:0 24px;gap:8px;--sinch-global-size-icon:24px;--sinch-global-color-icon:var(--sinch-comp-dialog-color-default-icon-initial)}#caption{--sinch-global-color-text:var(--sinch-comp-dialog-color-default-title-initial);--sinch-comp-title-font:var(--sinch-comp-dialog-font-title)}#content{min-height:0;overflow:auto;padding:4px 24px}#action{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;margin-top:20px;padding:0 24px}#action.empty{display:none}#close{position:relative;left:4px;top:-4px;margin-left:auto}</style><dialog id="dialog"><div id="header"><slot id="icon" name="icon"></slot><sinch-title id="caption" type="m" level="3"></sinch-title><sinch-icon-button id="close" size="s"><sinch-icon id="icon-close" slot="icon" name="close"></sinch-icon></sinch-icon-button></div><div id="content"><sinch-stop-events events="close"><slot name="content"></slot></sinch-stop-events></div><div id="action"><sinch-stop-events events="close"><slot name="buttons"></slot></sinch-stop-events></div></dialog>';
|
|
7
7
|
import { disableScroll, enableScroll } from './utils';
|
|
8
8
|
const template = document.createElement('template');
|
|
9
9
|
template.innerHTML = templateHTML;
|
package/field/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getFirstSlotElement, isAttrEqual, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;width:100%}#bottom,#top{display:flex;align-items:baseline}#top{height:24px;margin-bottom:2px}#additional,#invalid,#label,#optional{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#label{font:var(--sinch-comp-field-font-label);color:var(--sinch-comp-field-color-default-label-initial)}#optional{flex:1;font:var(--sinch-comp-field-font-optional);color:var(--sinch-comp-field-color-default-optional-initial);text-align:right}#additional{flex:1;text-align:right;font:var(--sinch-comp-field-font-additional);color:var(--sinch-comp-field-color-default-additional-initial);line-height:20px;margin-top:2px}#additional:empty{display:none}#invalid{font:var(--sinch-comp-field-font-invalid);color:var(--sinch-comp-field-color-invalid-text-initial);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]) #label{color:var(--sinch-comp-field-color-disabled-label-initial)}:host([disabled]) #additional{color:var(--sinch-comp-field-color-disabled-additional-initial)}:host([disabled]) #optional{color:var(--sinch-comp-field-color-disabled-optional-initial)}</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>';
|
|
2
|
+
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;width:100%}#bottom,#top{display:flex;align-items:baseline}#top{height:24px;margin-bottom:2px}#top.empty{display:none}#additional,#invalid,#label,#optional{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#label{font:var(--sinch-comp-field-font-label);color:var(--sinch-comp-field-color-default-label-initial)}#optional{flex:1;font:var(--sinch-comp-field-font-optional);color:var(--sinch-comp-field-color-default-optional-initial);text-align:right}#additional{flex:1;text-align:right;font:var(--sinch-comp-field-font-additional);color:var(--sinch-comp-field-color-default-additional-initial);line-height:20px;margin-top:2px}#additional:empty{display:none}#invalid{font:var(--sinch-comp-field-font-invalid);color:var(--sinch-comp-field-color-invalid-text-initial);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]) #label{color:var(--sinch-comp-field-color-disabled-label-initial)}:host([disabled]) #additional{color:var(--sinch-comp-field-color-disabled-additional-initial)}:host([disabled]) #optional{color:var(--sinch-comp-field-color-disabled-optional-initial)}</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>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-field', class extends NectaryElement {
|
|
@@ -15,6 +15,7 @@ defineCustomElement('sinch-field', class extends NectaryElement {
|
|
|
15
15
|
super();
|
|
16
16
|
const shadowRoot = this.attachShadow();
|
|
17
17
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
18
|
+
this.topSection = shadowRoot.querySelector('#top');
|
|
18
19
|
this.#$label = shadowRoot.querySelector('#label');
|
|
19
20
|
this.#$optionalText = shadowRoot.querySelector('#optional');
|
|
20
21
|
this.#$additionalText = shadowRoot.querySelector('#additional');
|
|
@@ -31,6 +32,7 @@ defineCustomElement('sinch-field', class extends NectaryElement {
|
|
|
31
32
|
const options = {
|
|
32
33
|
signal
|
|
33
34
|
};
|
|
35
|
+
this.shouldShowTopSection();
|
|
34
36
|
this.#$label.addEventListener('click', this.#onLabelClick, options);
|
|
35
37
|
this.#$tooltipSlot.addEventListener('slotchange', this.#onTooltipSlotChange, options);
|
|
36
38
|
}
|
|
@@ -41,6 +43,11 @@ defineCustomElement('sinch-field', class extends NectaryElement {
|
|
|
41
43
|
static get observedAttributes() {
|
|
42
44
|
return ['label', 'optionaltext', 'additionaltext', 'invalidtext', 'disabled'];
|
|
43
45
|
}
|
|
46
|
+
shouldShowTopSection() {
|
|
47
|
+
const label = getAttribute(this, 'label');
|
|
48
|
+
const optionaltext = getAttribute(this, 'optionaltext');
|
|
49
|
+
setClass(this.topSection, 'empty', label === null && optionaltext === null);
|
|
50
|
+
}
|
|
44
51
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
45
52
|
switch (name) {
|
|
46
53
|
case 'label':
|
|
@@ -72,12 +79,13 @@ defineCustomElement('sinch-field', class extends NectaryElement {
|
|
|
72
79
|
break;
|
|
73
80
|
}
|
|
74
81
|
}
|
|
82
|
+
this.shouldShowTopSection();
|
|
75
83
|
}
|
|
76
84
|
set label(value) {
|
|
77
85
|
updateAttribute(this, 'label', value);
|
|
78
86
|
}
|
|
79
87
|
get label() {
|
|
80
|
-
return getAttribute(this, 'label'
|
|
88
|
+
return getAttribute(this, 'label');
|
|
81
89
|
}
|
|
82
90
|
set optionalText(value) {
|
|
83
91
|
updateAttribute(this, 'optionaltext', value);
|
package/field/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TSinchElementReact } from '../types';
|
|
2
2
|
export type TSinchFieldElement = HTMLElement & {
|
|
3
3
|
/** Label */
|
|
4
|
-
label: string;
|
|
4
|
+
label: string | null;
|
|
5
5
|
/** Optional text */
|
|
6
6
|
optionalText: string | null;
|
|
7
7
|
/** Additional text */
|
|
@@ -23,7 +23,7 @@ export type TSinchFieldElement = HTMLElement & {
|
|
|
23
23
|
};
|
|
24
24
|
export type TSinchFieldReact = TSinchElementReact<TSinchFieldElement> & {
|
|
25
25
|
/** Label that shows in UI */
|
|
26
|
-
label
|
|
26
|
+
label?: string;
|
|
27
27
|
/** Optional text */
|
|
28
28
|
optionalText?: string;
|
|
29
29
|
/** Additional text */
|
package/input/index.js
CHANGED
|
@@ -79,7 +79,7 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
79
79
|
this.#controller = null;
|
|
80
80
|
}
|
|
81
81
|
static get observedAttributes() {
|
|
82
|
-
return ['type', 'value', 'placeholder', 'mask', 'invalid', 'disabled', 'size', 'autocomplete', 'data-size', 'aria-label'];
|
|
82
|
+
return ['type', 'value', 'placeholder', 'mask', 'invalid', 'disabled', 'size', 'autocomplete', 'autofocus', 'data-size', 'aria-label'];
|
|
83
83
|
}
|
|
84
84
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
85
85
|
switch (name) {
|
|
@@ -150,6 +150,16 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
150
150
|
updateBooleanAttribute(this, name, isDisabled);
|
|
151
151
|
break;
|
|
152
152
|
}
|
|
153
|
+
case 'autofocus':
|
|
154
|
+
{
|
|
155
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const isAutofocus = isAttrTrue(newVal);
|
|
159
|
+
this.#$input.autofocus = isAutofocus;
|
|
160
|
+
updateBooleanAttribute(this, name, isAutofocus);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
153
163
|
case 'size':
|
|
154
164
|
{
|
|
155
165
|
updateAttribute(this, 'data-size', newVal);
|
|
@@ -208,6 +218,12 @@ defineCustomElement('sinch-input', class extends NectaryElement {
|
|
|
208
218
|
get disabled() {
|
|
209
219
|
return getBooleanAttribute(this, 'disabled');
|
|
210
220
|
}
|
|
221
|
+
set autofocus(isAutofocus) {
|
|
222
|
+
updateBooleanAttribute(this, 'autofocus', isAutofocus);
|
|
223
|
+
}
|
|
224
|
+
get autofocus() {
|
|
225
|
+
return getBooleanAttribute(this, 'autofocus');
|
|
226
|
+
}
|
|
211
227
|
set size(size) {
|
|
212
228
|
updateLiteralAttribute(this, sizeValues, 'size', size);
|
|
213
229
|
}
|
package/input/types.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type TSinchInputElement = HTMLElement & {
|
|
|
20
20
|
invalid: boolean;
|
|
21
21
|
/** Disabled */
|
|
22
22
|
disabled: boolean;
|
|
23
|
+
/** Whether the input should be autocofused */
|
|
24
|
+
autofocus: boolean;
|
|
23
25
|
/** Size, `m` by default */
|
|
24
26
|
size: TSinchSize;
|
|
25
27
|
selectionStart: number | null;
|
|
@@ -46,6 +48,8 @@ export type TSinchInputElement = HTMLElement & {
|
|
|
46
48
|
setAttribute(name: 'invalid', value: ''): void;
|
|
47
49
|
/** Disabled */
|
|
48
50
|
setAttribute(name: 'disabled', value: ''): void;
|
|
51
|
+
/** Autofocus */
|
|
52
|
+
setAttribute(name: 'autofocus', value: ''): void;
|
|
49
53
|
/** Size, `m` by default */
|
|
50
54
|
setAttribute(name: 'size', value: TSinchSize): void;
|
|
51
55
|
};
|
|
@@ -66,6 +70,8 @@ export type TSinchInputReact = TSinchElementReact<TSinchInputElement> & {
|
|
|
66
70
|
invalid?: boolean;
|
|
67
71
|
/** Disabled */
|
|
68
72
|
disabled?: boolean;
|
|
73
|
+
/** Autofocus */
|
|
74
|
+
autofocus?: boolean;
|
|
69
75
|
/** Size, `m` by default */
|
|
70
76
|
size?: TSinchSize;
|
|
71
77
|
/** Change value handler */
|
package/package.json
CHANGED
package/utils/debounce.js
CHANGED
|
@@ -18,5 +18,5 @@ const createDebounce = (delayFn, cancelFn) => cb => {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
export const debounceTimeout = ms => createDebounce(cb =>
|
|
22
|
-
export const debounceAnimationFrame = createDebounce(
|
|
21
|
+
export const debounceTimeout = ms => createDebounce(cb => globalThis.setTimeout(cb, ms), globalThis.clearTimeout);
|
|
22
|
+
export const debounceAnimationFrame = createDebounce(globalThis.requestAnimationFrame, globalThis.cancelAnimationFrame);
|
package/utils/throttle.js
CHANGED
|
@@ -17,4 +17,4 @@ const createThrottle = (delayFn, cancelFn) => cb => {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
export const throttleAnimationFrame = createThrottle(
|
|
20
|
+
export const throttleAnimationFrame = createThrottle(globalThis.requestAnimationFrame, globalThis.cancelAnimationFrame);
|