@nectary/components 2.8.8 → 2.10.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/input/index.js CHANGED
@@ -107,14 +107,14 @@ defineCustomElement('sinch-input', class extends NectaryElement {
107
107
  this.#$input.value = value;
108
108
  this.#$inputMask.textContent = placeholder;
109
109
  if (isElementFocused(this.#$input)) {
110
- this.#$input.setSelectionRange(this.#selectionEnd, this.#selectionEnd);
110
+ this.#setSelectionRange(this.#selectionEnd, this.#selectionEnd);
111
111
  }
112
112
  break;
113
113
  }
114
114
  if (nextVal !== prevVal) {
115
115
  this.#$input.value = nextVal;
116
116
  if (isElementFocused(this.#$input)) {
117
- this.#$input.setSelectionRange(this.#selectionEnd, this.#selectionEnd);
117
+ this.#setSelectionRange(this.#selectionEnd, this.#selectionEnd);
118
118
  }
119
119
  }
120
120
  break;
@@ -255,7 +255,7 @@ defineCustomElement('sinch-input', class extends NectaryElement {
255
255
  this.#$input.selectionDirection = value;
256
256
  }
257
257
  setSelectionRange(selectionStart, selectionEnd) {
258
- this.#$input.setSelectionRange(selectionStart, selectionEnd);
258
+ this.#setSelectionRange(selectionStart, selectionEnd);
259
259
  }
260
260
  get focusable() {
261
261
  return true;
@@ -266,6 +266,11 @@ defineCustomElement('sinch-input', class extends NectaryElement {
266
266
  blur() {
267
267
  this.#$input.blur();
268
268
  }
269
+ #setSelectionRange = (start, end, direction) => {
270
+ if (this.type !== 'number') {
271
+ this.#$input.setSelectionRange(start, end, direction);
272
+ }
273
+ };
269
274
  #onCompositionStart = () => {
270
275
  this.#isCompositionInProgress = true;
271
276
  if (this.#maskSymbols !== null) {
@@ -279,7 +284,7 @@ defineCustomElement('sinch-input', class extends NectaryElement {
279
284
  placeholder
280
285
  } = beginMaskedComposition(this.#$input.value, this.#maskSymbols, selectionStart);
281
286
  this.#$input.value = value;
282
- this.#$input.setSelectionRange(selectionStart, selectionStart);
287
+ this.#setSelectionRange(selectionStart, selectionStart);
283
288
  this.#$inputMask.textContent = placeholder;
284
289
  this.#compositionBeginValue = value;
285
290
  }
@@ -299,7 +304,7 @@ defineCustomElement('sinch-input', class extends NectaryElement {
299
304
  cursorPos
300
305
  } = res;
301
306
  this.#$input.value = value;
302
- this.#$input.setSelectionRange(cursorPos, cursorPos);
307
+ this.#setSelectionRange(cursorPos, cursorPos);
303
308
  this.#$inputMask.textContent = placeholder;
304
309
  if (mergedValue.length > 0) {
305
310
  this.#selectionStart = cursorPos;
@@ -354,7 +359,7 @@ defineCustomElement('sinch-input', class extends NectaryElement {
354
359
  cursorPos
355
360
  } = res;
356
361
  this.#$input.value = value;
357
- this.#$input.setSelectionRange(cursorPos, cursorPos);
362
+ this.#setSelectionRange(cursorPos, cursorPos);
358
363
  this.#$inputMask.textContent = placeholder;
359
364
  if (mergedValue.length > 0) {
360
365
  this.#selectionStart = cursorPos;
@@ -408,7 +413,7 @@ defineCustomElement('sinch-input', class extends NectaryElement {
408
413
  const nextSelectionStart = this.#$input.selectionStart;
409
414
  const nextSelectionEnd = this.#$input.selectionEnd;
410
415
  this.#$input.value = prevValue;
411
- this.#$input.setSelectionRange(this.#selectionStart, this.#selectionEnd);
416
+ this.#setSelectionRange(this.#selectionStart, this.#selectionEnd);
412
417
  this.#selectionStart = nextSelectionStart;
413
418
  this.#selectionEnd = nextSelectionEnd;
414
419
  this.#dispatchChangeEvent(nextValue);
@@ -424,7 +429,7 @@ defineCustomElement('sinch-input', class extends NectaryElement {
424
429
  cursorPos
425
430
  } = splitValueAndMask(nextVal, this.#maskSymbols);
426
431
  this.#$input.value = value;
427
- this.#$input.setSelectionRange(cursorPos, cursorPos);
432
+ this.#setSelectionRange(cursorPos, cursorPos);
428
433
  this.#$inputMask.textContent = placeholder;
429
434
  if (mergedValue.length > 0) {
430
435
  this.#selectionStart = cursorPos;
package/input/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { TSinchElementReact } from '../types';
2
2
  import type { TSinchSize } from '../utils/size';
3
- export type TSinchInputType = 'text' | 'password';
3
+ export type TSinchInputType = 'text' | 'password' | 'number';
4
4
  export type TSinchInputClipboardEvent = CustomEvent<{
5
5
  value: string;
6
6
  replaceWith: (value: string) => void;
package/input/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- export const inputTypes = ['text', 'password'];
1
+ export const inputTypes = ['text', 'password', 'number'];
2
2
  const MASK_SYMBOL_LETTER = 'A';
3
3
  const MASK_SYMBOL_DIGIT = '0';
4
4
  const EMPTY_CHAR = ' ';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "2.8.8",
3
+ "version": "2.10.0",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
@@ -34,7 +34,5 @@ export type TSinchPopoverReact = TSinchElementReact<TSinchPopoverElement> & {
34
34
  /** Label that is used for a11y */
35
35
  'aria-label': string;
36
36
  /** Close event handler */
37
- onClose?: () => void;
38
- /** Close event handler */
39
37
  'on-close'?: (e: CustomEvent<void>) => void;
40
38
  };
package/text/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineCustomElement, getBooleanAttribute, updateBooleanAttribute, NectaryElement, getLiteralAttribute, updateLiteralAttribute, isAttrTrue, isAttrEqual } from '../utils';
2
- const templateHTML = '<style>:host{display:block;font:var(--sinch-comp-text-font);color:var(--sinch-global-color-text,var(--sinch-sys-color-text-default));--sinch-comp-text-font:var(--sinch-sys-font-body-m)}:host([inline]){display:inline}:host([type="s"]){--sinch-comp-text-font:var(--sinch-sys-font-body-s)}:host([type=xs]){--sinch-comp-text-font:var(--sinch-sys-font-body-xs)}:host([type=xxs]){--sinch-comp-text-font:var(--sinch-sys-font-body-xxs)}:host([type="m"][emphasized]){--sinch-comp-text-font:var(--sinch-sys-font-body-emphasize)}:host([type="s"][emphasized]){--sinch-comp-text-font:var(--sinch-sys-font-body-emphasize-s)}:host([ellipsis]){overflow:hidden;text-overflow:ellipsis;white-space:nowrap;--sinch-global-text-white-space:nowrap}</style><slot></slot>';
2
+ const templateHTML = '<style>:host{text-align:var(--sinch-comp-text-align);display:block;font:var(--sinch-comp-text-font);color:var(--sinch-global-color-text,var(--sinch-sys-color-text-default));--sinch-comp-text-font:var(--sinch-sys-font-body-m);--sinch-comp-text-align:unset}:host([inline]){display:inline}:host([type="s"]){--sinch-comp-text-font:var(--sinch-sys-font-body-s)}:host([type=xs]){--sinch-comp-text-font:var(--sinch-sys-font-body-xs)}:host([type=xxs]){--sinch-comp-text-font:var(--sinch-sys-font-body-xxs)}:host([type="m"][emphasized]){--sinch-comp-text-font:var(--sinch-sys-font-body-emphasize)}:host([type="s"][emphasized]){--sinch-comp-text-font:var(--sinch-sys-font-body-emphasize-s)}:host([ellipsis]){overflow:hidden;text-overflow:ellipsis;white-space:nowrap;--sinch-global-text-white-space:nowrap}</style><slot></slot>';
3
3
  import { typeValues } from './utils';
4
4
  const template = document.createElement('template');
5
5
  template.innerHTML = templateHTML;
package/tooltip/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import '../text';
2
2
  import '../pop';
3
3
  import { defineCustomElement, getAttribute, getLiteralAttribute, updateBooleanAttribute, updateAttribute, updateLiteralAttribute, NectaryElement, setClass, rectOverlap, getReactEventHandler, shouldReduceMotion } from '../utils';
4
- const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
4
+ const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
5
5
  import { TooltipState } from './tooltip-state';
6
- import { getPopOrientation, orientationValues, typeValues } from './utils';
6
+ import { getPopOrientation, orientationValues, textAlignValues, typeValues } from './utils';
7
7
  const TIP_SIZE = 8;
8
8
  const SHOW_DELAY_SLOW = 1000;
9
9
  const SHOW_DELAY_FAST = 250;
@@ -63,7 +63,7 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
63
63
  this.#controller = null;
64
64
  }
65
65
  static get observedAttributes() {
66
- return ['text', 'orientation', 'type', 'aria-label', 'aria-description'];
66
+ return ['text', 'orientation', 'text-align', 'type', 'aria-label', 'aria-description'];
67
67
  }
68
68
  attributeChangedCallback(name, _, newVal) {
69
69
  switch (name) {
@@ -81,6 +81,11 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
81
81
  }
82
82
  break;
83
83
  }
84
+ case 'text-align':
85
+ {
86
+ updateAttribute(this.#$pop, 'text-align', newVal);
87
+ break;
88
+ }
84
89
  case 'type':
85
90
  {
86
91
  this.#tooltipState.updateOptions({
@@ -108,6 +113,12 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
108
113
  set orientation(value) {
109
114
  updateLiteralAttribute(this, orientationValues, 'orientation', value);
110
115
  }
116
+ get 'text-align'() {
117
+ return getLiteralAttribute(this, textAlignValues, 'text-align', 'left');
118
+ }
119
+ set 'text-align'(value) {
120
+ updateLiteralAttribute(this, textAlignValues, 'text-align', value);
121
+ }
111
122
  get type() {
112
123
  return getLiteralAttribute(this, typeValues, 'type', 'slow');
113
124
  }
@@ -1,5 +1,6 @@
1
1
  import type { TRect, TSinchElementReact } from '../types';
2
2
  export type TSinchTooltipOrientation = 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
3
+ export type TSinchTooltipTextAlign = 'center' | 'right' | 'left';
3
4
  export type TSinchTooltipType = 'slow' | 'fast';
4
5
  export type TSinchTooltipElement = HTMLElement & {
5
6
  /** Text */
@@ -8,6 +9,8 @@ export type TSinchTooltipElement = HTMLElement & {
8
9
  orientation: TSinchTooltipOrientation;
9
10
  /** Type */
10
11
  type: TSinchTooltipType;
12
+ /** Text Align */
13
+ 'text-align': TSinchTooltipTextAlign;
11
14
  readonly footprintRect: TRect;
12
15
  readonly tooltipRect: TRect;
13
16
  /** Show event */
@@ -20,6 +23,8 @@ export type TSinchTooltipElement = HTMLElement & {
20
23
  setAttribute(name: 'orientation', value: TSinchTooltipOrientation): void;
21
24
  /** Type */
22
25
  setAttribute(name: 'type', value: TSinchTooltipType): void;
26
+ /** Text Align */
27
+ setAttribute(name: 'text-align', value: TSinchTooltipTextAlign): void;
23
28
  };
24
29
  export type TSinchTooltipReact = TSinchElementReact<TSinchTooltipElement> & {
25
30
  /** Text */
@@ -28,6 +33,8 @@ export type TSinchTooltipReact = TSinchElementReact<TSinchTooltipElement> & {
28
33
  orientation?: TSinchTooltipOrientation;
29
34
  /** Type */
30
35
  type?: TSinchTooltipType;
36
+ /** Text Align */
37
+ 'text-align'?: TSinchTooltipTextAlign;
31
38
  /** Show event handler */
32
39
  'on-show'?: (e: CustomEvent<void>) => void;
33
40
  /** Hide event handler */
@@ -1,5 +1,6 @@
1
- import type { TSinchTooltipOrientation, TSinchTooltipType } from './types';
1
+ import type { TSinchTooltipOrientation, TSinchTooltipType, TSinchTooltipTextAlign } from './types';
2
2
  import type { TSinchPopOrientation } from '../pop/types';
3
3
  export declare const typeValues: readonly TSinchTooltipType[];
4
4
  export declare const orientationValues: readonly TSinchTooltipOrientation[];
5
+ export declare const textAlignValues: readonly TSinchTooltipTextAlign[];
5
6
  export declare const getPopOrientation: (orientation: TSinchTooltipOrientation) => TSinchPopOrientation;
package/tooltip/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export const typeValues = ['fast', 'slow'];
2
2
  export const orientationValues = ['top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right'];
3
+ export const textAlignValues = ['right', 'center', 'left'];
3
4
  export const getPopOrientation = orientation => {
4
5
  if (orientation === 'top') {
5
6
  return 'top-center';