@nectary/components 0.36.1 → 0.38.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.
Files changed (59) hide show
  1. package/alert/index.js +1 -1
  2. package/avatar-badge/index.js +1 -1
  3. package/avatar-status/index.js +1 -1
  4. package/button/types.d.ts +6 -0
  5. package/chat-avatar/index.js +1 -1
  6. package/dialog/index.js +1 -1
  7. package/dropdown-text-option/index.js +1 -1
  8. package/field/index.d.ts +11 -0
  9. package/field/index.js +144 -0
  10. package/field/types.d.ts +35 -0
  11. package/field/types.js +1 -0
  12. package/file-drop/index.d.ts +13 -0
  13. package/file-drop/index.js +320 -0
  14. package/file-drop/types.d.ts +50 -0
  15. package/file-drop/types.js +1 -0
  16. package/file-drop/utils.d.ts +2 -0
  17. package/file-drop/utils.js +37 -0
  18. package/file-picker/index.d.ts +12 -0
  19. package/file-picker/index.js +170 -0
  20. package/file-picker/types.d.ts +32 -0
  21. package/file-picker/types.js +1 -0
  22. package/file-picker/utils.d.ts +1 -0
  23. package/file-picker/utils.js +9 -0
  24. package/file-status/index.d.ts +17 -0
  25. package/file-status/index.js +100 -0
  26. package/file-status/types.d.ts +18 -0
  27. package/file-status/types.js +1 -0
  28. package/file-status/utils.d.ts +5 -0
  29. package/file-status/utils.js +6 -0
  30. package/icons-branded/easytouse/index.d.ts +11 -0
  31. package/icons-branded/easytouse/index.js +4 -0
  32. package/illustrations/create-illustration-class.js +1 -1
  33. package/inline-alert/index.js +1 -1
  34. package/inline-alert/types.d.ts +2 -2
  35. package/input/index.js +10 -82
  36. package/input/types.d.ts +10 -24
  37. package/link/index.d.ts +1 -0
  38. package/link/index.js +19 -12
  39. package/link/types.d.ts +29 -0
  40. package/package.json +2 -2
  41. package/popover/index.js +37 -15
  42. package/progress/index.d.ts +17 -0
  43. package/progress/index.js +87 -0
  44. package/progress/types.d.ts +12 -0
  45. package/progress/types.js +1 -0
  46. package/search/index.js +1 -1
  47. package/select/index.d.ts +1 -0
  48. package/select/index.js +12 -94
  49. package/select/types.d.ts +6 -24
  50. package/spinner/index.js +1 -1
  51. package/text/index.js +9 -1
  52. package/text/types.d.ts +3 -0
  53. package/textarea/index.js +15 -83
  54. package/textarea/types.d.ts +28 -12
  55. package/title/index.js +10 -2
  56. package/title/types.d.ts +3 -0
  57. package/utils.d.ts +2 -0
  58. package/utils.js +26 -1
  59. package/vertical-stepper-item/index.js +1 -1
package/alert/index.js CHANGED
@@ -12,7 +12,7 @@ import '../icons/report';
12
12
  import '../icons/info';
13
13
  import '../text';
14
14
  import { defineCustomElement, getAttribute, getLiteralAttribute, updateAttribute, updateLiteralAttribute, NectaryElement } from '../utils';
15
- const templateHTML = '<style>#wrapper{display:flex;flex-direction:row;gap:8px;align-items:center;padding:0 16px;box-sizing:border-box;width:100%;height:48px}#text{color:var(--sinch-color-stormy-500);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0}#icon-error,#icon-info,#icon-warn{display:none}:host([type=warn]) #wrapper{background-color:var(--sinch-color-warning-200)}:host([type=error]) #wrapper{background-color:var(--sinch-color-error-200)}:host([type=info]) #wrapper{background-color:var(--sinch-color-informative-200)}:host([type=warn]) #icon-warn{display:block;--sinch-color-icon:var(--sinch-color-warning-500)}:host([type=error]) #icon-error{display:block;--sinch-color-icon:var(--sinch-color-error-500)}:host([type=info]) #icon-info{display:block;--sinch-color-icon:var(--sinch-color-informative-500)}</style><div id="wrapper"><sinch-icon-info id="icon-info"></sinch-icon-info><sinch-icon-report-problem id="icon-warn"></sinch-icon-report-problem><sinch-icon-report id="icon-error"></sinch-icon-report><sinch-text id="text" type="m"></sinch-text><slot name="action"></slot><slot name="close"></slot></div>';
15
+ const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:row;gap:8px;align-items:center;padding:8px 16px;box-sizing:border-box;width:100%;min-height:48px}#text{color:var(--sinch-color-stormy-500);flex:1;min-width:0}#icon-error,#icon-info,#icon-warn{display:none}:host([type=warn]) #wrapper{background-color:var(--sinch-color-warning-200)}:host([type=error]) #wrapper{background-color:var(--sinch-color-error-200)}:host([type=info]) #wrapper{background-color:var(--sinch-color-informative-200)}:host([type=warn]) #icon-warn{display:block;--sinch-color-icon:var(--sinch-color-warning-500)}:host([type=error]) #icon-error{display:block;--sinch-color-icon:var(--sinch-color-error-500)}:host([type=info]) #icon-info{display:block;--sinch-color-icon:var(--sinch-color-informative-500)}</style><div id="wrapper"><sinch-icon-info id="icon-info"></sinch-icon-info><sinch-icon-report-problem id="icon-warn"></sinch-icon-report-problem><sinch-icon-report id="icon-error"></sinch-icon-report><sinch-text id="text" type="m"></sinch-text><slot name="action"></slot><slot name="close"></slot></div>';
16
16
  import { assertType, typeValues } from './utils';
17
17
  const template = document.createElement('template');
18
18
  template.innerHTML = templateHTML;
@@ -8,7 +8,7 @@ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedec
8
8
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
9
 
10
10
  import { defineCustomElement, getAttribute, NectaryElement, setClass, updateAttribute } from '../utils';
11
- const templateHTML = '<style>#text{width:var(--sinch-avatar-badge-size);height:var(--sinch-avatar-badge-size);border:1px solid var(--sinch-color-snow-100);border-radius:calc(var(--sinch-avatar-badge-size)/ 2);text-align:center;box-sizing:border-box;color:var(--sinch-color-snow-100);font:var(--sinch-avatar-badge-font);background-color:var(--sinch-color-raspberry-500)}#text.long{width:fit-content;padding:0 calc(var(--sinch-avatar-badge-size)/ 4)}</style><div id="text"></div>';
11
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#text{width:var(--sinch-avatar-badge-size);height:var(--sinch-avatar-badge-size);border:1px solid var(--sinch-color-snow-100);border-radius:calc(var(--sinch-avatar-badge-size)/ 2);text-align:center;box-sizing:border-box;color:var(--sinch-color-snow-100);font:var(--sinch-avatar-badge-font);background-color:var(--sinch-color-raspberry-500)}#text.long{width:fit-content;padding:0 calc(var(--sinch-avatar-badge-size)/ 4)}</style><div id="text"></div>';
12
12
  const template = document.createElement('template');
13
13
  template.innerHTML = templateHTML;
14
14
  defineCustomElement('sinch-avatar-badge', (_$text = new WeakMap(), class extends NectaryElement {
@@ -1,5 +1,5 @@
1
1
  import { defineCustomElement, getLiteralAttribute, NectaryElement, updateLiteralAttribute } from '../utils';
2
- const templateHTML = '<style>#circle{width:10px;height:10px;border:1px solid var(--sinch-color-snow-100);border-radius:50%;box-sizing:border-box}:host([color=grey]) #circle{background-color:var(--sinch-color-snow-600)}:host([color=yellow]) #circle{background-color:var(--sinch-color-honey-500)}:host([color=red]) #circle{background-color:var(--sinch-color-raspberry-500)}:host([color=green]) #circle{background-color:var(--sinch-color-grass-400)}</style><div id="circle"></div>';
2
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#circle{width:10px;height:10px;border:1px solid var(--sinch-color-snow-100);border-radius:50%;box-sizing:border-box}:host([color=grey]) #circle{background-color:var(--sinch-color-snow-600)}:host([color=yellow]) #circle{background-color:var(--sinch-color-honey-500)}:host([color=red]) #circle{background-color:var(--sinch-color-raspberry-500)}:host([color=green]) #circle{background-color:var(--sinch-color-grass-400)}</style><div id="circle"></div>';
3
3
  import { assertColor, colorValues } from './utils';
4
4
  const template = document.createElement('template');
5
5
  template.innerHTML = templateHTML;
package/button/types.d.ts CHANGED
@@ -9,8 +9,11 @@ export declare type TSinchButtonElement = HTMLElement & {
9
9
  disabled: boolean;
10
10
  /** Small */
11
11
  small: boolean;
12
+ /** Click event */
12
13
  addEventListener(type: '-click', listener: (e: CustomEvent<void>) => void): void;
14
+ /** Focus event */
13
15
  addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
16
+ /** Blur event */
14
17
  addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
15
18
  /** Type */
16
19
  setAttribute(attr: 'type', value: TSinchButtonType): void;
@@ -32,7 +35,10 @@ export declare type TSinchButtonReact = TSinchElementReact<TSinchButtonElement>
32
35
  disabled?: boolean;
33
36
  /** Small */
34
37
  small?: boolean;
38
+ /** Click event handler */
35
39
  'on-click'?: (e: CustomEvent<void>) => void;
40
+ /** Focus event handler */
36
41
  'on-focus'?: (e: CustomEvent<void>) => void;
42
+ /** Blur event handler */
37
43
  'on-blur'?: (e: CustomEvent<void>) => void;
38
44
  };
@@ -9,7 +9,7 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
9
9
 
10
10
  import '../avatar';
11
11
  import { defineCustomElement, getAttribute, NectaryElement, updateAttribute } from '../utils';
12
- const templateHTML = '<style>sinch-avatar{display:block}</style><sinch-avatar background="blue" size="l"></sinch-avatar>';
12
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}sinch-avatar{display:block}</style><sinch-avatar background="blue" size="l"></sinch-avatar>';
13
13
  const template = document.createElement('template');
14
14
  template.innerHTML = templateHTML;
15
15
  defineCustomElement('sinch-chat-avatar', (_$avatar = new WeakMap(), class extends NectaryElement {
package/dialog/index.js CHANGED
@@ -16,7 +16,7 @@ import '../icon-button';
16
16
  import '../icons/close';
17
17
  import '../stop-events';
18
18
  import { defineCustomElement, getAttribute, getBooleanAttribute, getRect, isAttrTrue, updateAttribute, getReactEventHandler, NectaryElement, updateBooleanAttribute } from '../utils';
19
- const templateHTML = '<style>dialog{position:fixed;left:0;right:0;margin:auto;display:flex;flex-direction:column;padding:24px;max-width:var(--sinch-dialog-max-width,512px);max-height:unset;border-radius:var(--sinch-shape-radius-l);box-sizing:border-box;contain:content;background-color:var(--sinch-color-snow-100);color:var(--sinch-color-text-default);font:var(--sinch-font-body);border:none;box-shadow:var(--sinch-elevation-level-3)}dialog:not([open]){display:none}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:#000;opacity:.55}dialog::backdrop{background-color:#000;opacity:.55}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}#header{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;margin-bottom:16px}#caption{font:var(--sinch-font-title-m);color:var(--sinch-color-text-default);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#content{min-height:0;overflow:auto;max-height:var(--sinch-dialog-max-height,50vh)}#buttons{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;margin-top:24px}sinch-icon-button{transform:translate(4px,-4px)}</style><dialog><div id="header"><span id="caption"></span><sinch-icon-button id="close" small tabindex="0"><sinch-icon-close slot="icon"></sinch-icon-close></sinch-icon-button></div><div id="content"><sinch-stop-events events="close"><slot name="content"></slot></sinch-stop-events></div><div id="buttons"><sinch-stop-events events="close"><slot name="buttons"></slot></sinch-stop-events></div></dialog>';
19
+ const templateHTML = '<style>:host{display:inline-block}dialog{position:fixed;left:0;right:0;margin:auto;display:flex;flex-direction:column;padding:24px;max-width:var(--sinch-dialog-max-width,512px);max-height:unset;border-radius:var(--sinch-shape-radius-l);box-sizing:border-box;contain:content;background-color:var(--sinch-color-snow-100);color:var(--sinch-color-text-default);font:var(--sinch-font-body);border:none;box-shadow:var(--sinch-elevation-level-3)}dialog:not([open]){display:none}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:#000;opacity:.55}dialog::backdrop{background-color:#000;opacity:.55}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}#header{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;margin-bottom:16px}#caption{font:var(--sinch-font-title-m);color:var(--sinch-color-text-default);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#content{min-height:0;overflow:auto;max-height:var(--sinch-dialog-max-height,50vh)}#buttons{display:flex;flex-direction:row;justify-content:flex-end;gap:16px;margin-top:24px}sinch-icon-button{transform:translate(4px,-4px)}</style><dialog><div id="header"><span id="caption"></span><sinch-icon-button id="close" small tabindex="0"><sinch-icon-close slot="icon"></sinch-icon-close></sinch-icon-button></div><div id="content"><sinch-stop-events events="close"><slot name="content"></slot></sinch-stop-events></div><div id="buttons"><sinch-stop-events events="close"><slot name="buttons"></slot></sinch-stop-events></div></dialog>';
20
20
  const template = document.createElement('template');
21
21
  template.innerHTML = templateHTML;
22
22
  defineCustomElement('sinch-dialog', (_$dialog = new WeakMap(), _$closeButton = new WeakMap(), _$caption = new WeakMap(), _isConnected = new WeakMap(), _prevOverflowValue = new WeakMap(), _onCancel = new WeakMap(), _onCloseClick = new WeakMap(), _onBackdropClick = new WeakMap(), _onCloseReactHandler = new WeakMap(), _dispatchCloseEvent = new WeakSet(), _setOpen = new WeakSet(), class extends NectaryElement {
@@ -7,7 +7,7 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
7
7
 
8
8
  import '../icons/check';
9
9
  import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
10
- const templateHTML = '<style>:host{display:block}#wrapper{display:flex;position:relative;box-sizing:border-box;height:40px;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;--sinch-size-icon:24px}#content{flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host(:hover)>#wrapper,:host([data-selected])>#wrapper{background-color:var(--sinch-color-snow-500)}#check{display:none;margin-right:-6px}:host([data-checked]) #check{display:block}:host([disabled]:not([disabled=false]))>#wrapper{color:var(--sinch-color-stormy-100);cursor:initial;--sinch-color-icon:var(--sinch-color-stormy-100)}::slotted(*){margin-left:-6px}</style><div id="wrapper"><slot name="icon"></slot><span id="content"></span><sinch-icon-check id="check"></sinch-icon-check></div>';
10
+ const templateHTML = '<style>:host{display:block}#wrapper{display:flex;position:relative;box-sizing:border-box;height:40px;padding:8px 16px;align-items:center;gap:10px;user-select:none;cursor:pointer;--sinch-color-icon:var(--sinch-color-stormy-500);--sinch-size-icon:24px}#content{flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}:host(:hover)>#wrapper,:host([data-selected])>#wrapper{background-color:var(--sinch-color-snow-500)}#check{display:none;margin-right:-6px}:host([data-checked]) #check{display:block}:host([disabled]:not([disabled=false]))>#wrapper{color:var(--sinch-color-stormy-100);cursor:initial;--sinch-color-icon:var(--sinch-color-stormy-100)}::slotted(*){margin-left:-6px}</style><div id="wrapper"><slot name="icon"></slot><span id="content"></span><sinch-icon-check id="check"></sinch-icon-check></div>';
11
11
  const template = document.createElement('template');
12
12
  template.innerHTML = templateHTML;
13
13
 
@@ -0,0 +1,11 @@
1
+ import type { TSinchFieldElement, TSinchFieldReact } from './types';
2
+ declare global {
3
+ namespace JSX {
4
+ interface IntrinsicElements {
5
+ 'sinch-field': TSinchFieldReact;
6
+ }
7
+ }
8
+ interface HTMLElementTagNameMap {
9
+ 'sinch-field': TSinchFieldElement;
10
+ }
11
+ }
package/field/index.js ADDED
@@ -0,0 +1,144 @@
1
+ import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
+
4
+ var _$label, _$optionalText, _$additionalText, _$invalidText, _$inputSlot, _onLabelClick;
5
+
6
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
+
8
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
+
10
+ import { defineCustomElement, getAttribute, getBooleanAttribute, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
11
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{display:flex;flex-direction:column;width:100%}#bottom,#top{display:flex;align-items:baseline}#top{height:24px;margin-bottom:2px;--sinch-color-icon:var(--sinch-color-stormy-500)}#additional,#invalid,#label,#optional{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#label{font:var(--sinch-font-title-s);color:var(--sinch-color-text-default)}#optional{flex:1;text-align:right;font:var(--sinch-font-small-text);color:var(--sinch-color-text-muted)}#additional{flex:1;text-align:right;font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-muted);line-height:20px;margin-top:2px}#additional:empty{display:none}#invalid{font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-invalid);line-height:20px;margin-top:2px}#invalid:empty{display:none}::slotted(sinch-help-tooltip){align-self:center;margin:0 8px}:host([disabled]:not([disabled=false])) :is(#label,#additional,#optional,#invalid){color:var(--sinch-color-stormy-100)}:host([disabled]:not([disabled=false])) #top{--sinch-color-icon:var(--sinch-color-stormy-100)}</style><div id="wrapper"><div id="top"><label id="label" for="input"></label><slot name="tooltip"></slot><span id="optional"></span></div><slot name="input"></slot><div id="bottom"><div id="invalid"></div><div id="additional"></div></div></div>';
12
+ const template = document.createElement('template');
13
+ template.innerHTML = templateHTML;
14
+ defineCustomElement('sinch-field', (_$label = new WeakMap(), _$optionalText = new WeakMap(), _$additionalText = new WeakMap(), _$invalidText = new WeakMap(), _$inputSlot = new WeakMap(), _onLabelClick = new WeakMap(), class extends NectaryElement {
15
+ constructor() {
16
+ super();
17
+
18
+ _classPrivateFieldInitSpec(this, _$label, {
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+
23
+ _classPrivateFieldInitSpec(this, _$optionalText, {
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+
28
+ _classPrivateFieldInitSpec(this, _$additionalText, {
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+
33
+ _classPrivateFieldInitSpec(this, _$invalidText, {
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+
38
+ _classPrivateFieldInitSpec(this, _$inputSlot, {
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+
43
+ _classPrivateFieldInitSpec(this, _onLabelClick, {
44
+ writable: true,
45
+ value: () => {
46
+ _classPrivateFieldGet(this, _$inputSlot).assignedElements()[0]?.focus?.();
47
+ }
48
+ });
49
+
50
+ const shadowRoot = this.attachShadow();
51
+ shadowRoot.appendChild(template.content.cloneNode(true));
52
+
53
+ _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#label'));
54
+
55
+ _classPrivateFieldSet(this, _$optionalText, shadowRoot.querySelector('#optional'));
56
+
57
+ _classPrivateFieldSet(this, _$additionalText, shadowRoot.querySelector('#additional'));
58
+
59
+ _classPrivateFieldSet(this, _$invalidText, shadowRoot.querySelector('#invalid'));
60
+
61
+ _classPrivateFieldSet(this, _$inputSlot, shadowRoot.querySelector('slot[name="input"]'));
62
+ }
63
+
64
+ connectedCallback() {
65
+ _classPrivateFieldGet(this, _$label).addEventListener('click', _classPrivateFieldGet(this, _onLabelClick));
66
+ }
67
+
68
+ disconnectedCallback() {
69
+ _classPrivateFieldGet(this, _$label).removeEventListener('click', _classPrivateFieldGet(this, _onLabelClick));
70
+ }
71
+
72
+ static get observedAttributes() {
73
+ return ['label', 'optionaltext', 'additionaltext', 'invalidtext'];
74
+ }
75
+
76
+ set label(value) {
77
+ updateAttribute(this, 'label', value);
78
+ }
79
+
80
+ get label() {
81
+ return getAttribute(this, 'label', '');
82
+ }
83
+
84
+ set optionalText(value) {
85
+ updateAttribute(this, 'optionaltext', value);
86
+ }
87
+
88
+ get optionalText() {
89
+ return getAttribute(this, 'optionaltext', null);
90
+ }
91
+
92
+ set additionalText(value) {
93
+ updateAttribute(this, 'additionaltext', value);
94
+ }
95
+
96
+ get additionalText() {
97
+ return getAttribute(this, 'additionaltext', null);
98
+ }
99
+
100
+ set invalidText(value) {
101
+ updateAttribute(this, 'invalidtext', value);
102
+ }
103
+
104
+ get invalidText() {
105
+ return getAttribute(this, 'invalidtext', null);
106
+ }
107
+
108
+ set disabled(isDisabled) {
109
+ updateBooleanAttribute(this, 'disabled', isDisabled);
110
+ }
111
+
112
+ get disabled() {
113
+ return getBooleanAttribute(this, 'disabled');
114
+ }
115
+
116
+ attributeChangedCallback(name, _, newVal) {
117
+ switch (name) {
118
+ case 'label':
119
+ {
120
+ _classPrivateFieldGet(this, _$label).textContent = newVal;
121
+ break;
122
+ }
123
+
124
+ case 'optionaltext':
125
+ {
126
+ _classPrivateFieldGet(this, _$optionalText).textContent = newVal;
127
+ break;
128
+ }
129
+
130
+ case 'additionaltext':
131
+ {
132
+ _classPrivateFieldGet(this, _$additionalText).textContent = newVal;
133
+ break;
134
+ }
135
+
136
+ case 'invalidtext':
137
+ {
138
+ _classPrivateFieldGet(this, _$invalidText).textContent = newVal;
139
+ break;
140
+ }
141
+ }
142
+ }
143
+
144
+ }));
@@ -0,0 +1,35 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export declare type TSinchFieldElement = HTMLElement & {
3
+ /** Label */
4
+ label: string;
5
+ /** Optional text */
6
+ optionalText: string | null;
7
+ /** Additional text */
8
+ additionalText: string | null;
9
+ /** Invalid text, controls the overall invalid state of the text field */
10
+ invalidText: string | null;
11
+ /** Disabled */
12
+ disabled: boolean;
13
+ /** Label */
14
+ setAttribute(name: 'label', value: string): void;
15
+ /** Optional text */
16
+ setAttribute(name: 'optionaltext', value: string): void;
17
+ /** Additional text */
18
+ setAttribute(name: 'additionaltext', value: string): void;
19
+ /** Invalid text, controls the overall invalid state of the text field */
20
+ setAttribute(name: 'invalidtext', value: string): void;
21
+ /** Disabled */
22
+ setAttribute(name: 'disabled', value: ''): void;
23
+ };
24
+ export declare type TSinchFieldReact = TSinchElementReact<TSinchFieldElement> & {
25
+ /** Label that shows in UI */
26
+ label: string;
27
+ /** Optional text */
28
+ optionalText?: string;
29
+ /** Additional text */
30
+ additionalText?: string;
31
+ /** Invalid text, controls the overall invalid state of the text field */
32
+ invalidText?: string;
33
+ /** Disabled */
34
+ disabled?: boolean;
35
+ };
package/field/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import '../text';
2
+ import '../file-picker';
3
+ import type { TSinchFileDropElement, TSinchFileDropReact } from './types';
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'sinch-file-drop': TSinchFileDropReact;
8
+ }
9
+ }
10
+ interface HTMLElementTagNameMap {
11
+ 'sinch-file-drop': TSinchFileDropElement;
12
+ }
13
+ }
@@ -0,0 +1,320 @@
1
+ import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
+
4
+ var _$filePicker, _$dropArea, _$placeholder, _setDragEffect, _onDragEnter, _onDragLeave, _onDragOver, _onDrop, _onFilePickerChange, _onFilePickerInvalid, _onChangeReactHandler, _onInvalidReactHandler, _dispatchChangeEvent, _dispatchInvalidEvent;
5
+
6
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
+
8
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
9
+
10
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
11
+
12
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
13
+
14
+ import '../text';
15
+ import '../file-picker';
16
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
17
+ const templateHTML = '<style>:host{display:block}#wrapper{position:relative;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:center;align-content:center;gap:8px;height:148px;min-width:148px;box-sizing:border-box;padding:16px;border-radius:var(--sinch-shape-radius-m);background-color:var(--sinch-color-background-grey)}#wrapper.drop.valid{background-color:var(--sinch-color-background-blue)}#wrapper::after{content:"";position:absolute;top:0;left:0;right:0;bottom:0;border:1px dashed var(--sinch-color-stormy-100);border-radius:var(--sinch-shape-radius-m);pointer-events:none}#placeholder{align-self:center;text-align:center}:host([invalid]) #wrapper::after{border-color:var(--sinch-color-text-invalid);border-width:1px}#wrapper.drop::after{pointer-events:all}#wrapper.drop.valid::after{border-color:var(--sinch-color-aqua-400);border-width:2px}#wrapper.drop #placeholder{color:var(--sinch-color-text-muted)}:host([disabled]) #wrapper #placeholder{color:var(--sinch-color-stormy-100)}:host([disabled]) #wrapper{background-color:var(--sinch-color-snow-100)}:host([disabled]) #wrapper::after{border-color:var(--sinch-color-stormy-100);border-width:1px}</style><div id="wrapper"><sinch-text id="placeholder" type="m" aria-hidden="true"></sinch-text><sinch-file-picker id="file-picker"><slot></slot></sinch-file-picker></div>';
18
+ import { areFilesAccepted, doFilesSatisfySize } from './utils';
19
+ const template = document.createElement('template');
20
+ template.innerHTML = templateHTML;
21
+ defineCustomElement('sinch-file-drop', (_$filePicker = new WeakMap(), _$dropArea = new WeakMap(), _$placeholder = new WeakMap(), _setDragEffect = new WeakSet(), _onDragEnter = new WeakMap(), _onDragLeave = new WeakMap(), _onDragOver = new WeakMap(), _onDrop = new WeakMap(), _onFilePickerChange = new WeakMap(), _onFilePickerInvalid = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onInvalidReactHandler = new WeakMap(), _dispatchChangeEvent = new WeakSet(), _dispatchInvalidEvent = new WeakSet(), class extends NectaryElement {
22
+ constructor() {
23
+ super();
24
+
25
+ _classPrivateMethodInitSpec(this, _dispatchInvalidEvent);
26
+
27
+ _classPrivateMethodInitSpec(this, _dispatchChangeEvent);
28
+
29
+ _classPrivateMethodInitSpec(this, _setDragEffect);
30
+
31
+ _classPrivateFieldInitSpec(this, _$filePicker, {
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+
36
+ _classPrivateFieldInitSpec(this, _$dropArea, {
37
+ writable: true,
38
+ value: void 0
39
+ });
40
+
41
+ _classPrivateFieldInitSpec(this, _$placeholder, {
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+
46
+ _classPrivateFieldInitSpec(this, _onDragEnter, {
47
+ writable: true,
48
+ value: e => {
49
+ e.stopPropagation();
50
+ e.preventDefault();
51
+ const hasTypes = e.dataTransfer?.types?.includes('Files') === true;
52
+ const hasItems = e.dataTransfer?.items != null && e.dataTransfer.items.length > 0;
53
+
54
+ _classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, true, hasTypes || hasItems);
55
+ }
56
+ });
57
+
58
+ _classPrivateFieldInitSpec(this, _onDragLeave, {
59
+ writable: true,
60
+ value: e => {
61
+ e.stopPropagation();
62
+ e.preventDefault();
63
+
64
+ _classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, false);
65
+ }
66
+ });
67
+
68
+ _classPrivateFieldInitSpec(this, _onDragOver, {
69
+ writable: true,
70
+ value: e => {
71
+ e.stopPropagation();
72
+ e.preventDefault();
73
+ }
74
+ });
75
+
76
+ _classPrivateFieldInitSpec(this, _onDrop, {
77
+ writable: true,
78
+ value: e => {
79
+ e.stopPropagation();
80
+ e.preventDefault();
81
+
82
+ _classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, false);
83
+
84
+ if (this.disabled) {
85
+ return;
86
+ }
87
+
88
+ const dt = e.dataTransfer;
89
+
90
+ if (dt === null) {
91
+ return;
92
+ }
93
+
94
+ if (dt.files.length === 0) {
95
+ return;
96
+ }
97
+
98
+ if (!this.multiple && dt.files.length > 1) {
99
+ _classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, 'multiple');
100
+
101
+ return;
102
+ }
103
+
104
+ const files = Array.from(dt.files);
105
+
106
+ if (!areFilesAccepted(files, this.accept)) {
107
+ _classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, 'accept');
108
+
109
+ return;
110
+ }
111
+
112
+ if (!doFilesSatisfySize(files, this.size)) {
113
+ _classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, 'size');
114
+
115
+ return;
116
+ }
117
+
118
+ _classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, files);
119
+ }
120
+ });
121
+
122
+ _classPrivateFieldInitSpec(this, _onFilePickerChange, {
123
+ writable: true,
124
+ value: e => {
125
+ _classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, e.detail);
126
+ }
127
+ });
128
+
129
+ _classPrivateFieldInitSpec(this, _onFilePickerInvalid, {
130
+ writable: true,
131
+ value: e => {
132
+ _classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, e.detail);
133
+ }
134
+ });
135
+
136
+ _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
137
+ writable: true,
138
+ value: e => {
139
+ getReactEventHandler(this, 'on-change')?.(e);
140
+ }
141
+ });
142
+
143
+ _classPrivateFieldInitSpec(this, _onInvalidReactHandler, {
144
+ writable: true,
145
+ value: e => {
146
+ getReactEventHandler(this, 'on-invalid')?.(e);
147
+ }
148
+ });
149
+
150
+ const shadowRoot = this.attachShadow();
151
+ shadowRoot.appendChild(template.content.cloneNode(true));
152
+
153
+ _classPrivateFieldSet(this, _$dropArea, shadowRoot.querySelector('#wrapper'));
154
+
155
+ _classPrivateFieldSet(this, _$placeholder, shadowRoot.querySelector('#placeholder'));
156
+
157
+ _classPrivateFieldSet(this, _$filePicker, shadowRoot.querySelector('#file-picker'));
158
+ }
159
+
160
+ connectedCallback() {
161
+ this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
162
+ this.addEventListener('-invalid', _classPrivateFieldGet(this, _onInvalidReactHandler));
163
+ this.addEventListener('dragenter', _classPrivateFieldGet(this, _onDragEnter));
164
+ this.addEventListener('dragleave', _classPrivateFieldGet(this, _onDragLeave));
165
+ this.addEventListener('dragover', _classPrivateFieldGet(this, _onDragOver));
166
+ this.addEventListener('drop', _classPrivateFieldGet(this, _onDrop));
167
+
168
+ _classPrivateFieldGet(this, _$filePicker).addEventListener('-change', _classPrivateFieldGet(this, _onFilePickerChange));
169
+
170
+ _classPrivateFieldGet(this, _$filePicker).addEventListener('-invalid', _classPrivateFieldGet(this, _onFilePickerInvalid));
171
+ }
172
+
173
+ disconnectedCallback() {
174
+ this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
175
+ this.removeEventListener('-invalid', _classPrivateFieldGet(this, _onInvalidReactHandler));
176
+ this.removeEventListener('dragenter', _classPrivateFieldGet(this, _onDragEnter));
177
+ this.removeEventListener('dragleave', _classPrivateFieldGet(this, _onDragLeave));
178
+ this.removeEventListener('dragover', _classPrivateFieldGet(this, _onDragOver));
179
+ this.removeEventListener('drop', _classPrivateFieldGet(this, _onDrop));
180
+
181
+ _classPrivateFieldGet(this, _$filePicker).removeEventListener('-change', _classPrivateFieldGet(this, _onFilePickerChange));
182
+
183
+ _classPrivateFieldGet(this, _$filePicker).removeEventListener('-invalid', _classPrivateFieldGet(this, _onFilePickerInvalid));
184
+ }
185
+
186
+ static get observedAttributes() {
187
+ return ['accept', 'multiple', 'placeholder', 'disabled', 'invalid', 'size'];
188
+ }
189
+
190
+ attributeChangedCallback(name, oldVal, newVal) {
191
+ if (newVal === oldVal) {
192
+ return;
193
+ }
194
+
195
+ switch (name) {
196
+ case 'multiple':
197
+ {
198
+ updateAttribute(_classPrivateFieldGet(this, _$filePicker), 'multiple', newVal);
199
+ break;
200
+ }
201
+
202
+ case 'accept':
203
+ {
204
+ updateAttribute(_classPrivateFieldGet(this, _$filePicker), 'accept', newVal);
205
+ break;
206
+ }
207
+
208
+ case 'placeholder':
209
+ {
210
+ _classPrivateFieldGet(this, _$placeholder).textContent = newVal;
211
+ break;
212
+ }
213
+
214
+ case 'disabled':
215
+ {
216
+ updateBooleanAttribute(this, 'disabled', isAttrTrue(newVal));
217
+
218
+ _classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, false);
219
+
220
+ break;
221
+ }
222
+
223
+ case 'invalid':
224
+ {
225
+ updateBooleanAttribute(this, 'invalid', isAttrTrue(newVal));
226
+ break;
227
+ }
228
+
229
+ case 'size':
230
+ {
231
+ updateAttribute(_classPrivateFieldGet(this, _$filePicker), 'size', newVal);
232
+ break;
233
+ }
234
+ }
235
+ }
236
+
237
+ set multiple(isMultiple) {
238
+ updateBooleanAttribute(this, 'multiple', isMultiple);
239
+ }
240
+
241
+ get multiple() {
242
+ return getBooleanAttribute(this, 'multiple');
243
+ }
244
+
245
+ set accept(value) {
246
+ updateAttribute(this, 'accept', value);
247
+ }
248
+
249
+ get accept() {
250
+ return getAttribute(this, 'accept', null);
251
+ }
252
+
253
+ get size() {
254
+ return getIntegerAttribute(this, 'size', null);
255
+ }
256
+
257
+ set size(value) {
258
+ updateAttribute(this, 'size', value);
259
+ }
260
+
261
+ set text(value) {
262
+ updateAttribute(this, 'text', value);
263
+ }
264
+
265
+ get text() {
266
+ return getAttribute(this, 'text', '');
267
+ }
268
+
269
+ set placeholder(value) {
270
+ updateAttribute(this, 'placeholder', value);
271
+ }
272
+
273
+ get placeholder() {
274
+ return getAttribute(this, 'placeholder', '');
275
+ }
276
+
277
+ set disabled(isDisabled) {
278
+ updateBooleanAttribute(this, 'disabled', isDisabled);
279
+ }
280
+
281
+ get disabled() {
282
+ return getBooleanAttribute(this, 'disabled');
283
+ }
284
+
285
+ set invalid(isInvalid) {
286
+ updateBooleanAttribute(this, 'invalid', isInvalid);
287
+ }
288
+
289
+ get invalid() {
290
+ return getBooleanAttribute(this, 'invalid');
291
+ }
292
+
293
+ }));
294
+
295
+ function _setDragEffect2(shouldEnable) {
296
+ let isValid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
297
+ const isElementEnabled = !this.disabled;
298
+
299
+ if (shouldEnable) {
300
+ if (isElementEnabled) {
301
+ setClass(_classPrivateFieldGet(this, _$dropArea), 'drop', true);
302
+ setClass(_classPrivateFieldGet(this, _$dropArea), 'valid', isValid);
303
+ }
304
+ } else {
305
+ setClass(_classPrivateFieldGet(this, _$dropArea), 'drop', false);
306
+ setClass(_classPrivateFieldGet(this, _$dropArea), 'valid', false);
307
+ }
308
+ }
309
+
310
+ function _dispatchChangeEvent2(files) {
311
+ this.dispatchEvent(new CustomEvent('-change', {
312
+ detail: files
313
+ }));
314
+ }
315
+
316
+ function _dispatchInvalidEvent2(type) {
317
+ this.dispatchEvent(new CustomEvent('-invalid', {
318
+ detail: type
319
+ }));
320
+ }