@nectary/components 0.8.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.d.ts +21 -0
- package/accordion/index.js +118 -0
- package/accordion-item/index.d.ts +33 -0
- package/accordion-item/index.js +139 -0
- package/alert/index.d.ts +26 -0
- package/alert/index.js +91 -0
- package/alert-button/index.d.ts +23 -0
- package/alert-button/index.js +62 -0
- package/alert-close/index.d.ts +22 -0
- package/alert-close/index.js +41 -0
- package/button/index.d.ts +32 -0
- package/button/index.js +100 -0
- package/checkbox/index.d.ts +29 -0
- package/checkbox/index.js +134 -0
- package/help-tooltip/index.d.ts +15 -0
- package/help-tooltip/index.js +80 -0
- package/icon/cancel/index.d.ts +11 -0
- package/icon/cancel/index.js +4 -0
- package/icon/close/index.d.ts +11 -0
- package/icon/close/index.js +4 -0
- package/icon/create-icon-class.d.ts +308 -0
- package/icon/create-icon-class.js +53 -0
- package/icon/east/index.d.ts +11 -0
- package/icon/east/index.js +4 -0
- package/icon/help-outline/index.d.ts +11 -0
- package/icon/help-outline/index.js +4 -0
- package/icon/more-horiz/index.d.ts +11 -0
- package/icon/more-horiz/index.js +4 -0
- package/icon/more-vert/index.d.ts +11 -0
- package/icon/more-vert/index.js +4 -0
- package/icon/north/index.d.ts +11 -0
- package/icon/north/index.js +4 -0
- package/icon/north-east/index.d.ts +11 -0
- package/icon/north-east/index.js +4 -0
- package/icon/north-west/index.d.ts +11 -0
- package/icon/north-west/index.js +4 -0
- package/icon/open-in-new/index.d.ts +11 -0
- package/icon/open-in-new/index.js +4 -0
- package/icon/south/index.d.ts +11 -0
- package/icon/south/index.js +4 -0
- package/icon/south-east/index.d.ts +11 -0
- package/icon/south-east/index.js +4 -0
- package/icon/south-west/index.d.ts +11 -0
- package/icon/south-west/index.js +4 -0
- package/icon/types.d.ts +7 -0
- package/icon/types.js +1 -0
- package/icon/west/index.d.ts +11 -0
- package/icon/west/index.js +4 -0
- package/icon-branded/barchart-down/index.d.ts +11 -0
- package/icon-branded/barchart-down/index.js +4 -0
- package/icon-branded/barchart-up/index.d.ts +11 -0
- package/icon-branded/barchart-up/index.js +4 -0
- package/icon-branded/campaigns/index.d.ts +11 -0
- package/icon-branded/campaigns/index.js +4 -0
- package/icon-branded/chatbot/index.d.ts +11 -0
- package/icon-branded/chatbot/index.js +4 -0
- package/icon-branded/contact/index.d.ts +11 -0
- package/icon-branded/contact/index.js +4 -0
- package/icon-branded/create-icon-class.d.ts +309 -0
- package/icon-branded/create-icon-class.js +61 -0
- package/icon-branded/home/index.d.ts +11 -0
- package/icon-branded/home/index.js +4 -0
- package/icon-branded/multiple-channels/index.d.ts +11 -0
- package/icon-branded/multiple-channels/index.js +4 -0
- package/icon-branded/rocket/index.d.ts +11 -0
- package/icon-branded/rocket/index.js +4 -0
- package/icon-branded/settings/index.d.ts +11 -0
- package/icon-branded/settings/index.js +4 -0
- package/icon-branded/types.d.ts +9 -0
- package/icon-branded/types.js +1 -0
- package/icon-branded/user/index.d.ts +11 -0
- package/icon-branded/user/index.js +4 -0
- package/icon-branded/users/index.d.ts +11 -0
- package/icon-branded/users/index.js +4 -0
- package/index.d.ts +56 -0
- package/index.js +56 -0
- package/input/index.d.ts +35 -0
- package/input/index.js +203 -0
- package/link/index.d.ts +30 -0
- package/link/index.js +118 -0
- package/logo/create-logo-class.d.ts +309 -0
- package/logo/create-logo-class.js +63 -0
- package/logo/sinch-icon/index.d.ts +11 -0
- package/logo/sinch-icon/index.js +4 -0
- package/logo/sinch-icon-wordmark/index.d.ts +11 -0
- package/logo/sinch-icon-wordmark/index.js +4 -0
- package/logo/types.d.ts +9 -0
- package/logo/types.js +1 -0
- package/package.json +34 -0
- package/radio/index.d.ts +19 -0
- package/radio/index.js +185 -0
- package/radio-option/index.d.ts +28 -0
- package/radio-option/index.js +134 -0
- package/readme.md +172 -0
- package/select/index.d.ts +37 -0
- package/select/index.js +492 -0
- package/select-option/index.d.ts +27 -0
- package/select-option/index.js +107 -0
- package/spinner/index.d.ts +21 -0
- package/spinner/index.js +23 -0
- package/table/index.d.ts +13 -0
- package/table/index.js +18 -0
- package/table-body/index.d.ts +13 -0
- package/table-body/index.js +18 -0
- package/table-cell/index.d.ts +20 -0
- package/table-cell/index.js +27 -0
- package/table-head/index.d.ts +13 -0
- package/table-head/index.js +18 -0
- package/table-head-cell/index.d.ts +24 -0
- package/table-head-cell/index.js +74 -0
- package/table-head-sort/index.d.ts +25 -0
- package/table-head-sort/index.js +92 -0
- package/table-row/index.d.ts +17 -0
- package/table-row/index.js +26 -0
- package/tabs/index.d.ts +19 -0
- package/tabs/index.js +181 -0
- package/tabs-option/index.d.ts +28 -0
- package/tabs-option/index.js +129 -0
- package/tag/index.d.ts +27 -0
- package/tag/index.js +79 -0
- package/tag-close/index.d.ts +24 -0
- package/tag-close/index.js +70 -0
- package/textarea/index.d.ts +35 -0
- package/textarea/index.js +201 -0
- package/theme.css +112 -0
- package/toggle/index.d.ts +31 -0
- package/toggle/index.js +144 -0
- package/tooltip/index.d.ts +26 -0
- package/tooltip/index.js +68 -0
- package/types.d.ts +3 -0
- package/utils.d.ts +31 -0
- package/utils.js +146 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
import type { FocusEvent } from 'react';
|
|
3
|
+
export declare const isRadioOptionElement: (element: EventTarget | Element | null) => element is TSinchRadioOptionElement;
|
|
4
|
+
export declare type TSinchRadioOptionElement = HTMLElement & {
|
|
5
|
+
value: string;
|
|
6
|
+
checked: boolean;
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
text: string;
|
|
9
|
+
focus(): void;
|
|
10
|
+
blur(): void;
|
|
11
|
+
};
|
|
12
|
+
export declare type TSinchRadioOptionReact = TSinchElementReact<TSinchRadioOptionElement> & {
|
|
13
|
+
value: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
text: string;
|
|
16
|
+
onFocus?: (e: FocusEvent<TSinchRadioOptionElement>) => void;
|
|
17
|
+
onBlur?: (e: FocusEvent<TSinchRadioOptionElement>) => void;
|
|
18
|
+
};
|
|
19
|
+
declare global {
|
|
20
|
+
namespace JSX {
|
|
21
|
+
interface IntrinsicElements {
|
|
22
|
+
'sinch-radio-option': TSinchRadioOptionReact;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
interface HTMLElementTagNameMap {
|
|
26
|
+
'sinch-radio-option': TSinchRadioOptionElement;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
+
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
+
|
|
4
|
+
var _$input, _$label, _onInput;
|
|
5
|
+
|
|
6
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
7
|
+
|
|
8
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
9
|
+
|
|
10
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
11
|
+
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-800);--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;font:var(--sinch-font-body);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);box-shadow:0 0 0 2px var(--sinch-color-radio-border) inset;transition:background-color .1s linear}#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;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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-checked) inset}#input:checked~#icon-knob{opacity:100%;background-color:var(--sinch-color-radio-border-checked)}#input:focus::before{background-color:var(--sinch-color-radio-outer-circle-focus)}#input:focus::after{box-shadow:0 0 0 2px var(--sinch-color-radio-border-focus) inset}#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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-hover) inset}#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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-active) inset}#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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-disabled) inset}#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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-focus-checked) inset}#input:focus:checked~#icon-knob{opacity:100%;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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-hover-checked) inset}#input:hover:checked~#icon-knob{opacity:100%;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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-active-checked) inset}#input:active:checked~#icon-knob{opacity:100%;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{box-shadow:0 0 0 2px var(--sinch-color-radio-border-disabled-checked) inset}#input:disabled:checked~#icon-knob{opacity:100%;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>';
|
|
12
|
+
export const isRadioOptionElement = element => {
|
|
13
|
+
return element instanceof Element && element.tagName === 'SINCH-RADIO-OPTION';
|
|
14
|
+
};
|
|
15
|
+
const template = document.createElement('template');
|
|
16
|
+
template.innerHTML = templateHTML;
|
|
17
|
+
defineCustomElement('sinch-radio-option', (_$input = new WeakMap(), _$label = new WeakMap(), _onInput = new WeakMap(), class extends HTMLElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
|
|
21
|
+
_classPrivateFieldInitSpec(this, _$input, {
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
_classPrivateFieldInitSpec(this, _$label, {
|
|
27
|
+
writable: true,
|
|
28
|
+
value: void 0
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
_classPrivateFieldInitSpec(this, _onInput, {
|
|
32
|
+
writable: true,
|
|
33
|
+
value: e => {
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
_classPrivateFieldGet(this, _$input).checked = false;
|
|
36
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
37
|
+
bubbles: true,
|
|
38
|
+
detail: this.value
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const shadowRoot = this.attachShadow({
|
|
44
|
+
mode: 'production' === 'development' ? 'open' : 'closed',
|
|
45
|
+
delegatesFocus: true
|
|
46
|
+
});
|
|
47
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
48
|
+
|
|
49
|
+
_classPrivateFieldSet(this, _$input, shadowRoot.querySelector('input'));
|
|
50
|
+
|
|
51
|
+
_classPrivateFieldSet(this, _$label, shadowRoot.querySelector('label'));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
connectedCallback() {
|
|
55
|
+
_classPrivateFieldGet(this, _$input).addEventListener('input', _classPrivateFieldGet(this, _onInput));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
disconnectedCallback() {
|
|
59
|
+
_classPrivateFieldGet(this, _$input).removeEventListener('input', _classPrivateFieldGet(this, _onInput));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static get observedAttributes() {
|
|
63
|
+
return ['checked', 'disabled', 'text', 'value'];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
set checked(isChecked) {
|
|
67
|
+
updateBooleanAttribute(this, 'checked', isChecked);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get checked() {
|
|
71
|
+
return getBooleanAttribute(this, 'checked');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
set value(value) {
|
|
75
|
+
updateAttribute(this, 'value', value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get value() {
|
|
79
|
+
return getAttribute(this, 'value', '');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
set disabled(isDisabled) {
|
|
83
|
+
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get disabled() {
|
|
87
|
+
return getBooleanAttribute(this, 'disabled');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
set text(value) {
|
|
91
|
+
updateAttribute(this, 'text', value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get text() {
|
|
95
|
+
return getAttribute(this, 'text', '');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
attributeChangedCallback(name, _, newVal) {
|
|
99
|
+
switch (name) {
|
|
100
|
+
case 'text':
|
|
101
|
+
{
|
|
102
|
+
_classPrivateFieldGet(this, _$label).textContent = newVal;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
case 'checked':
|
|
107
|
+
{
|
|
108
|
+
_classPrivateFieldGet(this, _$input).checked = isAttrTrue(newVal);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
case 'disabled':
|
|
113
|
+
{
|
|
114
|
+
_classPrivateFieldGet(this, _$input).disabled = isAttrTrue(newVal);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
case 'value':
|
|
119
|
+
{
|
|
120
|
+
_classPrivateFieldGet(this, _$input).value = newVal ?? '';
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
focus() {
|
|
127
|
+
_classPrivateFieldGet(this, _$input).focus();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
blur() {
|
|
131
|
+
_classPrivateFieldGet(this, _$input).blur();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}));
|
package/readme.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# 🐝 Nectary
|
|
2
|
+
|
|
3
|
+
Design System's framework-agnostic Component Library implementation.
|
|
4
|
+
|
|
5
|
+
>Nectaries are specialized nectar-producing structures of the flower.
|
|
6
|
+
|
|
7
|
+
>Bumblebees eat nectar and pollen made by flowers. The sugary nectar provides the bees with energy while the pollen provides them with protein.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Add the following line to `.npmrc` in the project root:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
//registry.npmjs.org/:_authToken=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
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Add the component library dependency to `package.json`:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm install @sinch-engage/nectary
|
|
21
|
+
# or
|
|
22
|
+
yarn add @sinch-engage/nectary
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
⚠️ VPN is required.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Theme
|
|
30
|
+
|
|
31
|
+
Import CSS file with [custom properties](./theme.css) (variables):
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import '@sinch-engage/nectary/theme.css'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Use color palette or custom font face:
|
|
38
|
+
|
|
39
|
+
```css
|
|
40
|
+
span {
|
|
41
|
+
color: var(--sinch-color-honey-700);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
h2 {
|
|
45
|
+
font: var(--sinch-font-title-2);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Components
|
|
50
|
+
|
|
51
|
+
Import component:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import '@sinch-engage/nectary/button'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Use it in React/Vue/Angular/etc, for example:
|
|
58
|
+
|
|
59
|
+
```jsx
|
|
60
|
+
<sinch-button value="Click me" onClick={() => console.log('click')}></sinch-button>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
⚠️ Note that it's not allowed to self-close custom element tags.
|
|
64
|
+
|
|
65
|
+
## Testing
|
|
66
|
+
|
|
67
|
+
If you are testing your application using Nectary components with Jest, you might run into some problems, as it does not work out of the box. Here are the common pitfalls and their solutions.
|
|
68
|
+
|
|
69
|
+
### Example configuration
|
|
70
|
+
|
|
71
|
+
jest.config.js
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
/** @type {import("ts-jest/dist/types").InitialOptionsTsJest} */
|
|
75
|
+
module.exports = {
|
|
76
|
+
preset: "ts-jest",
|
|
77
|
+
testEnvironment: "jsdom",
|
|
78
|
+
moduleNameMapper: {
|
|
79
|
+
"\\.(css)$": "identity-obj-proxy"
|
|
80
|
+
},
|
|
81
|
+
transform: {
|
|
82
|
+
"^.+\\.(ts|tsx)?$": "ts-jest",
|
|
83
|
+
"^.+\\.(js|jsx)$": "babel-jest"
|
|
84
|
+
},
|
|
85
|
+
transformIgnorePatterns: [
|
|
86
|
+
"node_modules/(?!@nectary)"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
babel.config.js
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
module.exports = {presets: ['@babel/preset-env']}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### CSS
|
|
98
|
+
|
|
99
|
+
If you already have a babel loader for CSS, you might not need this part. If you do not, you can use [identity-obj-proxy](https://www.npmjs.com/package/identity-obj-proxy) to mock your CSS imports:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
npm install identity-obj-proxy
|
|
103
|
+
# or
|
|
104
|
+
yarn add identity-obj-proxy
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Then add this part to your jest.config.js file:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
moduleNameMapper: {
|
|
111
|
+
"\\.(css)$": "identity-obj-proxy"
|
|
112
|
+
},
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
It lets Jest know how to mock the css imports in your codebase, like for example when you import the theme:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import '@sinch-engage/nectary/theme.css'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
This import should not throw an error now.
|
|
122
|
+
|
|
123
|
+
### JS and TS
|
|
124
|
+
|
|
125
|
+
You are going to need to install [babel-jest](https://www.npmjs.com/package/babel-jest) if it is not already done:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
npm install babel-jest
|
|
129
|
+
# or
|
|
130
|
+
yarn add babel-jest
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Then add this lines to your jest.config.js file:
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
transform: {
|
|
137
|
+
"^.+\\.(ts|tsx)?$": "ts-jest", // if you are using Typescript and ts-jest
|
|
138
|
+
"^.+\\.(js|jsx)$": "babel-jest"
|
|
139
|
+
},
|
|
140
|
+
transformIgnorePatterns: [
|
|
141
|
+
"node_modules/(?!@nectary)"
|
|
142
|
+
]
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
It is necessary to export the env preset in the babel.js.config file:
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
module.exports = {presets: ['@babel/preset-env']}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
If you import any component:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
import '@sinch-engage/nectary/input'
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
It should not throw the error:
|
|
158
|
+
|
|
159
|
+
```Jest encountered an unexpected token```
|
|
160
|
+
|
|
161
|
+
## TODO
|
|
162
|
+
|
|
163
|
+
- [x] [Storybook](https://saas.pages.sinch.com/engage/engage/) (VPN is required)
|
|
164
|
+
- [x] Follow the WCAG 2.1 guidelines
|
|
165
|
+
- [x] Tests
|
|
166
|
+
- [x] (in progress) Cross-browser Chromium/Firefox/WebKit visual regression tests
|
|
167
|
+
- [x] Cross-framework React/Vue/Angular tests
|
|
168
|
+
- [x] a11y tests using [Axe](https://www.deque.com/axe/) library
|
|
169
|
+
- [ ] CI/CD
|
|
170
|
+
- [x] Auto-publish on Git tag
|
|
171
|
+
- [x] Send message/changelog to Slack
|
|
172
|
+
- [ ] Provide unique Storybook preview link in PRs
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { TSinchElementReact } from '../types';
|
|
2
|
+
import type { FocusEvent, SyntheticEvent } from 'react';
|
|
3
|
+
export declare type TSinchSelectElement = HTMLElement & {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
placeholder: string | null;
|
|
7
|
+
optionalText: string | null;
|
|
8
|
+
invalidText: string | null;
|
|
9
|
+
additionalText: string | null;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
maxVisibleItems: number | null;
|
|
12
|
+
focus(): void;
|
|
13
|
+
blur(): void;
|
|
14
|
+
};
|
|
15
|
+
export declare type TSinchSelectReact = TSinchElementReact<TSinchSelectElement> & {
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
optionalText?: string;
|
|
20
|
+
invalidText?: string;
|
|
21
|
+
additionalText?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
maxVisibleItems?: number;
|
|
24
|
+
onChange: (e: SyntheticEvent<TSinchSelectElement, CustomEvent<string>>) => void;
|
|
25
|
+
onFocus?: (e: FocusEvent<TSinchSelectElement>) => void;
|
|
26
|
+
onBlur?: (e: FocusEvent<TSinchSelectElement>) => void;
|
|
27
|
+
};
|
|
28
|
+
declare global {
|
|
29
|
+
namespace JSX {
|
|
30
|
+
interface IntrinsicElements {
|
|
31
|
+
'sinch-select': TSinchSelectReact;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
interface HTMLElementTagNameMap {
|
|
35
|
+
'sinch-select': TSinchSelectElement;
|
|
36
|
+
}
|
|
37
|
+
}
|