@ledgerhq/lumen-utils-shared 0.1.0 → 0.1.2

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 (48) hide show
  1. package/dist/index.d.ts +3 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +164 -130
  4. package/dist/lib/a11y/getButtonA11yProps.d.ts +19 -0
  5. package/dist/lib/a11y/getButtonA11yProps.d.ts.map +1 -0
  6. package/dist/lib/a11y/index.d.ts +2 -0
  7. package/dist/lib/a11y/index.d.ts.map +1 -0
  8. package/dist/lib/components/amountDisplayHelpers/buildAriaLabel.d.ts.map +1 -1
  9. package/dist/lib/components/amountDisplayHelpers/types.d.ts +1 -1
  10. package/dist/lib/components/amountDisplayHelpers/types.d.ts.map +1 -1
  11. package/dist/lib/components/amountDisplayHelpers/useSplitText.d.ts.map +1 -1
  12. package/dist/lib/components/getStepperCalculations/getStepperCalculations.d.ts.map +1 -1
  13. package/dist/lib/context/createSafeContext.d.ts.map +1 -0
  14. package/dist/lib/context/disabledContext.d.ts +14 -0
  15. package/dist/lib/context/disabledContext.d.ts.map +1 -0
  16. package/dist/lib/context/index.d.ts +3 -0
  17. package/dist/lib/context/index.d.ts.map +1 -0
  18. package/dist/lib/getObjectPath/getObjectPath.d.ts.map +1 -1
  19. package/dist/lib/isTextChildren/isTextChildren.d.ts.map +1 -1
  20. package/dist/lib/shallowEqual/index.d.ts +2 -0
  21. package/dist/lib/shallowEqual/index.d.ts.map +1 -0
  22. package/dist/lib/shallowEqual/shallowEqual.d.ts +8 -0
  23. package/dist/lib/shallowEqual/shallowEqual.d.ts.map +1 -0
  24. package/package.json +1 -1
  25. package/src/index.ts +3 -1
  26. package/src/lib/a11y/getButtonA11yProps.test.ts +71 -0
  27. package/src/lib/a11y/getButtonA11yProps.ts +59 -0
  28. package/src/lib/a11y/index.ts +1 -0
  29. package/src/lib/components/amountDisplayHelpers/types.ts +1 -1
  30. package/src/lib/{createSafeContext → context}/createSafeContext.tsx +10 -9
  31. package/src/lib/context/disabledContext.test.tsx +81 -0
  32. package/src/lib/context/disabledContext.tsx +27 -0
  33. package/src/lib/{createSafeContext → context}/index.ts +1 -0
  34. package/src/lib/shallowEqual/index.ts +1 -0
  35. package/src/lib/shallowEqual/shallowEqual.test.ts +48 -0
  36. package/src/lib/shallowEqual/shallowEqual.ts +23 -0
  37. package/dist/lib/createSafeContext/createSafeContext.d.ts.map +0 -1
  38. package/dist/lib/createSafeContext/index.d.ts +0 -2
  39. package/dist/lib/createSafeContext/index.d.ts.map +0 -1
  40. package/dist/lib/getStepperCalculations/getStepperCalculations.d.ts +0 -61
  41. package/dist/lib/getStepperCalculations/getStepperCalculations.d.ts.map +0 -1
  42. package/dist/lib/getStepperCalculations/index.d.ts +0 -2
  43. package/dist/lib/getStepperCalculations/index.d.ts.map +0 -1
  44. package/src/lib/getStepperCalculations/getStepperCalculations.test.ts +0 -139
  45. package/src/lib/getStepperCalculations/getStepperCalculations.ts +0 -103
  46. package/src/lib/getStepperCalculations/index.ts +0 -5
  47. /package/dist/lib/{createSafeContext → context}/createSafeContext.d.ts +0 -0
  48. /package/src/lib/{createSafeContext → context}/createSafeContext.test.tsx +0 -0
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './lib/string/string';
2
2
  export * from './lib/inputFormatter';
3
- export * from './lib/createSafeContext';
3
+ export * from './lib/context';
4
4
  export * from './lib/cn';
5
5
  export * from './lib/isTextChildren';
6
6
  export * from './lib/useMergeRef';
@@ -8,4 +8,6 @@ export * from './lib/getObjectPath';
8
8
  export * from './lib/components';
9
9
  export * from './lib/throttle';
10
10
  export * from './lib/debounce';
11
+ export * from './lib/a11y';
12
+ export * from './lib/shallowEqual';
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,127 +1,142 @@
1
- import { jsx as k } from "react/jsx-runtime";
2
- import { createContext as W, useMemo as D, useContext as F } from "react";
1
+ import { jsx as v } from "react/jsx-runtime";
2
+ import { createContext as L, useRef as w, useContext as W, useMemo as I } from "react";
3
3
  import { clsx as _ } from "clsx";
4
- import { twMerge as j } from "tailwind-merge";
5
- function q(t) {
4
+ import { twMerge as F } from "tailwind-merge";
5
+ function J(t) {
6
6
  return t ? t.split(/[-_ ]+/).map((e) => e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()).join("") : "";
7
7
  }
8
- const N = 48, R = 17, w = 2;
9
- function G(t) {
8
+ const R = 48, B = 17, N = 2;
9
+ function Q(t) {
10
10
  const e = t.replace(/\D/g, "").length;
11
11
  return Math.max(
12
- R,
13
- N - e * w
12
+ B,
13
+ R - e * N
14
14
  );
15
15
  }
16
- function C(t, e = !0) {
16
+ function A(t, e = !0) {
17
17
  if (!t) return "";
18
- const o = t.includes("."), [c, r] = t.split("."), u = c.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
19
- return o && e ? r ? `${u}.${r}` : `${u}.` : u;
18
+ const i = t.includes("."), [r, c] = t.split("."), l = r.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
19
+ return i && e ? c ? `${l}.${c}` : `${l}.` : l;
20
20
  }
21
- function H(t, e = {}) {
21
+ function Y(t, e = {}) {
22
22
  const {
23
- allowDecimals: o = !0,
24
- thousandsSeparator: c = !0,
25
- maxIntegerLength: r = 9,
26
- maxDecimalLength: u = 9
27
- } = e, i = t.replace(",", ".").replace(/[^\d.]/g, "");
28
- let n = i;
29
- if (n = n.replace(/^0+(?=\d)/, ""), !o)
30
- return n = n.replace(/\D/g, ""), r > 0 && n.length > r && (n = n.slice(0, r)), c ? C(n) : n;
23
+ allowDecimals: i = !0,
24
+ thousandsSeparator: r = !0,
25
+ maxIntegerLength: c = 9,
26
+ maxDecimalLength: l = 9
27
+ } = e, o = t.replace(",", ".").replace(/[^\d.]/g, "");
28
+ let n = o;
29
+ if (n = n.replace(/^0+(?=\d)/, ""), !i)
30
+ return n = n.replace(/\D/g, ""), c > 0 && n.length > c && (n = n.slice(0, c)), r ? A(n) : n;
31
31
  n === "." && (n = "0.");
32
32
  const a = n.indexOf(".");
33
33
  if (a !== -1) {
34
- let s = n.slice(0, a), f = n.slice(a + 1).replace(/\./g, "");
35
- r > 0 && s.length > r && (s = s.slice(0, r)), f = f.slice(0, u), s === "" && (s = "0");
36
- const h = i.endsWith(".") || n.endsWith(".");
37
- n = f.length > 0 ? `${s}.${f}` : h ? `${s}.` : s;
34
+ let u = n.slice(0, a), f = n.slice(a + 1).replace(/\./g, "");
35
+ c > 0 && u.length > c && (u = u.slice(0, c)), f = f.slice(0, l), u === "" && (u = "0");
36
+ const h = o.endsWith(".") || n.endsWith(".");
37
+ n = f.length > 0 ? `${u}.${f}` : h ? `${u}.` : u;
38
38
  } else
39
- r > 0 && n.length > r && (n = n.slice(0, r));
40
- return c ? C(n) : n;
39
+ c > 0 && n.length > c && (n = n.slice(0, c));
40
+ return r ? A(n) : n;
41
41
  }
42
- function J(t, e) {
43
- const o = W(e), c = ({ children: u, value: i }) => {
44
- const n = D(
45
- () => i,
46
- Object.values(i ?? {})
47
- );
48
- return /* @__PURE__ */ k(o.Provider, { value: n, children: u });
42
+ function q(t, e) {
43
+ if (Object.is(t, e)) return !0;
44
+ const i = t, r = e, c = Object.keys(i), l = Object.keys(r);
45
+ return c.length !== l.length ? !1 : c.every(
46
+ (o) => Object.prototype.hasOwnProperty.call(r, o) && Object.is(i[o], r[o])
47
+ );
48
+ }
49
+ function z(t, e) {
50
+ const i = L(e), r = ({ children: l, value: o }) => {
51
+ const n = w(o);
52
+ return q(n.current, o) || (n.current = o), /* @__PURE__ */ v(i.Provider, { value: n.current, children: l });
49
53
  };
50
- c.displayName = t + "Provider";
51
- function r({
52
- consumerName: u,
53
- contextRequired: i
54
+ r.displayName = t + "Provider";
55
+ function c({
56
+ consumerName: l,
57
+ contextRequired: o
54
58
  }) {
55
- const n = F(o);
59
+ const n = W(i);
56
60
  if (n)
57
61
  return n;
58
- if (i)
62
+ if (o)
59
63
  throw new Error(
60
- `${u} must be used within ${t}`
64
+ `${l} must be used within ${t}`
61
65
  );
62
66
  return e || {};
63
67
  }
64
- return [c, r];
68
+ return [r, c];
65
69
  }
66
- function K(...t) {
67
- return j(_(t));
70
+ const [tt, K] = z("Disabled", { disabled: !1 }), et = ({
71
+ consumerName: t,
72
+ contextRequired: e,
73
+ mergeWith: i
74
+ }) => {
75
+ const r = K({
76
+ consumerName: t,
77
+ contextRequired: e ?? !1
78
+ });
79
+ return !!(i?.disabled || r.disabled);
80
+ };
81
+ function nt(...t) {
82
+ return F(_(t));
68
83
  }
69
- const S = (t) => typeof t == "string" || typeof t == "number", Q = (t) => Array.isArray(t) ? t.every(S) : S(t);
70
- function I(t, e) {
84
+ const C = (t) => typeof t == "string" || typeof t == "number", rt = (t) => Array.isArray(t) ? t.every(C) : C(t);
85
+ function M(t, e) {
71
86
  if (typeof t == "function")
72
87
  return t(e);
73
88
  typeof t == "object" && t !== null && "current" in t && (t.current = e);
74
89
  }
75
- function z(...t) {
90
+ function Z(...t) {
76
91
  const e = /* @__PURE__ */ new Map();
77
- return (o) => {
78
- if (o === null) {
79
- t.forEach((c) => {
80
- const r = e.get(c);
81
- typeof r == "function" && r(), I(c, null);
92
+ return (i) => {
93
+ if (i === null) {
94
+ t.forEach((r) => {
95
+ const c = e.get(r);
96
+ typeof c == "function" && c(), M(r, null);
82
97
  }), e.clear();
83
98
  return;
84
99
  }
85
- t.forEach((c) => {
86
- const r = I(c, o);
87
- typeof r == "function" && e.set(c, r);
100
+ t.forEach((r) => {
101
+ const c = M(r, i);
102
+ typeof c == "function" && e.set(r, c);
88
103
  });
89
104
  };
90
105
  }
91
- function Y(...t) {
92
- return D(() => z(...t), t);
106
+ function ot(...t) {
107
+ return I(() => Z(...t), t);
93
108
  }
94
- const tt = (t, e) => {
95
- let o = t;
96
- for (const c of e) {
97
- if (o == null)
109
+ const it = (t, e) => {
110
+ let i = t;
111
+ for (const r of e) {
112
+ if (i == null)
98
113
  return;
99
- o = o[c];
114
+ i = i[r];
100
115
  }
101
- return o;
102
- }, et = ({
116
+ return i;
117
+ }, ct = ({
103
118
  currentStep: t,
104
119
  totalSteps: e,
105
- size: o,
106
- label: c,
107
- strokeWidth: r = 4,
108
- arcPercentage: u = 0.75
120
+ size: i,
121
+ label: r,
122
+ strokeWidth: c = 4,
123
+ arcPercentage: l = 0.75
109
124
  }) => {
110
- const i = Math.min(Math.max(t, 0), e), n = c ?? `${i}/${e}`, a = e <= 0 ? 0 : i / e, s = (o - r) / 2, f = o / 2, h = o / 2, m = 2 * Math.PI * s, g = m * u, T = g * (1 - a), p = i <= 0, A = `${g} ${m}`, $ = p ? g - 2 : T;
125
+ const o = Math.min(Math.max(t, 0), e), n = r ?? `${o}/${e}`, a = e <= 0 ? 0 : o / e, u = (i - c) / 2, f = i / 2, h = i / 2, d = 2 * Math.PI * u, g = d * l, b = g * (1 - a), p = o <= 0, $ = `${g} ${d}`, P = p ? g - 2 : b;
111
126
  return {
112
127
  displayLabel: n,
113
128
  progress: a,
114
- r: s,
129
+ r: u,
115
130
  cx: f,
116
131
  cy: h,
117
- circumference: m,
132
+ circumference: d,
118
133
  trackArcLength: g,
119
- trackDashArray: `${g} ${m}`,
120
- progressDashArray: A,
121
- progressDashOffset: $,
134
+ trackDashArray: `${g} ${d}`,
135
+ progressDashArray: $,
136
+ progressDashOffset: P,
122
137
  showMinimalDot: p
123
138
  };
124
- }, nt = (t) => D(
139
+ }, st = (t) => I(
125
140
  () => ({
126
141
  integerPart: Array.from(t.integerPart, (e) => ({
127
142
  value: e,
@@ -133,71 +148,90 @@ const tt = (t, e) => {
133
148
  })) : []
134
149
  }),
135
150
  [t.integerPart, t.decimalPart]
136
- ), rt = (t, e, o) => {
137
- if (e) return o;
138
- const c = t.decimalPart ? `${t.decimalSeparator}${t.decimalPart}` : "", r = `${t.integerPart}${c}`;
139
- return t.currencyPosition === "end" ? `${r} ${t.currencyText}` : `${t.currencyText} ${r}`;
151
+ ), lt = (t, e, i) => {
152
+ if (e) return i;
153
+ const r = t.decimalPart ? `${t.decimalSeparator}${t.decimalPart}` : "", c = `${t.integerPart}${r}`;
154
+ return t.currencyPosition === "end" ? `${c} ${t.currencyText}` : `${t.currencyText} ${c}`;
140
155
  };
141
- function V(t, e, o = {}) {
142
- const { leading: c = !1, trailing: r = !0, maxWait: u } = o;
143
- let i = null, n = null, a = null, s = 0, f = null, h = null, m;
144
- const g = u !== void 0, T = g ? Math.max(u, e) : 0, p = (l) => {
145
- s = l;
146
- const d = f, y = h;
147
- return f = null, h = null, m = t.apply(y, d), m;
148
- }, A = (l) => {
149
- const d = a ? l - a : 0;
150
- return e - d;
151
- }, $ = (l) => {
152
- const d = a ? l - a : e, y = l - s;
153
- return a === null || d >= e || d < 0 || g && y >= T;
154
- }, M = (l) => (i = null, r && f ? p(l) : (f = null, h = null, m)), x = () => {
155
- const l = Date.now();
156
- if ($(l)) {
157
- M(l);
156
+ function U(t, e, i = {}) {
157
+ const { leading: r = !1, trailing: c = !0, maxWait: l } = i;
158
+ let o = null, n = null, a = null, u = 0, f = null, h = null, d;
159
+ const g = l !== void 0, b = g ? Math.max(l, e) : 0, p = (s) => {
160
+ u = s;
161
+ const m = f, x = h;
162
+ return f = null, h = null, d = t.apply(x, m), d;
163
+ }, $ = (s) => {
164
+ const m = a ? s - a : 0;
165
+ return e - m;
166
+ }, P = (s) => {
167
+ const m = a ? s - a : e, x = s - u;
168
+ return a === null || m >= e || m < 0 || g && x >= b;
169
+ }, D = (s) => (o = null, c && f ? p(s) : (f = null, h = null, d)), y = () => {
170
+ const s = Date.now();
171
+ if (P(s)) {
172
+ D(s);
158
173
  return;
159
174
  }
160
- i = setTimeout(x, A(l));
161
- }, b = () => {
162
- const l = Date.now();
163
- n = null, f && (p(l), i !== null && (clearTimeout(i), i = setTimeout(x, e)));
164
- }, v = (l) => (s = l, i = setTimeout(x, e), g && (n = setTimeout(b, T)), c ? p(l) : m), E = () => {
165
- i !== null && clearTimeout(i), n !== null && clearTimeout(n), s = 0, f = null, h = null, a = null, i = null, n = null;
166
- }, L = () => i === null && n === null ? m : M(Date.now()), O = () => i !== null || n !== null, P = function(...l) {
167
- const d = Date.now(), y = $(d);
168
- if (f = l, h = this, a = d, y) {
169
- if (i === null)
170
- return v(d);
175
+ o = setTimeout(y, $(s));
176
+ }, O = () => {
177
+ const s = Date.now();
178
+ n = null, f && (p(s), o !== null && (clearTimeout(o), o = setTimeout(y, e)));
179
+ }, S = (s) => (u = s, o = setTimeout(y, e), g && (n = setTimeout(O, b)), r ? p(s) : d), E = () => {
180
+ o !== null && clearTimeout(o), n !== null && clearTimeout(n), u = 0, f = null, h = null, a = null, o = null, n = null;
181
+ }, j = () => o === null && n === null ? d : D(Date.now()), k = () => o !== null || n !== null, T = function(...s) {
182
+ const m = Date.now(), x = P(m);
183
+ if (f = s, h = this, a = m, x) {
184
+ if (o === null)
185
+ return S(m);
171
186
  if (g)
172
- return clearTimeout(i), i = setTimeout(x, e), p(d);
187
+ return clearTimeout(o), o = setTimeout(y, e), p(m);
173
188
  }
174
- return i === null && (i = setTimeout(x, e)), m;
189
+ return o === null && (o = setTimeout(y, e)), d;
175
190
  };
176
- return P.cancel = E, P.flush = L, P.pending = O, P;
191
+ return T.cancel = E, T.flush = j, T.pending = k, T;
177
192
  }
178
- function it(t, e, o = {}) {
179
- const { leading: c = !0, trailing: r = !0 } = o;
180
- return V(t, e, {
181
- leading: c,
182
- trailing: r,
193
+ function ut(t, e, i = {}) {
194
+ const { leading: r = !0, trailing: c = !0 } = i;
195
+ return U(t, e, {
196
+ leading: r,
197
+ trailing: c,
183
198
  maxWait: e
184
199
  });
185
200
  }
201
+ const at = ({
202
+ onClick: t,
203
+ disabled: e
204
+ }) => t ? e ? {
205
+ role: "button",
206
+ tabIndex: -1,
207
+ "aria-disabled": !0
208
+ } : {
209
+ role: "button",
210
+ tabIndex: 0,
211
+ onKeyDown: (r) => {
212
+ (r.key === "Enter" || r.key === " ") && (r.preventDefault(), t?.(r));
213
+ },
214
+ onClick: t
215
+ } : void 0;
186
216
  export {
187
- I as assignRef,
188
- rt as buildAriaLabel,
189
- K as cn,
190
- J as createSafeContext,
191
- V as debounce,
192
- C as formatThousands,
193
- G as getFontSize,
194
- tt as getObjectPath,
195
- et as getStepperCalculations,
196
- Q as isTextChildren,
197
- z as mergeRefs,
198
- H as textFormatter,
199
- it as throttle,
200
- q as toPascalCase,
201
- Y as useMergedRef,
202
- nt as useSplitText
217
+ tt as DisabledProvider,
218
+ M as assignRef,
219
+ lt as buildAriaLabel,
220
+ nt as cn,
221
+ z as createSafeContext,
222
+ U as debounce,
223
+ A as formatThousands,
224
+ at as getButtonA11yProps,
225
+ Q as getFontSize,
226
+ it as getObjectPath,
227
+ ct as getStepperCalculations,
228
+ rt as isTextChildren,
229
+ Z as mergeRefs,
230
+ q as shallowEqual,
231
+ Y as textFormatter,
232
+ ut as throttle,
233
+ J as toPascalCase,
234
+ et as useDisabledContext,
235
+ ot as useMergedRef,
236
+ st as useSplitText
203
237
  };
@@ -0,0 +1,19 @@
1
+ import { AriaAttributes, MouseEventHandler, HTMLAttributes } from 'react';
2
+ type ButtonA11yOptions<T extends HTMLElement = HTMLElement> = {
3
+ onClick?: MouseEventHandler<T>;
4
+ disabled?: boolean;
5
+ };
6
+ type ButtonA11yProps<T extends HTMLElement = HTMLElement> = Pick<HTMLAttributes<T>, 'role' | 'tabIndex' | 'onKeyDown' | 'onClick'> & Pick<AriaAttributes, 'aria-disabled'>;
7
+ /**
8
+ * Returns props to make a non-button element (e.g. `<div>`) behave like a
9
+ * button: `role="button"`, `tabIndex`, keyboard activation on Enter/Space,
10
+ * and the original `onClick` passthrough.
11
+ *
12
+ * Returns undefined if `onClick` is not provided
13
+ *
14
+ * When `disabled` is `true`, the element gets `aria-disabled`, is removed
15
+ * from the tab order, and click/keyboard handlers are omitted.
16
+ */
17
+ export declare const getButtonA11yProps: <T extends HTMLElement = HTMLElement>({ onClick, disabled, }: ButtonA11yOptions<T>) => ButtonA11yProps<T> | undefined;
18
+ export {};
19
+ //# sourceMappingURL=getButtonA11yProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getButtonA11yProps.d.ts","sourceRoot":"","sources":["../../../src/lib/a11y/getButtonA11yProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,iBAAiB,EAEjB,cAAc,EACf,MAAM,OAAO,CAAC;AAEf,KAAK,iBAAiB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI;IAC5D,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,IAAI,CAC9D,cAAc,CAAC,CAAC,CAAC,EACjB,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAC9C,GACC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAExC;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,wBAGrE,iBAAiB,CAAC,CAAC,CAAC,KAAG,eAAe,CAAC,CAAC,CAAC,GAAG,SA0B9C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { getButtonA11yProps } from './getButtonA11yProps';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/a11y/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"buildAriaLabel.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/buildAriaLabel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,eAAO,MAAM,cAAc,UAClB,cAAc,UACb,OAAO,eACF,MAAM,KAClB,MAaF,CAAC"}
1
+ {"version":3,"file":"buildAriaLabel.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/buildAriaLabel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,eAAO,MAAM,cAAc,GACzB,OAAO,cAAc,EACrB,QAAQ,OAAO,EACf,aAAa,MAAM,KAClB,MAaF,CAAC"}
@@ -25,6 +25,6 @@ export type FormattedValue = {
25
25
  * @optional
26
26
  * @default 'start'
27
27
  */
28
- currencyPosition?: 'start' | 'end';
28
+ currencyPosition: 'start' | 'end';
29
29
  };
30
30
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,GAAG,WAAW,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,gBAAgB,EAAE,GAAG,GAAG,GAAG,CAAC;IAC5B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CACpC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,GAAG,WAAW,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,gBAAgB,EAAE,GAAG,GAAG,GAAG,CAAC;IAC5B;;;;OAIG;IACH,gBAAgB,EAAE,OAAO,GAAG,KAAK,CAAC;CACnC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSplitText.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/useSplitText.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,YAAY,UAChB,cAAc,KACpB;IACD,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,WAAW,EAAE,SAAS,EAAE,CAAC;CAiB1B,CAAC"}
1
+ {"version":3,"file":"useSplitText.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/useSplitText.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,YAAY,GACvB,OAAO,cAAc,KACpB;IACD,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,WAAW,EAAE,SAAS,EAAE,CAAC;CAiB1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getStepperCalculations.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/getStepperCalculations/getStepperCalculations.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACrC,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,CAAC,EAAE,MAAM,CAAC;IACV,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yDAAyD;IACzD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,2DAA2D;IAC3D,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,sBAAsB,0EAOhC,wBAAwB,KAAG,yBAmC7B,CAAC"}
1
+ {"version":3,"file":"getStepperCalculations.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/getStepperCalculations/getStepperCalculations.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACrC,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,CAAC,EAAE,MAAM,CAAC;IACV,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yDAAyD;IACzD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,2DAA2D;IAC3D,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,sBAAsB,GAAI,uEAOpC,wBAAwB,KAAG,yBAmC7B,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSafeContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/createSafeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAE,SAAS,EAAsB,MAAM,OAAO,CAAC;AAGzE,wBAAgB,iBAAiB,CAAC,YAAY,SAAS,MAAM,EAC3D,iBAAiB,EAAE,MAAM,EACzB,cAAc,CAAC,EAAE,YAAY;cAKjB,SAAS;WACZ,YAAY;KAaG,eAAe,SAAS,OAAO,gDAGpD;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,eAAe,CAAC;CAClC,KAAG,eAAe,SAAS,IAAI,GAAG,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,EAgBxE"}
@@ -0,0 +1,14 @@
1
+ type DisabledContextValue = {
2
+ disabled?: boolean;
3
+ };
4
+ declare const DisabledProvider: import('react').FC<{
5
+ children: import('react').ReactNode;
6
+ value: DisabledContextValue;
7
+ }>;
8
+ declare const useDisabledContext: ({ consumerName, contextRequired, mergeWith, }: {
9
+ consumerName: string;
10
+ contextRequired?: boolean;
11
+ mergeWith?: DisabledContextValue;
12
+ }) => boolean;
13
+ export { DisabledProvider, useDisabledContext };
14
+ //# sourceMappingURL=disabledContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disabledContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/disabledContext.tsx"],"names":[],"mappings":"AAEA,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,QAAA,MAAO,gBAAgB;;;EACmD,CAAC;AAE3E,QAAA,MAAM,kBAAkB,GAAI,+CAIzB;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC,YAOA,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './createSafeContext';
2
+ export * from './disabledContext';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getObjectPath.d.ts","sourceRoot":"","sources":["../../../src/lib/getObjectPath/getObjectPath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,iBACxB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QACtB,MAAM,EAAE,KACb,CAAC,GAAG,SAWN,CAAC"}
1
+ {"version":3,"file":"getObjectPath.d.ts","sourceRoot":"","sources":["../../../src/lib/getObjectPath/getObjectPath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,GAAG,OAAO,EACvC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,MAAM,MAAM,EAAE,KACb,CAAC,GAAG,SAWN,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"isTextChildren.d.ts","sourceRoot":"","sources":["../../../src/lib/isTextChildren/isTextChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,eAAO,MAAM,cAAc,YAAa,SAAS,YAGhD,CAAC"}
1
+ {"version":3,"file":"isTextChildren.d.ts","sourceRoot":"","sources":["../../../src/lib/isTextChildren/isTextChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,YAGhD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './shallowEqual';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/shallowEqual/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Performs a shallow equality comparison between two objects.
3
+ * Returns true if both objects have the same keys and each value
4
+ * is strictly equal (using Object.is) to the corresponding value
5
+ * in the other object.
6
+ */
7
+ export declare function shallowEqual<T extends object>(a: T, b: T): boolean;
8
+ //# sourceMappingURL=shallowEqual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shallowEqual.d.ts","sourceRoot":"","sources":["../../../src/lib/shallowEqual/shallowEqual.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAgBlE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/lumen-utils-shared",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './lib/string/string';
2
2
  export * from './lib/inputFormatter';
3
- export * from './lib/createSafeContext';
3
+ export * from './lib/context';
4
4
  export * from './lib/cn';
5
5
  export * from './lib/isTextChildren';
6
6
  export * from './lib/useMergeRef';
@@ -8,3 +8,5 @@ export * from './lib/getObjectPath';
8
8
  export * from './lib/components';
9
9
  export * from './lib/throttle';
10
10
  export * from './lib/debounce';
11
+ export * from './lib/a11y';
12
+ export * from './lib/shallowEqual';
@@ -0,0 +1,71 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { getButtonA11yProps } from './getButtonA11yProps';
3
+
4
+ describe('getButtonA11yProps', () => {
5
+ it('returns role="button" and tabIndex=0 with an onClick handler', () => {
6
+ const onClick = vi.fn();
7
+ const result = getButtonA11yProps({ onClick });
8
+
9
+ expect(result).toMatchObject({
10
+ role: 'button',
11
+ tabIndex: 0,
12
+ onClick,
13
+ });
14
+ expect(result?.onKeyDown).toBeTypeOf('function');
15
+ });
16
+
17
+ it('returns disabled a11y props when disabled is true', () => {
18
+ const onClick = vi.fn();
19
+ const result = getButtonA11yProps({ onClick, disabled: true });
20
+
21
+ expect(result).toEqual({
22
+ role: 'button',
23
+ tabIndex: -1,
24
+ 'aria-disabled': true,
25
+ });
26
+ });
27
+
28
+ it('omits click and keyboard handlers when disabled', () => {
29
+ const result = getButtonA11yProps({ onClick: vi.fn(), disabled: true });
30
+
31
+ expect(result).not.toHaveProperty('onClick');
32
+ expect(result).not.toHaveProperty('onKeyDown');
33
+ });
34
+
35
+ it('calls onClick on Enter key', () => {
36
+ const onClick = vi.fn();
37
+ const result = getButtonA11yProps({ onClick });
38
+ const event = { key: 'Enter', preventDefault: vi.fn() };
39
+
40
+ result?.onKeyDown?.(event as any);
41
+
42
+ expect(event.preventDefault).toHaveBeenCalled();
43
+ expect(onClick).toHaveBeenCalledTimes(1);
44
+ });
45
+
46
+ it('calls onClick on Space key', () => {
47
+ const onClick = vi.fn();
48
+ const result = getButtonA11yProps({ onClick });
49
+ const event = { key: ' ', preventDefault: vi.fn() };
50
+
51
+ result?.onKeyDown?.(event as any);
52
+
53
+ expect(event.preventDefault).toHaveBeenCalled();
54
+ expect(onClick).toHaveBeenCalledTimes(1);
55
+ });
56
+
57
+ it('does not call onClick on other keys', () => {
58
+ const onClick = vi.fn();
59
+ const result = getButtonA11yProps({ onClick });
60
+ const event = { key: 'Tab', preventDefault: vi.fn() };
61
+
62
+ result?.onKeyDown?.(event as any);
63
+
64
+ expect(event.preventDefault).not.toHaveBeenCalled();
65
+ expect(onClick).not.toHaveBeenCalled();
66
+ });
67
+
68
+ it('returns undefined when onClick is not provided', () => {
69
+ expect(getButtonA11yProps({})).toBeUndefined();
70
+ });
71
+ });