@nectary/components 0.36.1 → 0.37.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/textarea/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
2
  import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
3
 
4
- var _$input, _$label, _$optionalText, _$additionalText, _$invalidText, _cursorPos, _isPendingDk, _onCompositionStart, _onSelectionChange, _onInput, _onInputFocus, _onInputBlur, _onChangeReactHandler, _onFocusReactHandler, _onBlurReactHandler;
4
+ var _$input, _cursorPos, _isPendingDk, _onCompositionStart, _onSelectionChange, _onInput, _onInputFocus, _onInputBlur, _onChangeReactHandler, _onFocusReactHandler, _onBlurReactHandler;
5
5
 
6
6
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
7
 
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, getBooleanAttribute, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
11
- const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0;--sinch-color-icon:var(--sinch-color-stormy-500)}#wrapper{width:100%;box-sizing:border-box}#input{all:initial;display:block;border:1px solid var(--sinch-color-stormy-200);box-sizing:border-box;border-radius:var(--sinch-shape-radius-s);width:100%;padding:8px 12px;font:var(--sinch-font-body);color:var(--sinch-color-text-default);caret-color:var(--sinch-caret-color,auto);background-color:var(--sinch-color-snow-100);resize:none}#input::placeholder{font:var(--sinch-font-body);color:var(--sinch-color-text-muted)}#input:disabled{border-color:var(--sinch-color-snow-500);color:var(--sinch-color-stormy-100)}#input:disabled::placeholder{color:var(--sinch-color-snow-500)}#input:focus{border-color:var(--sinch-color-stormy-600)}:host([resizable]:not([resizable=false])) #input{resize:vertical}:host([invalidtext]:not([invalidtext=""])) #input:not(:disabled){border-color:var(--sinch-color-text-invalid)}#bottom,#top{display:flex;align-items:baseline}#top{height:24px;margin-bottom:2px}#additional,#invalid,#label,#optional{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#label{font:var(--sinch-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])){--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><textarea id="input"></textarea><div id="bottom"><span id="invalid"></span><span id="additional"></span></div></div>';
11
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#input{all:initial;display:block;border:1px solid var(--sinch-color-stormy-200);box-sizing:border-box;border-radius:var(--sinch-shape-radius-s);width:100%;padding:8px 12px;font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);resize:none}#input::placeholder{font:var(--sinch-font-body);color:var(--sinch-color-text-muted);opacity:1}#input:disabled{border-color:var(--sinch-color-snow-500);color:var(--sinch-color-stormy-100)}#input:disabled::placeholder{color:var(--sinch-color-snow-500)}#input:focus{border-color:var(--sinch-color-stormy-600)}:host([resizable]:not([resizable=false])) #input{resize:vertical}:host([invalid]:not([invalid=false])) #input:enabled{border-color:var(--sinch-color-text-invalid)}</style><textarea id="input"></textarea>';
12
12
  const template = document.createElement('template');
13
13
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _$label = new WeakMap(), _$optionalText = new WeakMap(), _$additionalText = new WeakMap(), _$invalidText = new WeakMap(), _cursorPos = new WeakMap(), _isPendingDk = new WeakMap(), _onCompositionStart = new WeakMap(), _onSelectionChange = new WeakMap(), _onInput = new WeakMap(), _onInputFocus = new WeakMap(), _onInputBlur = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
14
+ defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _cursorPos = new WeakMap(), _isPendingDk = new WeakMap(), _onCompositionStart = new WeakMap(), _onSelectionChange = new WeakMap(), _onInput = new WeakMap(), _onInputFocus = new WeakMap(), _onInputBlur = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
15
15
  constructor() {
16
16
  super();
17
17
 
@@ -20,26 +20,6 @@ defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _$label = new We
20
20
  value: void 0
21
21
  });
22
22
 
23
- _classPrivateFieldInitSpec(this, _$label, {
24
- writable: true,
25
- value: void 0
26
- });
27
-
28
- _classPrivateFieldInitSpec(this, _$optionalText, {
29
- writable: true,
30
- value: void 0
31
- });
32
-
33
- _classPrivateFieldInitSpec(this, _$additionalText, {
34
- writable: true,
35
- value: void 0
36
- });
37
-
38
- _classPrivateFieldInitSpec(this, _$invalidText, {
39
- writable: true,
40
- value: void 0
41
- });
42
-
43
23
  _classPrivateFieldInitSpec(this, _cursorPos, {
44
24
  writable: true,
45
25
  value: null
@@ -142,14 +122,6 @@ defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _$label = new We
142
122
  shadowRoot.appendChild(template.content.cloneNode(true));
143
123
 
144
124
  _classPrivateFieldSet(this, _$input, shadowRoot.querySelector('#input'));
145
-
146
- _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#label'));
147
-
148
- _classPrivateFieldSet(this, _$optionalText, shadowRoot.querySelector('#optional'));
149
-
150
- _classPrivateFieldSet(this, _$additionalText, shadowRoot.querySelector('#additional'));
151
-
152
- _classPrivateFieldSet(this, _$invalidText, shadowRoot.querySelector('#invalid'));
153
125
  }
154
126
 
155
127
  connectedCallback() {
@@ -192,10 +164,14 @@ defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _$label = new We
192
164
  }
193
165
 
194
166
  static get observedAttributes() {
195
- return ['value', 'placeholder', 'label', 'optionaltext', 'additionaltext', 'invalidtext', 'disabled', 'rows'];
167
+ return ['value', 'placeholder', 'invalid', 'disabled', 'rows'];
196
168
  }
197
169
 
198
- attributeChangedCallback(name, _, newVal) {
170
+ attributeChangedCallback(name, oldVal, newVal) {
171
+ if (oldVal === newVal) {
172
+ return;
173
+ }
174
+
199
175
  switch (name) {
200
176
  case 'value':
201
177
  {
@@ -217,12 +193,6 @@ defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _$label = new We
217
193
  break;
218
194
  }
219
195
 
220
- case 'label':
221
- {
222
- _classPrivateFieldGet(this, _$label).textContent = newVal;
223
- break;
224
- }
225
-
226
196
  case 'placeholder':
227
197
  {
228
198
  _classPrivateFieldGet(this, _$input).placeholder = newVal ?? '';
@@ -230,23 +200,9 @@ defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _$label = new We
230
200
  break;
231
201
  }
232
202
 
233
- case 'optionaltext':
234
- {
235
- _classPrivateFieldGet(this, _$optionalText).textContent = newVal;
236
- break;
237
- }
238
-
239
- case 'additionaltext':
240
- {
241
- _classPrivateFieldGet(this, _$additionalText).textContent = newVal;
242
- break;
243
- }
244
-
245
- case 'invalidtext':
203
+ case 'invalid':
246
204
  {
247
- const isInvalid = newVal !== null && newVal !== '';
248
- _classPrivateFieldGet(this, _$invalidText).textContent = newVal;
249
- updateExplicitBooleanAttribute(this, 'aria-invalid', isInvalid);
205
+ updateExplicitBooleanAttribute(this, 'aria-invalid', isAttrTrue(newVal));
250
206
  break;
251
207
  }
252
208
 
@@ -286,36 +242,12 @@ defineCustomElement('sinch-textarea', (_$input = new WeakMap(), _$label = new We
286
242
  return getAttribute(this, 'placeholder', null);
287
243
  }
288
244
 
289
- set label(value) {
290
- updateAttribute(this, 'label', value);
291
- }
292
-
293
- get label() {
294
- return getAttribute(this, 'label', '');
295
- }
296
-
297
- set optionalText(value) {
298
- updateAttribute(this, 'optionaltext', value);
299
- }
300
-
301
- get optionalText() {
302
- return getAttribute(this, 'optionaltext', null);
303
- }
304
-
305
- set additionalText(value) {
306
- updateAttribute(this, 'additionaltext', value);
307
- }
308
-
309
- get additionalText() {
310
- return getAttribute(this, 'additionaltext', null);
311
- }
312
-
313
- set invalidText(value) {
314
- updateAttribute(this, 'invalidtext', value);
245
+ set invalid(value) {
246
+ updateBooleanAttribute(this, 'invalid', value);
315
247
  }
316
248
 
317
- get invalidText() {
318
- return getAttribute(this, 'invalidtext', null);
249
+ get invalid() {
250
+ return getBooleanAttribute(this, 'invalid');
319
251
  }
320
252
 
321
253
  set disabled(isDisabled) {
@@ -1,44 +1,60 @@
1
1
  import type { TSinchElementReact } from '../types';
2
2
  import type { SyntheticEvent } from 'react';
3
3
  export declare type TSinchTextareaElement = HTMLElement & {
4
+ /** Value */
4
5
  value: string;
5
- label: string;
6
+ /** Text that appears in the text field when it has no value set */
6
7
  placeholder: string | null;
7
- optionalText: string | null;
8
- invalidText: string | null;
9
- additionalText: string | null;
8
+ /** Disabled */
10
9
  disabled: boolean;
10
+ /** Invalid state */
11
+ invalid: boolean;
11
12
  selectionStart: HTMLTextAreaElement['selectionStart'];
12
13
  selectionEnd: HTMLTextAreaElement['selectionEnd'];
13
14
  selectionDirection: HTMLTextAreaElement['selectionDirection'];
15
+ /** Number of rows */
14
16
  rows: HTMLTextAreaElement['rows'];
17
+ /** Whether the text field is resizable */
15
18
  resizable: boolean;
19
+ /** Change value event */
16
20
  addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
21
+ /** Focus event */
17
22
  addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
23
+ /** Blur event */
18
24
  addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
25
+ /** Value */
19
26
  setAttribute(name: 'value', value: string): void;
20
- setAttribute(name: 'label', value: string): void;
27
+ /** Text that appears in the text field when it has no value set */
21
28
  setAttribute(name: 'placeholder', value: string): void;
22
- setAttribute(name: 'optionaltext', value: string): void;
23
- setAttribute(name: 'invalidtext', value: string): void;
24
- setAttribute(name: 'additionaltext', value: string): void;
29
+ /** Invalid state */
30
+ setAttribute(name: 'invalid', value: ''): void;
31
+ /** Disabled */
25
32
  setAttribute(name: 'disabled', value: ''): void;
33
+ /** Number of rows */
26
34
  setAttribute(name: 'rows', value: string): void;
35
+ /** Whether the text field is resizable */
27
36
  setAttribute(name: 'resizable', value: ''): void;
28
37
  };
29
38
  export declare type TSinchTextareaReact = TSinchElementReact<TSinchTextareaElement> & {
39
+ /** Value */
30
40
  value: string;
31
- label: string;
41
+ /** Text that appears in the text field when it has no value set */
32
42
  placeholder?: string;
33
- optionalText?: string;
34
- invalidText?: string;
35
- additionalText?: string;
43
+ /** Disabled */
36
44
  disabled?: boolean;
45
+ /** Invalid state */
46
+ invalid?: boolean;
37
47
  'aria-label': string;
48
+ /** Number of rows */
38
49
  rows?: number;
50
+ /** Whether the text field is resizable */
39
51
  resizable?: boolean;
52
+ /** @deprecated Change value handler */
40
53
  onChange?: (e: SyntheticEvent<TSinchTextareaElement, CustomEvent<string>>) => void;
54
+ /** Change value handler */
41
55
  'on-change'?: (e: CustomEvent<string>) => void;
56
+ /** Focus handler */
42
57
  'on-focus'?: (e: CustomEvent<void>) => void;
58
+ /** Blur handler */
43
59
  'on-blur'?: (e: CustomEvent<void>) => void;
44
60
  };
package/utils.d.ts CHANGED
@@ -8,6 +8,7 @@ declare global {
8
8
  }
9
9
  export declare class NectaryElement extends HTMLElement {
10
10
  attachShadow(options?: Partial<ShadowRootInit>): ShadowRoot;
11
+ __version: string;
11
12
  }
12
13
  export declare const getReactEventHandler: ($element: HTMLElement, handlerName: string) => ((arg?: any) => void) | null;
13
14
  export declare const updateExplicitBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
package/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import pkg from './package.json';
1
3
  const nectaryDefinitions = new Map();
2
4
  let nectaryRegistry = null;
3
5
  export const defineCustomElement = (name, constructor) => {
@@ -27,6 +29,12 @@ export const setNectaryRegistry = registry => {
27
29
  nectaryDefinitions.clear();
28
30
  };
29
31
  export class NectaryElement extends HTMLElement {
32
+ constructor() {
33
+ super(...arguments);
34
+
35
+ _defineProperty(this, '__version', pkg.version);
36
+ }
37
+
30
38
  attachShadow(options) {
31
39
  return super.attachShadow({
32
40
  mode: 'closed',
@@ -10,7 +10,7 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
10
10
  import '../icons/check';
11
11
  import '../icons/exclamation';
12
12
  import { defineCustomElement, getAttribute, getLiteralAttribute, NectaryElement, updateAttribute, updateLiteralAttribute } from '../utils';
13
- const templateHTML = '<style>:host{display:block;outline:0}#wrapper{position:relative;width:100%;min-height:68px;display:flex;flex-direction:column}#circle-wrapper{display:flex;flex-direction:row;align-items:flex-start;gap:8px;min-width:0}#circle{display:flex;align-items:center;justify-content:center;width:32px;height:32px;background-color:var(--sinch-color-snow-700);font:var(--sinch-font-title-s);line-height:32px;text-align:center;color:var(--sinch-color-stormy-500);border:1px solid transparent;border-radius:50%;box-sizing:border-box;--sinch-icon-size:20px}#label-wrapper{margin-top:4px;min-width:0;flex:1}#label{font:var(--sinch-font-title-s);color:var(--sinch-color-stormy-500);overflow:hidden;white-space:nowrap;text-overflow:ellipsis}#description{font:var(--sinch-font-text-xs);color:var(--sinch-color-stormy-300);overflow:hidden;white-space:nowrap;text-overflow:ellipsis}#icon-error,#icon-success{display:none}#content{display:none;padding:16px 0 16px 40px}#progress{position:absolute;width:1px;left:16px;top:32px;bottom:0;background-color:var(--sinch-color-snow-700);transform:translateX(-50%)}#bar{position:absolute;width:1px;height:0;background-color:var(--sinch-color-stormy-400);left:0;top:0}:host(:last-of-type) #progress{display:none}:host([data-progress=active]) #content{display:block}:host([data-progress=active]) #circle{color:var(--sinch-color-snow-100);background-color:var(--sinch-color-stormy-400)}:host([data-progress=done]) #circle{border-color:var(--sinch-color-stormy-400)}:host([data-progress=done]:not([status])) #icon-success{display:block}:host([data-progress=done][status=error]) #circle{background-color:var(--sinch-color-error-200);border-color:var(--sinch-color-stormy-400)}:host([data-progress=done][status=error]) #icon-error{display:block}:host([data-progress=done]:not([status=skip])) #circle-text{display:none}:host([data-progress=done]) #bar{height:100%}</style><div id="wrapper"><div id="progress"><div id="bar"></div></div><div id="circle-wrapper"><div id="circle" aria-hidden="true"><sinch-icon-check id="icon-success"></sinch-icon-check><sinch-icon-exclamation id="icon-error"></sinch-icon-exclamation><span id="circle-text"></span></div><div id="label-wrapper"><div id="label"></div><div id="description"></div></div></div><div id="content"><slot></slot></div></div>';
13
+ const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:column;position:relative;width:100%;min-height:68px}#circle-wrapper{display:flex;flex-direction:row;align-items:flex-start;gap:8px;min-width:0}#circle{display:flex;align-items:center;justify-content:center;width:32px;height:32px;background-color:var(--sinch-color-snow-700);font:var(--sinch-font-title-s);line-height:32px;text-align:center;color:var(--sinch-color-stormy-500);border:1px solid transparent;border-radius:50%;box-sizing:border-box;--sinch-icon-size:20px}#label-wrapper{margin-top:4px;min-width:0;flex:1}#label{font:var(--sinch-font-title-s);color:var(--sinch-color-stormy-500);overflow:hidden;white-space:nowrap;text-overflow:ellipsis}#description{font:var(--sinch-font-text-xs);color:var(--sinch-color-stormy-300);overflow:hidden;white-space:nowrap;text-overflow:ellipsis}#icon-error,#icon-success{display:none}#content{display:none;padding:16px 0 16px 40px}#progress{position:absolute;width:1px;left:16px;top:32px;bottom:0;background-color:var(--sinch-color-snow-700);transform:translateX(-50%)}#bar{position:absolute;width:1px;height:0;background-color:var(--sinch-color-stormy-400);left:0;top:0}:host(:last-of-type) #progress{display:none}:host([data-progress=active]) #content{display:block}:host([data-progress=active]) #circle{color:var(--sinch-color-snow-100);background-color:var(--sinch-color-stormy-400)}:host([data-progress=done]) #circle{border-color:var(--sinch-color-stormy-400)}:host([data-progress=done]:not([status])) #icon-success{display:block}:host([data-progress=done][status=error]) #circle{background-color:var(--sinch-color-error-200);border-color:var(--sinch-color-stormy-400)}:host([data-progress=done][status=error]) #icon-error{display:block}:host([data-progress=done]:not([status=skip])) #circle-text{display:none}:host([data-progress=done]) #bar{height:100%}</style><div id="wrapper"><div id="progress"><div id="bar"></div></div><div id="circle-wrapper"><div id="circle" aria-hidden="true"><sinch-icon-check id="icon-success"></sinch-icon-check><sinch-icon-exclamation id="icon-error"></sinch-icon-exclamation><span id="circle-text"></span></div><div id="label-wrapper"><div id="label"></div><div id="description"></div></div></div><div id="content"><slot></slot></div></div>';
14
14
  import { statusValues } from './utils';
15
15
  const template = document.createElement('template');
16
16
  template.innerHTML = templateHTML;