@nectary/components 5.39.0 → 5.39.1

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/bundle.js CHANGED
@@ -49,6 +49,9 @@ const DEFAULT_INTEGER_OPTIONS = {
49
49
  itemSpaceBetween: 0,
50
50
  defaultValue: null
51
51
  };
52
+ const DEFAULT_FLOAT_OPTIONS = {
53
+ fractionDigits: 2
54
+ };
52
55
  const applyRange = (value, { min, max }) => {
53
56
  let result = value;
54
57
  if (min != null) {
@@ -59,6 +62,21 @@ const applyRange = (value, { min, max }) => {
59
62
  }
60
63
  return result;
61
64
  };
65
+ const attrValueToFloat = (value, options) => {
66
+ const opts = {
67
+ ...DEFAULT_FLOAT_OPTIONS,
68
+ ...options
69
+ };
70
+ const float = Number.parseFloat(String(value));
71
+ if (Number.isNaN(float)) {
72
+ return null;
73
+ }
74
+ if (opts.min !== void 0 || opts.max !== void 0) {
75
+ const rangedFloat = applyRange(float, { min: opts.min, max: opts.max });
76
+ return rangedFloat.toFixed(opts.fractionDigits);
77
+ }
78
+ return float.toFixed(opts.fractionDigits);
79
+ };
62
80
  const attrValueToInteger = (value, options = DEFAULT_INTEGER_OPTIONS) => {
63
81
  const { defaultValue = null, itemSizeMultiplier = 1, itemSpaceBetween = 0, addExtraSpace = false } = options;
64
82
  let intValue = defaultValue;
@@ -11785,8 +11803,9 @@ class Progress extends NectaryElement {
11785
11803
  attributeChangedCallback(name, oldVal, newVal) {
11786
11804
  switch (name) {
11787
11805
  case "value": {
11788
- const int = attrValueToInteger(newVal, { min: 0, max: 100 }) ?? 0;
11789
- this.#$bar.style.width = `${int}%`;
11806
+ const float = attrValueToFloat(newVal, { min: 0, max: 100, fractionDigits: 2 }) ?? "0";
11807
+ const int = parseInt(float);
11808
+ this.#$bar.style.width = `${float}%`;
11790
11809
  this.#$text.textContent = Intl.NumberFormat(navigator.language, { style: "percent" }).format(int / 100);
11791
11810
  this.setAttribute("valuenow", int !== null ? String(int) : "0");
11792
11811
  this.setAttribute("aria-valuenow", int !== null ? String(int) : "0");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.39.0",
3
+ "version": "5.39.1",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
package/progress/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "../text/index.js";
2
- import { isAttrEqual, updateBooleanAttribute, isAttrTrue, attrValueToInteger, getIntegerAttribute, updateAttribute, getBooleanAttribute } from "../utils/dom.js";
2
+ import { isAttrEqual, updateBooleanAttribute, isAttrTrue, attrValueToFloat, getIntegerAttribute, updateAttribute, getBooleanAttribute } from "../utils/dom.js";
3
3
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
4
4
  const templateHTML = '<style>:host{display:block}#wrapper{display:flex;align-items:center;height:24px}#bar,#progress{height:8px;border-radius:4px}#progress{background-color:var(--sinch-comp-progress-color-default-background-initial);flex:1;min-width:0}#bar{background-color:var(--sinch-comp-progress-color-default-bar-initial);width:0}#text{display:none;width:46px;--sinch-global-color-text:var(--sinch-comp-progress-color-default-text-initial)}:host([detailed]) #text{display:block}</style><div id="wrapper"><sinch-text id="text" type="m"></sinch-text><div id="progress"><div id="bar"></div></div></div>';
5
5
  const template = document.createElement("template");
@@ -23,8 +23,9 @@ class Progress extends NectaryElement {
23
23
  attributeChangedCallback(name, oldVal, newVal) {
24
24
  switch (name) {
25
25
  case "value": {
26
- const int = attrValueToInteger(newVal, { min: 0, max: 100 }) ?? 0;
27
- this.#$bar.style.width = `${int}%`;
26
+ const float = attrValueToFloat(newVal, { min: 0, max: 100, fractionDigits: 2 }) ?? "0";
27
+ const int = parseInt(float);
28
+ this.#$bar.style.width = `${float}%`;
28
29
  this.#$text.textContent = Intl.NumberFormat(navigator.language, { style: "percent" }).format(int / 100);
29
30
  this.setAttribute("valuenow", int !== null ? String(int) : "0");
30
31
  this.setAttribute("aria-valuenow", int !== null ? String(int) : "0");
package/utils/dom.d.ts CHANGED
@@ -12,13 +12,20 @@ export declare function getLiteralAttribute<T extends readonly string[]>($elemen
12
12
  export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: T[number]): T[number];
13
13
  export declare const clampNumber: (value: number, min: number, max: number) => number;
14
14
  type IntegerOptions = {
15
- min?: number;
16
- max?: number;
15
+ min?: number | undefined;
16
+ max?: number | undefined;
17
17
  defaultValue?: number | null;
18
18
  itemSizeMultiplier?: number;
19
19
  itemSpaceBetween?: number;
20
20
  addExtraSpace?: boolean;
21
21
  };
22
+ type FloatOptions = {
23
+ min?: number | undefined;
24
+ max?: number | undefined;
25
+ fractionDigits?: number;
26
+ };
27
+ export declare const applyRange: (value: number, { min, max }: IntegerOptions) => number;
28
+ export declare const attrValueToFloat: (value: string | null, options: FloatOptions) => string | null;
22
29
  export declare const attrValueToInteger: (value: string | null, options?: IntegerOptions) => number | null;
23
30
  export declare const attrValueToPixels: (value: string | null, options?: IntegerOptions) => string;
24
31
  export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, options?: IntegerOptions) => void;
package/utils/dom.js CHANGED
@@ -52,6 +52,9 @@ const DEFAULT_INTEGER_OPTIONS = {
52
52
  itemSpaceBetween: 0,
53
53
  defaultValue: null
54
54
  };
55
+ const DEFAULT_FLOAT_OPTIONS = {
56
+ fractionDigits: 2
57
+ };
55
58
  const applyRange = (value, { min, max }) => {
56
59
  let result = value;
57
60
  if (min != null) {
@@ -62,6 +65,21 @@ const applyRange = (value, { min, max }) => {
62
65
  }
63
66
  return result;
64
67
  };
68
+ const attrValueToFloat = (value, options) => {
69
+ const opts = {
70
+ ...DEFAULT_FLOAT_OPTIONS,
71
+ ...options
72
+ };
73
+ const float = Number.parseFloat(String(value));
74
+ if (Number.isNaN(float)) {
75
+ return null;
76
+ }
77
+ if (opts.min !== void 0 || opts.max !== void 0) {
78
+ const rangedFloat = applyRange(float, { min: opts.min, max: opts.max });
79
+ return rangedFloat.toFixed(opts.fractionDigits);
80
+ }
81
+ return float.toFixed(opts.fractionDigits);
82
+ };
65
83
  const attrValueToInteger = (value, options = DEFAULT_INTEGER_OPTIONS) => {
66
84
  const { defaultValue = null, itemSizeMultiplier = 1, itemSpaceBetween = 0, addExtraSpace = false } = options;
67
85
  let intValue = defaultValue;
@@ -220,6 +238,8 @@ const getTransformedAncestor = (node) => {
220
238
  return null;
221
239
  };
222
240
  export {
241
+ applyRange,
242
+ attrValueToFloat,
223
243
  attrValueToInteger,
224
244
  attrValueToPixels,
225
245
  clampNumber,
package/utils/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Context, subscribeContext } from "./context.js";
2
2
  import { CSV_DELIMITER, getFirstCsvValue, packCsv, unpackCsv, updateCsv } from "./csv.js";
3
- import { attrValueToInteger, attrValueToPixels, clampNumber, cloneNode, composedContains, createScopedElement, getAttribute, getBooleanAttribute, getCssVar, getCssVars, getDeepActiveElement, getIntegerAttribute, getLiteralAttribute, getScrollableParents, getTransformedAncestor, hasClass, isAttrEqual, isAttrTrue, isLiteralValue, isTransformedElement, setClass, shouldReduceMotion, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute, updateIntegerAttribute, updateLiteralAttribute } from "./dom.js";
3
+ import { applyRange, attrValueToFloat, attrValueToInteger, attrValueToPixels, clampNumber, cloneNode, composedContains, createScopedElement, getAttribute, getBooleanAttribute, getCssVar, getCssVars, getDeepActiveElement, getIntegerAttribute, getLiteralAttribute, getScrollableParents, getTransformedAncestor, hasClass, isAttrEqual, isAttrTrue, isLiteralValue, isTransformedElement, setClass, shouldReduceMotion, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute, updateIntegerAttribute, updateLiteralAttribute } from "./dom.js";
4
4
  import { NectaryElement, defineCustomElement, pascalToKebabCase, registerComponent, resetNectaryRegistry, setNectaryRegistry } from "./element.js";
5
5
  import { getRect, getTargetRect, rectOverlap } from "./rect.js";
6
6
  import { getFirstFocusableElement, getFirstSlotElement, isElementFocused } from "./slot.js";
@@ -15,6 +15,8 @@ export {
15
15
  CSV_DELIMITER,
16
16
  Context,
17
17
  NectaryElement,
18
+ applyRange,
19
+ attrValueToFloat,
18
20
  attrValueToInteger,
19
21
  attrValueToPixels,
20
22
  clampNumber,