@nectary/components 0.38.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/types.d.ts +1 -0
- 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.d.ts +2 -0
- package/card/index.js +24 -87
- 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 +196 -287
- package/date-picker/types.d.ts +25 -1
- package/dialog/index.d.ts +1 -0
- package/dialog/index.js +72 -143
- 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 +30 -82
- 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/pagination/types.d.ts +1 -0
- package/popover/index.js +224 -294
- package/progress/index.js +9 -28
- package/radio/index.js +103 -169
- package/radio/types.d.ts +1 -0
- package/radio-option/index.js +24 -48
- package/segment/index.js +50 -131
- package/segment-collapse/index.js +24 -49
- package/segment-collapse/types.d.ts +1 -0
- package/segmented-control/index.js +36 -73
- package/segmented-control/types.d.ts +1 -0
- package/segmented-control-option/index.js +41 -87
- package/segmented-icon-control/index.js +47 -84
- package/segmented-icon-control/types.d.ts +1 -0
- 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/{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/types.d.ts +1 -0
- package/tabs-option/index.js +20 -44
- package/tag/index.d.ts +1 -1
- package/tag/index.js +42 -36
- 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 +224 -368
- package/time-picker/types.d.ts +5 -1
- package/title/index.js +6 -20
- package/toast/index.d.ts +17 -0
- package/toast/index.js +115 -0
- package/toast/types.d.ts +28 -0
- package/toast/utils.d.ts +5 -0
- package/toast/utils.js +6 -0
- package/toast-manager/index.d.ts +17 -0
- package/toast-manager/index.js +195 -0
- package/toast-manager/types.d.ts +7 -0
- package/toggle/index.js +55 -108
- package/toggle/types.d.ts +1 -0
- 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} +18 -9
- package/{utils.js → utils/index.js} +118 -39
- package/vertical-stepper/index.js +29 -50
- package/vertical-stepper-item/index.js +13 -37
- package/card-button/index.d.ts +0 -11
- package/card-button/index.js +0 -77
- package/card-button/types.d.ts +0 -12
- package/card-link/index.d.ts +0 -12
- package/card-link/index.js +0 -115
- package/card-link/types.d.ts +0 -14
- package/dropdown/index.d.ts +0 -12
- package/dropdown/index.js +0 -415
- package/dropdown/types.d.ts +0 -30
- package/dropdown-text-option/index.js +0 -104
- package/dropdown-text-option/types.d.ts +0 -16
- package/search/index.d.ts +0 -14
- package/search/index.js +0 -523
- package/search/types.d.ts +0 -25
- package/search-option/index.d.ts +0 -11
- package/search-option/index.js +0 -55
- package/search-option/types.d.ts +0 -9
- 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 -2
- package/tag/utils.js +0 -1
- package/tag-close/index.d.ts +0 -12
- package/tag-close/index.js +0 -38
- package/tag-close/types.d.ts +0 -3
- package/tag-close/types.js +0 -1
- /package/{card-button → chip}/types.js +0 -0
- /package/{card-link → color-menu}/types.js +0 -0
- /package/{dropdown-text-option → color-swatch}/types.js +0 -0
- /package/{dropdown → select-button}/types.js +0 -0
- /package/{search → select-menu}/types.js +0 -0
- /package/{search-option → select-menu-option}/types.js +0 -0
- /package/{select → toast}/types.js +0 -0
- /package/{select-option → toast-manager}/types.js +0 -0
package/toggle/index.js
CHANGED
|
@@ -1,116 +1,36 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$input, _$label, _onInput, _onCheckboxFocus, _onCheckboxBlur, _onChangeReactHandler, _onFocusReactHandler, _onBlurReactHandler;
|
|
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, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
|
|
11
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle
|
|
2
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;box-sizing:border-box;width:100%;height:32px}:host([small]:not([small=false])) #wrapper{font:var(--sinch-font-small-text)}#input{all:initial;display:block;position:absolute;left:0;top:6px;width:40px;height:20px;cursor:pointer;pointer-events:initial}#input:disabled{cursor:initial}:host([small]:not([small=false])) #input{width:32px;height:16px;top:8px}#input:focus-visible::after{position:absolute;content:"";left:-4px;top:-4px;right:-4px;bottom:-4px;border:2px solid var(--sinch-color-aqua-400);border-radius:18px;pointer-events:none}:host([small]:not([small=false])) #input:focus-visible::after{border-radius:14px}@supports not selector(:focus-visible){#input:focus::after{position:absolute;content:"";left:-4px;top:-4px;right:-4px;bottom:-4px;border:2px solid var(--sinch-color-aqua-400);border-radius:18px;pointer-events:none}:host([small]:not([small=false])) #input:focus::after{border-radius:14px}}#knob-container{position:relative;box-sizing:border-box;width:40px;height:20px;border-radius:10px;pointer-events:none;padding:2px;background-color:var(--sinch-color-stormy-100);overflow:hidden}:host([small]:not([small=false])) #knob-container{width:32px;height:16px;border-radius:8px}#input:checked~#knob-container{background-color:var(--sinch-color-tropical-500)}#knob{position:relative;box-sizing:border-box;width:16px;height:16px;border-radius:50%;background-color:var(--sinch-color-snow-100);box-shadow:var(--sinch-elevation-level-1);transform:translateX(0);transition:transform .1s ease-in-out}:host([small]:not([small=false])) #knob{width:12px;height:12px}#input:checked~#knob-container>#knob{transform:translateX(20px)}:host([small]:not([small=false])) #input:checked~#knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-font-body);color:var(--sinch-color-snow-100);text-transform:uppercase;font-size:8px;line-height:16px;display:none;position:absolute;top:0;padding:0 3px}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::after,:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::before{display:block}@media (prefers-reduced-motion){#knob{transition:none}}#label{flex:1;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:8px;font:var(--sinch-font-body);color:var(--sinch-color-text-default)}#label:empty{display:none}#input:disabled~#label{color:var(--sinch-color-stormy-200)}#input:disabled~#knob-container{background-color:var(--sinch-color-snow-700)}#input:checked:disabled~#knob-container{background-color:var(--sinch-color-tropical-100)}</style><div id="wrapper"><input id="input" type="checkbox"><div id="knob-container"><div id="knob"></div></div><label id="label" for="input"></label></div>';
|
|
12
3
|
const template = document.createElement('template');
|
|
13
4
|
template.innerHTML = templateHTML;
|
|
14
|
-
defineCustomElement('sinch-toggle',
|
|
5
|
+
defineCustomElement('sinch-toggle', class extends NectaryElement {
|
|
6
|
+
#$input;
|
|
7
|
+
#$label;
|
|
8
|
+
|
|
15
9
|
constructor() {
|
|
16
10
|
super();
|
|
17
|
-
|
|
18
|
-
_classPrivateFieldInitSpec(this, _$input, {
|
|
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, _onInput, {
|
|
29
|
-
writable: true,
|
|
30
|
-
value: e => {
|
|
31
|
-
e.stopPropagation();
|
|
32
|
-
|
|
33
|
-
const isChecked = _classPrivateFieldGet(this, _$input).checked;
|
|
34
|
-
|
|
35
|
-
_classPrivateFieldGet(this, _$input).checked = this.checked;
|
|
36
|
-
this.dispatchEvent(new CustomEvent('change', {
|
|
37
|
-
detail: isChecked,
|
|
38
|
-
bubbles: true
|
|
39
|
-
}));
|
|
40
|
-
this.dispatchEvent(new CustomEvent('-change', {
|
|
41
|
-
detail: isChecked
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
_classPrivateFieldInitSpec(this, _onCheckboxFocus, {
|
|
47
|
-
writable: true,
|
|
48
|
-
value: () => {
|
|
49
|
-
this.dispatchEvent(new CustomEvent('-focus'));
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
_classPrivateFieldInitSpec(this, _onCheckboxBlur, {
|
|
54
|
-
writable: true,
|
|
55
|
-
value: () => {
|
|
56
|
-
this.dispatchEvent(new CustomEvent('-blur'));
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
_classPrivateFieldInitSpec(this, _onChangeReactHandler, {
|
|
61
|
-
writable: true,
|
|
62
|
-
value: e => {
|
|
63
|
-
getReactEventHandler(this, 'on-change')?.(e);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
_classPrivateFieldInitSpec(this, _onFocusReactHandler, {
|
|
68
|
-
writable: true,
|
|
69
|
-
value: e => {
|
|
70
|
-
getReactEventHandler(this, 'on-focus')?.(e);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
_classPrivateFieldInitSpec(this, _onBlurReactHandler, {
|
|
75
|
-
writable: true,
|
|
76
|
-
value: e => {
|
|
77
|
-
getReactEventHandler(this, 'on-blur')?.(e);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
11
|
const shadowRoot = this.attachShadow();
|
|
82
12
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
_classPrivateFieldSet(this, _$label, shadowRoot.querySelector('label'));
|
|
13
|
+
this.#$input = shadowRoot.querySelector('#input');
|
|
14
|
+
this.#$label = shadowRoot.querySelector('#label');
|
|
87
15
|
}
|
|
88
16
|
|
|
89
17
|
connectedCallback() {
|
|
90
18
|
this.setAttribute('role', 'checkbox');
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
_classPrivateFieldGet(this, _$input).addEventListener('blur', _classPrivateFieldGet(this, _onCheckboxBlur));
|
|
98
|
-
|
|
99
|
-
this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
|
|
100
|
-
this.addEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
|
|
101
|
-
this.addEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
|
|
19
|
+
this.#$input.addEventListener('input', this.#onInput);
|
|
20
|
+
this.#$input.addEventListener('focus', this.#onCheckboxFocus);
|
|
21
|
+
this.#$input.addEventListener('blur', this.#onCheckboxBlur);
|
|
22
|
+
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
23
|
+
this.addEventListener('-focus', this.#onFocusReactHandler);
|
|
24
|
+
this.addEventListener('-blur', this.#onBlurReactHandler);
|
|
102
25
|
}
|
|
103
26
|
|
|
104
27
|
disconnectedCallback() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
|
|
112
|
-
this.removeEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
|
|
113
|
-
this.removeEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
|
|
28
|
+
this.#$input.removeEventListener('input', this.#onInput);
|
|
29
|
+
this.#$input.removeEventListener('focus', this.#onCheckboxFocus);
|
|
30
|
+
this.#$input.removeEventListener('blur', this.#onCheckboxBlur);
|
|
31
|
+
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
32
|
+
this.removeEventListener('-focus', this.#onFocusReactHandler);
|
|
33
|
+
this.removeEventListener('-blur', this.#onBlurReactHandler);
|
|
114
34
|
}
|
|
115
35
|
|
|
116
36
|
static get observedAttributes() {
|
|
@@ -162,21 +82,21 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
|
|
|
162
82
|
}
|
|
163
83
|
|
|
164
84
|
get text() {
|
|
165
|
-
return getAttribute(this, 'text'
|
|
85
|
+
return getAttribute(this, 'text');
|
|
166
86
|
}
|
|
167
87
|
|
|
168
88
|
attributeChangedCallback(name, _, newVal) {
|
|
169
89
|
switch (name) {
|
|
170
90
|
case 'text':
|
|
171
91
|
{
|
|
172
|
-
|
|
92
|
+
this.#$label.textContent = newVal;
|
|
173
93
|
break;
|
|
174
94
|
}
|
|
175
95
|
|
|
176
96
|
case 'checked':
|
|
177
97
|
{
|
|
178
98
|
const isChecked = isAttrTrue(newVal);
|
|
179
|
-
|
|
99
|
+
this.#$input.checked = isChecked;
|
|
180
100
|
updateExplicitBooleanAttribute(this, 'aria-checked', isChecked);
|
|
181
101
|
break;
|
|
182
102
|
}
|
|
@@ -184,7 +104,7 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
|
|
|
184
104
|
case 'disabled':
|
|
185
105
|
{
|
|
186
106
|
const isDisabled = isAttrTrue(newVal);
|
|
187
|
-
|
|
107
|
+
this.#$input.disabled = isDisabled;
|
|
188
108
|
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
189
109
|
break;
|
|
190
110
|
}
|
|
@@ -192,11 +112,38 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
|
|
|
192
112
|
}
|
|
193
113
|
|
|
194
114
|
focus() {
|
|
195
|
-
|
|
115
|
+
this.#$input.focus();
|
|
196
116
|
}
|
|
197
117
|
|
|
198
118
|
blur() {
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
119
|
+
this.#$input.blur();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#onInput = e => {
|
|
123
|
+
e.stopPropagation();
|
|
124
|
+
const isChecked = this.#$input.checked;
|
|
125
|
+
this.#$input.checked = this.checked;
|
|
126
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
127
|
+
detail: isChecked,
|
|
128
|
+
bubbles: true
|
|
129
|
+
}));
|
|
130
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
131
|
+
detail: isChecked
|
|
132
|
+
}));
|
|
133
|
+
};
|
|
134
|
+
#onCheckboxFocus = () => {
|
|
135
|
+
this.dispatchEvent(new CustomEvent('-focus'));
|
|
136
|
+
};
|
|
137
|
+
#onCheckboxBlur = () => {
|
|
138
|
+
this.dispatchEvent(new CustomEvent('-blur'));
|
|
139
|
+
};
|
|
140
|
+
#onChangeReactHandler = e => {
|
|
141
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
142
|
+
};
|
|
143
|
+
#onFocusReactHandler = e => {
|
|
144
|
+
getReactEventHandler(this, 'on-focus')?.(e);
|
|
145
|
+
};
|
|
146
|
+
#onBlurReactHandler = e => {
|
|
147
|
+
getReactEventHandler(this, 'on-blur')?.(e);
|
|
148
|
+
};
|
|
149
|
+
});
|
package/toggle/types.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare type TSinchToggleReact = TSinchElementReact<TSinchToggleElement>
|
|
|
21
21
|
disabled?: boolean;
|
|
22
22
|
text?: string;
|
|
23
23
|
'aria-label': string;
|
|
24
|
+
/** @deprecated */
|
|
24
25
|
onChange?: (e: SyntheticEvent<TSinchToggleElement, CustomEvent<boolean>>) => void;
|
|
25
26
|
'on-change'?: (e: CustomEvent<boolean>) => void;
|
|
26
27
|
};
|
package/types.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const NO_COLOR: "";
|
|
2
|
+
export declare type TSinchColorName = typeof NO_COLOR | 'Blue 10' | 'Blue 20' | 'Blue 30' | 'Blue 40' | 'Blue 50' | 'Green 10' | 'Green 20' | 'Green 30' | 'Yellow 20' | 'Yellow 10' | 'Orange 10' | 'Orange 30' | 'Orange 20' | 'Coral 10' | 'Pink 10' | 'Pink 20' | 'Brown 10' | 'Brown 20' | 'Gray 10' | 'Gray 20' | 'Red 10' | 'Skin tone 0' | 'Skin tone 10' | 'Skin tone 20' | 'Skin tone 30' | 'Skin tone 40' | 'Skin tone 50';
|
|
3
|
+
export declare const colorNameValues: readonly TSinchColorName[];
|
|
4
|
+
declare type TAssertColorName = (value: string | null) => asserts value is TSinchColorName;
|
|
5
|
+
export declare const assertColorNameValue: TAssertColorName;
|
|
6
|
+
export declare const colorMap: Record<TSinchColorName, {
|
|
7
|
+
value: string;
|
|
8
|
+
isInverted: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
export {};
|
package/utils/colors.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export const NO_COLOR = '';
|
|
2
|
+
export const colorNameValues = [NO_COLOR, 'Blue 10', 'Blue 20', 'Blue 30', 'Blue 40', 'Blue 50', 'Green 10', 'Green 20', 'Green 30', 'Yellow 10', 'Yellow 20', 'Orange 10', 'Orange 20', 'Orange 30', 'Pink 10', 'Pink 20', 'Brown 10', 'Brown 20', 'Gray 10', 'Gray 20', 'Coral 10', 'Red 10', 'Skin tone 0', 'Skin tone 10', 'Skin tone 20', 'Skin tone 30', 'Skin tone 40', 'Skin tone 50'];
|
|
3
|
+
export const assertColorNameValue = value => {
|
|
4
|
+
if (value === null || !colorNameValues.includes(value)) {
|
|
5
|
+
throw new Error(`Invalid color name: "${value}"`);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
export const colorMap = {
|
|
9
|
+
[NO_COLOR]: {
|
|
10
|
+
value: NO_COLOR,
|
|
11
|
+
isInverted: false
|
|
12
|
+
},
|
|
13
|
+
'Blue 50': {
|
|
14
|
+
value: 'night-400',
|
|
15
|
+
isInverted: true
|
|
16
|
+
},
|
|
17
|
+
'Blue 40': {
|
|
18
|
+
value: 'aqua-400',
|
|
19
|
+
isInverted: false
|
|
20
|
+
},
|
|
21
|
+
'Blue 30': {
|
|
22
|
+
value: 'aqua-200',
|
|
23
|
+
isInverted: false
|
|
24
|
+
},
|
|
25
|
+
'Blue 20': {
|
|
26
|
+
value: 'night-200',
|
|
27
|
+
isInverted: false
|
|
28
|
+
},
|
|
29
|
+
'Blue 10': {
|
|
30
|
+
value: 'informative-200',
|
|
31
|
+
isInverted: false
|
|
32
|
+
},
|
|
33
|
+
'Green 30': {
|
|
34
|
+
value: 'grass-400',
|
|
35
|
+
isInverted: false
|
|
36
|
+
},
|
|
37
|
+
'Green 20': {
|
|
38
|
+
value: 'grass-200',
|
|
39
|
+
isInverted: false
|
|
40
|
+
},
|
|
41
|
+
'Green 10': {
|
|
42
|
+
value: 'success-200',
|
|
43
|
+
isInverted: false
|
|
44
|
+
},
|
|
45
|
+
'Yellow 20': {
|
|
46
|
+
value: 'bolt-400',
|
|
47
|
+
isInverted: false
|
|
48
|
+
},
|
|
49
|
+
'Yellow 10': {
|
|
50
|
+
value: 'bolt-200',
|
|
51
|
+
isInverted: false
|
|
52
|
+
},
|
|
53
|
+
'Orange 30': {
|
|
54
|
+
value: 'orange-400',
|
|
55
|
+
isInverted: false
|
|
56
|
+
},
|
|
57
|
+
'Orange 20': {
|
|
58
|
+
value: 'orange-200',
|
|
59
|
+
isInverted: false
|
|
60
|
+
},
|
|
61
|
+
'Orange 10': {
|
|
62
|
+
value: 'warning-200',
|
|
63
|
+
isInverted: false
|
|
64
|
+
},
|
|
65
|
+
'Pink 20': {
|
|
66
|
+
value: 'candy-400',
|
|
67
|
+
isInverted: false
|
|
68
|
+
},
|
|
69
|
+
'Pink 10': {
|
|
70
|
+
value: 'candy-200',
|
|
71
|
+
isInverted: false
|
|
72
|
+
},
|
|
73
|
+
'Brown 20': {
|
|
74
|
+
value: 'mud-400',
|
|
75
|
+
isInverted: true
|
|
76
|
+
},
|
|
77
|
+
'Brown 10': {
|
|
78
|
+
value: 'mud-200',
|
|
79
|
+
isInverted: false
|
|
80
|
+
},
|
|
81
|
+
'Gray 20': {
|
|
82
|
+
value: 'dirt-400',
|
|
83
|
+
isInverted: false
|
|
84
|
+
},
|
|
85
|
+
'Gray 10': {
|
|
86
|
+
value: 'dirt-200',
|
|
87
|
+
isInverted: false
|
|
88
|
+
},
|
|
89
|
+
'Coral 10': {
|
|
90
|
+
value: 'berry-200',
|
|
91
|
+
isInverted: false
|
|
92
|
+
},
|
|
93
|
+
'Red 10': {
|
|
94
|
+
value: 'error-200',
|
|
95
|
+
isInverted: false
|
|
96
|
+
},
|
|
97
|
+
'Skin tone 0': {
|
|
98
|
+
value: 'skin-tone-10',
|
|
99
|
+
isInverted: false
|
|
100
|
+
},
|
|
101
|
+
'Skin tone 10': {
|
|
102
|
+
value: 'skin-tone-20',
|
|
103
|
+
isInverted: false
|
|
104
|
+
},
|
|
105
|
+
'Skin tone 20': {
|
|
106
|
+
value: 'skin-tone-30',
|
|
107
|
+
isInverted: false
|
|
108
|
+
},
|
|
109
|
+
'Skin tone 30': {
|
|
110
|
+
value: 'skin-tone-40',
|
|
111
|
+
isInverted: false
|
|
112
|
+
},
|
|
113
|
+
'Skin tone 40': {
|
|
114
|
+
value: 'skin-tone-50',
|
|
115
|
+
isInverted: false
|
|
116
|
+
},
|
|
117
|
+
'Skin tone 50': {
|
|
118
|
+
value: 'skin-tone-60',
|
|
119
|
+
isInverted: true
|
|
120
|
+
}
|
|
121
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TRect } from '
|
|
1
|
+
import type { TRect } from '../types';
|
|
2
2
|
export declare const defineCustomElement: (name: string, constructor: CustomElementConstructor) => void;
|
|
3
3
|
export declare const setNectaryRegistry: (registry: CustomElementRegistry) => void;
|
|
4
4
|
declare global {
|
|
@@ -16,8 +16,7 @@ export declare const isAttrTrue: (attrValue: string | null) => boolean;
|
|
|
16
16
|
export declare const getBooleanAttribute: ($element: Element, attrName: string) => boolean;
|
|
17
17
|
export declare const updateBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
|
|
18
18
|
export declare const updateAttribute: ($element: Element, attrName: string, attrValue: string | number | boolean | null | undefined) => void;
|
|
19
|
-
export declare function getAttribute($element: Element, attrName: string): string |
|
|
20
|
-
export declare function getAttribute($element: Element, attrName: string, defaultValue: null): string | null;
|
|
19
|
+
export declare function getAttribute($element: Element, attrName: string): string | null;
|
|
21
20
|
export declare function getAttribute($element: Element, attrName: string, defaultValue: string): string;
|
|
22
21
|
export declare const isLiteralValue: <T extends readonly string[]>(literals: T, value: string | null | undefined) => value is T[number];
|
|
23
22
|
export declare const updateLiteralAttribute: <T extends readonly string[]>($element: Element, literals: T, attrName: string, attrValue: string | null | undefined) => void;
|
|
@@ -25,15 +24,16 @@ export declare function getLiteralAttribute<T extends readonly string[]>($elemen
|
|
|
25
24
|
export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: null): T[number] | null;
|
|
26
25
|
export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: T[number]): T[number];
|
|
27
26
|
export declare const clampNumber: (value: number, min: number, max: number) => number;
|
|
28
|
-
declare type
|
|
27
|
+
declare type IntegerOptions = {
|
|
29
28
|
min?: number;
|
|
30
29
|
max?: number;
|
|
30
|
+
defaultValue?: number | null;
|
|
31
|
+
itemSizeMultiplier?: number;
|
|
32
|
+
itemSpaceBetween?: number;
|
|
31
33
|
};
|
|
32
|
-
export declare const attrValueToInteger: (value: string | null,
|
|
33
|
-
export declare const attrValueToPixels: (value: string | null, options?:
|
|
34
|
-
|
|
35
|
-
}) => string;
|
|
36
|
-
export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, range?: TRange) => void;
|
|
34
|
+
export declare const attrValueToInteger: (value: string | null, options?: IntegerOptions) => number | null;
|
|
35
|
+
export declare const attrValueToPixels: (value: string | null, options?: IntegerOptions) => string;
|
|
36
|
+
export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, options?: IntegerOptions) => void;
|
|
37
37
|
export declare function getIntegerAttribute($element: Element, attrName: string): number | undefined;
|
|
38
38
|
export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: null): number | null;
|
|
39
39
|
export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: number): number;
|
|
@@ -48,4 +48,13 @@ export declare const throttleAnimationFrame: (cb: (...args: any[]) => void) => {
|
|
|
48
48
|
cancel: () => void;
|
|
49
49
|
};
|
|
50
50
|
export declare const getFirstSlotElement: (root: HTMLSlotElement) => HTMLElement | null;
|
|
51
|
+
export declare const cloneNode: (el: Element, deep: boolean) => Element;
|
|
52
|
+
export declare const isElementFocused: ($el: Element | null) => boolean;
|
|
53
|
+
export declare class Context {
|
|
54
|
+
#private;
|
|
55
|
+
constructor($element: Element, name: string);
|
|
56
|
+
get elements(): Iterable<Element>;
|
|
57
|
+
subscribe(): void;
|
|
58
|
+
unsubscribe(): void;
|
|
59
|
+
}
|
|
51
60
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import pkg from './package.json';
|
|
1
|
+
import pkg from '../package.json';
|
|
3
2
|
const nectaryDefinitions = new Map();
|
|
4
3
|
let nectaryRegistry = null;
|
|
5
4
|
export const defineCustomElement = (name, constructor) => {
|
|
@@ -29,12 +28,6 @@ export const setNectaryRegistry = registry => {
|
|
|
29
28
|
nectaryDefinitions.clear();
|
|
30
29
|
};
|
|
31
30
|
export class NectaryElement extends HTMLElement {
|
|
32
|
-
constructor() {
|
|
33
|
-
super(...arguments);
|
|
34
|
-
|
|
35
|
-
_defineProperty(this, '__version', pkg.version);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
31
|
attachShadow(options) {
|
|
39
32
|
return super.attachShadow({
|
|
40
33
|
mode: 'closed',
|
|
@@ -44,6 +37,7 @@ export class NectaryElement extends HTMLElement {
|
|
|
44
37
|
});
|
|
45
38
|
}
|
|
46
39
|
|
|
40
|
+
__version = pkg.version;
|
|
47
41
|
}
|
|
48
42
|
export const getReactEventHandler = ($element, handlerName) => {
|
|
49
43
|
for (const key in $element) {
|
|
@@ -81,7 +75,8 @@ export const updateAttribute = ($element, attrName, attrValue) => {
|
|
|
81
75
|
$element.removeAttribute(attrName);
|
|
82
76
|
}
|
|
83
77
|
};
|
|
84
|
-
export function getAttribute($element, attrName
|
|
78
|
+
export function getAttribute($element, attrName) {
|
|
79
|
+
let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
85
80
|
return $element.getAttribute(attrName) ?? defaultValue;
|
|
86
81
|
}
|
|
87
82
|
export const isLiteralValue = (literals, value) => {
|
|
@@ -110,59 +105,79 @@ export function getLiteralAttribute($element, literals, attrName, defaultValue)
|
|
|
110
105
|
export const clampNumber = (value, min, max) => {
|
|
111
106
|
return Math.min(max, Math.max(min, value));
|
|
112
107
|
};
|
|
108
|
+
const DEFAULT_INTEGER_OPTIONS = {
|
|
109
|
+
itemSizeMultiplier: 1,
|
|
110
|
+
itemSpaceBetween: 0,
|
|
111
|
+
defaultValue: null
|
|
112
|
+
};
|
|
113
113
|
|
|
114
|
-
const applyRange = (value,
|
|
114
|
+
const applyRange = (value, _ref) => {
|
|
115
|
+
let {
|
|
116
|
+
min,
|
|
117
|
+
max
|
|
118
|
+
} = _ref;
|
|
115
119
|
let result = value;
|
|
116
120
|
|
|
117
|
-
if (
|
|
118
|
-
result = Math.max(
|
|
121
|
+
if (min != null) {
|
|
122
|
+
result = Math.max(min, result);
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
if (
|
|
122
|
-
result = Math.min(
|
|
125
|
+
if (max != null) {
|
|
126
|
+
result = Math.min(max, result);
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
return result;
|
|
126
130
|
};
|
|
127
131
|
|
|
128
132
|
export const attrValueToInteger = function (value) {
|
|
129
|
-
let
|
|
133
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
|
|
134
|
+
const {
|
|
135
|
+
defaultValue = null,
|
|
136
|
+
itemSizeMultiplier = 1,
|
|
137
|
+
itemSpaceBetween = 0
|
|
138
|
+
} = options;
|
|
139
|
+
let intValue = defaultValue;
|
|
130
140
|
|
|
131
|
-
if (value
|
|
132
|
-
|
|
133
|
-
}
|
|
141
|
+
if (value !== null) {
|
|
142
|
+
const int = parseInt(value);
|
|
134
143
|
|
|
135
|
-
|
|
144
|
+
if (Number.isInteger(int)) {
|
|
145
|
+
intValue = applyRange(int, options);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
136
148
|
|
|
137
|
-
if (
|
|
138
|
-
return
|
|
149
|
+
if (intValue !== null) {
|
|
150
|
+
return intValue * itemSizeMultiplier + Math.max(intValue - 1, 0) * itemSpaceBetween;
|
|
139
151
|
}
|
|
140
152
|
|
|
141
|
-
return
|
|
153
|
+
return null;
|
|
142
154
|
};
|
|
143
155
|
export const attrValueToPixels = function (value) {
|
|
144
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
|
145
|
-
const int = attrValueToInteger(value,
|
|
146
|
-
|
|
147
|
-
max: options.max
|
|
148
|
-
});
|
|
149
|
-
return int === null ? 'unset' : `${int * (options.multiplier ?? 1)}px`;
|
|
156
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
|
|
157
|
+
const int = attrValueToInteger(value, options);
|
|
158
|
+
return int === null ? 'unset' : `${int}px`;
|
|
150
159
|
};
|
|
151
160
|
export const updateIntegerAttribute = function ($element, attrName, attrValue) {
|
|
152
|
-
let
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
161
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_INTEGER_OPTIONS;
|
|
162
|
+
const {
|
|
163
|
+
defaultValue = null,
|
|
164
|
+
itemSizeMultiplier: multiplier = 1
|
|
165
|
+
} = options;
|
|
166
|
+
let intValue = null;
|
|
167
|
+
|
|
168
|
+
if (typeof attrValue === 'string') {
|
|
169
|
+
intValue = attrValueToInteger(attrValue, options);
|
|
170
|
+
} else if (typeof attrValue === 'number') {
|
|
171
|
+
intValue = applyRange(attrValue, options) * multiplier;
|
|
172
|
+
} else {
|
|
173
|
+
intValue = defaultValue;
|
|
157
174
|
}
|
|
158
175
|
|
|
159
|
-
const intValue = typeof attrValue === 'string' ? attrValueToInteger(attrValue, range) : applyRange(attrValue, range);
|
|
160
|
-
|
|
161
176
|
if (intValue === null) {
|
|
162
|
-
|
|
177
|
+
$element.removeAttribute(attrName);
|
|
178
|
+
} else {
|
|
179
|
+
$element.setAttribute(attrName, intValue.toFixed(0));
|
|
163
180
|
}
|
|
164
|
-
|
|
165
|
-
$element.setAttribute(attrName, intValue.toFixed(0));
|
|
166
181
|
};
|
|
167
182
|
export function getIntegerAttribute($element, attrName, defaultValue) {
|
|
168
183
|
return attrValueToInteger($element.getAttribute(attrName)) ?? defaultValue;
|
|
@@ -261,4 +276,68 @@ export const getFirstSlotElement = root => {
|
|
|
261
276
|
|
|
262
277
|
slot = el;
|
|
263
278
|
}
|
|
264
|
-
};
|
|
279
|
+
};
|
|
280
|
+
export const cloneNode = (el, deep) => {
|
|
281
|
+
const root = el.getRootNode();
|
|
282
|
+
|
|
283
|
+
if (root !== document && Reflect.has(root, 'createElement')) {
|
|
284
|
+
const cloned = root.createElement(el.tagName.toLowerCase());
|
|
285
|
+
|
|
286
|
+
for (const attr of el.getAttributeNames()) {
|
|
287
|
+
cloned.setAttribute(attr, el.getAttribute(attr));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (deep) {
|
|
291
|
+
for (let i = 0; i < el.children.length; i++) {
|
|
292
|
+
const clonedChild = cloneNode(el.children[i], deep);
|
|
293
|
+
cloned.appendChild(clonedChild);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return cloned;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return el.cloneNode(deep);
|
|
301
|
+
};
|
|
302
|
+
export const isElementFocused = $el => {
|
|
303
|
+
return $el !== null && $el === $el.getRootNode().activeElement;
|
|
304
|
+
};
|
|
305
|
+
export class Context {
|
|
306
|
+
#$root;
|
|
307
|
+
#listeners = new Set();
|
|
308
|
+
#name;
|
|
309
|
+
#isSubscribed = false;
|
|
310
|
+
|
|
311
|
+
constructor($element, name) {
|
|
312
|
+
this.#$root = $element;
|
|
313
|
+
this.#name = name;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
get elements() {
|
|
317
|
+
return this.#listeners;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
subscribe() {
|
|
321
|
+
if (this.#isSubscribed) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.#$root.addEventListener(`-context-connect-${this.#name}`, this.#onConnect);
|
|
326
|
+
this.#$root.addEventListener(`-context-disconnect-${this.#name}`, this.#onDisconnect);
|
|
327
|
+
this.#isSubscribed = true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
unsubscribe() {
|
|
331
|
+
this.#listeners.clear();
|
|
332
|
+
this.#$root.removeEventListener(`-context-connect-${this.#name}`, this.#onConnect);
|
|
333
|
+
this.#$root.removeEventListener(`-context-disconnect-${this.#name}`, this.#onDisconnect);
|
|
334
|
+
this.#isSubscribed = false;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
#onConnect = e => {
|
|
338
|
+
this.#listeners.add(e.target);
|
|
339
|
+
};
|
|
340
|
+
#onDisconnect = e => {
|
|
341
|
+
this.#listeners.delete(e.target);
|
|
342
|
+
};
|
|
343
|
+
}
|