@ledgerhq/lumen-utils-shared 0.1.3 → 0.1.5

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 (42) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +145 -132
  4. package/dist/lib/cn.d.ts.map +1 -1
  5. package/dist/lib/components/amountDisplayHelpers/buildAriaLabel.d.ts.map +1 -1
  6. package/dist/lib/components/amountDisplayHelpers/useSplitText.d.ts.map +1 -1
  7. package/dist/lib/context/createSafeContext.d.ts.map +1 -1
  8. package/dist/lib/density/density.d.ts +2 -0
  9. package/dist/lib/density/density.d.ts.map +1 -0
  10. package/dist/lib/density/index.d.ts +2 -0
  11. package/dist/lib/density/index.d.ts.map +1 -0
  12. package/dist/lib/inputFormatter/fontSizeFormatter.d.ts +20 -2
  13. package/dist/lib/inputFormatter/fontSizeFormatter.d.ts.map +1 -1
  14. package/dist/lib/inputFormatter/index.d.ts +1 -1
  15. package/dist/lib/inputFormatter/index.d.ts.map +1 -1
  16. package/dist/lib/isTextChildren/isTextChildren.d.ts.map +1 -1
  17. package/dist/lib/resolveBaseInputPlaceholder/index.d.ts +2 -0
  18. package/dist/lib/resolveBaseInputPlaceholder/index.d.ts.map +1 -0
  19. package/dist/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.d.ts +20 -0
  20. package/dist/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.d.ts.map +1 -0
  21. package/dist/lib/throttle/throttle.d.ts.map +1 -1
  22. package/dist/lib/useMergeRef/useMergeRef.d.ts +1 -1
  23. package/dist/lib/useMergeRef/useMergeRef.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/src/index.ts +2 -0
  26. package/src/lib/cn.ts +2 -1
  27. package/src/lib/components/amountDisplayHelpers/buildAriaLabel.ts +1 -1
  28. package/src/lib/components/amountDisplayHelpers/useSplitText.test.ts +1 -1
  29. package/src/lib/components/amountDisplayHelpers/useSplitText.ts +1 -1
  30. package/src/lib/context/createSafeContext.tsx +2 -1
  31. package/src/lib/density/density.ts +1 -0
  32. package/src/lib/density/index.ts +1 -0
  33. package/src/lib/inputFormatter/fontSizeFormatter.test.ts +46 -0
  34. package/src/lib/inputFormatter/fontSizeFormatter.ts +15 -9
  35. package/src/lib/inputFormatter/index.ts +1 -1
  36. package/src/lib/isTextChildren/isTextChildren.test.ts +2 -1
  37. package/src/lib/isTextChildren/isTextChildren.ts +1 -1
  38. package/src/lib/resolveBaseInputPlaceholder/index.ts +1 -0
  39. package/src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.test.ts +61 -0
  40. package/src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.ts +44 -0
  41. package/src/lib/throttle/throttle.ts +2 -1
  42. package/src/lib/useMergeRef/useMergeRef.ts +2 -1
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './lib/density';
1
2
  export * from './lib/string/string';
2
3
  export * from './lib/inputFormatter';
3
4
  export * from './lib/context';
@@ -10,4 +11,5 @@ export * from './lib/throttle';
10
11
  export * from './lib/debounce';
11
12
  export * from './lib/a11y';
12
13
  export * from './lib/shallowEqual';
14
+ export * from './lib/resolveBaseInputPlaceholder';
13
15
  //# 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,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,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;AACnC,cAAc,mCAAmC,CAAC"}
package/dist/index.js CHANGED
@@ -1,138 +1,138 @@
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
- import { clsx as _ } from "clsx";
4
- import { twMerge as F } from "tailwind-merge";
5
- function J(t) {
1
+ import { jsx as k } from "react/jsx-runtime";
2
+ import { createContext as W, useRef as F, useContext as w, useMemo as I } from "react";
3
+ import { clsx as B } from "clsx";
4
+ import { twMerge as R } from "tailwind-merge";
5
+ function G(t) {
6
6
  return t ? t.split(/[-_ ]+/).map((e) => e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()).join("") : "";
7
7
  }
8
- const R = 48, B = 17, N = 2;
9
- function Q(t) {
10
- const e = t.replace(/\D/g, "").length;
11
- return Math.max(
12
- B,
13
- R - e * N
14
- );
8
+ const _ = {
9
+ md: { max: 48, min: 17, scale: 2, startAt: 0 },
10
+ sm: { max: 28, min: 12, scale: 2, startAt: 6 }
11
+ };
12
+ function J(t, e = "md") {
13
+ const { max: r, min: o, scale: s, startAt: l } = _[e], i = t.replace(/\D/g, "").length;
14
+ return Math.max(o, r - Math.max(0, i - l) * s);
15
15
  }
16
16
  function A(t, e = !0) {
17
17
  if (!t) return "";
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;
18
+ const r = t.includes("."), [o, s] = t.split("."), l = o.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
19
+ return r && e ? s ? `${l}.${s}` : `${l}.` : l;
20
20
  }
21
- function Y(t, e = {}) {
21
+ function Q(t, e = {}) {
22
22
  const {
23
- allowDecimals: i = !0,
24
- thousandsSeparator: r = !0,
25
- maxIntegerLength: c = 9,
23
+ allowDecimals: r = !0,
24
+ thousandsSeparator: o = !0,
25
+ maxIntegerLength: s = 9,
26
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;
27
+ } = e, i = t.replace(",", ".").replace(/[^\d.]/g, "");
28
+ let n = i;
29
+ if (n = n.replace(/^0+(?=\d)/, ""), !r)
30
+ return n = n.replace(/\D/g, ""), s > 0 && n.length > s && (n = n.slice(0, s)), o ? A(n) : n;
31
31
  n === "." && (n = "0.");
32
- const a = n.indexOf(".");
33
- if (a !== -1) {
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;
32
+ const u = n.indexOf(".");
33
+ if (u !== -1) {
34
+ let a = n.slice(0, u), f = n.slice(u + 1).replace(/\./g, "");
35
+ s > 0 && a.length > s && (a = a.slice(0, s)), f = f.slice(0, l), a === "" && (a = "0");
36
+ const h = i.endsWith(".") || n.endsWith(".");
37
+ n = f.length > 0 ? `${a}.${f}` : h ? `${a}.` : a;
38
38
  } else
39
- c > 0 && n.length > c && (n = n.slice(0, c));
40
- return r ? A(n) : n;
39
+ s > 0 && n.length > s && (n = n.slice(0, s));
40
+ return o ? A(n) : n;
41
41
  }
42
42
  function q(t, e) {
43
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])
44
+ const r = t, o = e, s = Object.keys(r), l = Object.keys(o);
45
+ return s.length !== l.length ? !1 : s.every(
46
+ (i) => Object.prototype.hasOwnProperty.call(o, i) && Object.is(r[i], o[i])
47
47
  );
48
48
  }
49
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 });
50
+ const r = W(e), o = ({ children: l, value: i }) => {
51
+ const n = F(i);
52
+ return q(n.current, i) || (n.current = i), /* @__PURE__ */ k(r.Provider, { value: n.current, children: l });
53
53
  };
54
- r.displayName = t + "Provider";
55
- function c({
54
+ o.displayName = t + "Provider";
55
+ function s({
56
56
  consumerName: l,
57
- contextRequired: o
57
+ contextRequired: i
58
58
  }) {
59
- const n = W(i);
59
+ const n = w(r);
60
60
  if (n)
61
61
  return n;
62
- if (o)
62
+ if (i)
63
63
  throw new Error(
64
64
  `${l} must be used within ${t}`
65
65
  );
66
66
  return e || {};
67
67
  }
68
- return [r, c];
68
+ return [o, s];
69
69
  }
70
- const [tt, K] = z("Disabled", { disabled: !1 }), et = ({
70
+ const [X, K] = z("Disabled", { disabled: !1 }), tt = ({
71
71
  consumerName: t,
72
72
  contextRequired: e,
73
- mergeWith: i
73
+ mergeWith: r
74
74
  }) => {
75
- const r = K({
75
+ const o = K({
76
76
  consumerName: t,
77
77
  contextRequired: e ?? !1
78
78
  });
79
- return !!(i?.disabled || r.disabled);
79
+ return !!(r?.disabled || o.disabled);
80
80
  };
81
- function nt(...t) {
82
- return F(_(t));
81
+ function et(...t) {
82
+ return R(B(t));
83
83
  }
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) {
84
+ const O = (t) => typeof t == "string" || typeof t == "number", nt = (t) => Array.isArray(t) ? t.every(O) : O(t);
85
+ function S(t, e) {
86
86
  if (typeof t == "function")
87
87
  return t(e);
88
88
  typeof t == "object" && t !== null && "current" in t && (t.current = e);
89
89
  }
90
- function Z(...t) {
90
+ function N(...t) {
91
91
  const e = /* @__PURE__ */ new Map();
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);
92
+ return (r) => {
93
+ if (r === null) {
94
+ t.forEach((o) => {
95
+ const s = e.get(o);
96
+ typeof s == "function" && s(), S(o, null);
97
97
  }), e.clear();
98
98
  return;
99
99
  }
100
- t.forEach((r) => {
101
- const c = M(r, i);
102
- typeof c == "function" && e.set(r, c);
100
+ t.forEach((o) => {
101
+ const s = S(o, r);
102
+ typeof s == "function" && e.set(o, s);
103
103
  });
104
104
  };
105
105
  }
106
- function ot(...t) {
107
- return I(() => Z(...t), t);
106
+ function rt(...t) {
107
+ return I(() => N(...t), t);
108
108
  }
109
- const it = (t, e) => {
110
- let i = t;
111
- for (const r of e) {
112
- if (i == null)
109
+ const ot = (t, e) => {
110
+ let r = t;
111
+ for (const o of e) {
112
+ if (r == null)
113
113
  return;
114
- i = i[r];
114
+ r = r[o];
115
115
  }
116
- return i;
117
- }, ct = ({
116
+ return r;
117
+ }, it = ({
118
118
  currentStep: t,
119
119
  totalSteps: e,
120
- size: i,
121
- label: r,
122
- strokeWidth: c = 4,
120
+ size: r,
121
+ label: o,
122
+ strokeWidth: s = 4,
123
123
  arcPercentage: l = 0.75
124
124
  }) => {
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;
125
+ const i = Math.min(Math.max(t, 0), e), n = o ?? `${i}/${e}`, u = e <= 0 ? 0 : i / e, a = (r - s) / 2, f = r / 2, h = r / 2, d = 2 * Math.PI * a, g = d * l, b = g * (1 - u), p = i <= 0, D = `${g} ${d}`, P = p ? g - 2 : b;
126
126
  return {
127
127
  displayLabel: n,
128
- progress: a,
129
- r: u,
128
+ progress: u,
129
+ r: a,
130
130
  cx: f,
131
131
  cy: h,
132
132
  circumference: d,
133
133
  trackArcLength: g,
134
134
  trackDashArray: `${g} ${d}`,
135
- progressDashArray: $,
135
+ progressDashArray: D,
136
136
  progressDashOffset: P,
137
137
  showMinimalDot: p
138
138
  };
@@ -148,53 +148,53 @@ const it = (t, e) => {
148
148
  })) : []
149
149
  }),
150
150
  [t.integerPart, t.decimalPart]
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}`;
151
+ ), ct = (t, e, r) => {
152
+ if (e) return r;
153
+ const o = t.decimalPart ? `${t.decimalSeparator}${t.decimalPart}` : "", s = `${t.integerPart}${o}`;
154
+ return t.currencyPosition === "end" ? `${s} ${t.currencyText}` : `${t.currencyText} ${s}`;
155
155
  };
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;
156
+ function Z(t, e, r = {}) {
157
+ const { leading: o = !1, trailing: s = !0, maxWait: l } = r;
158
+ let i = null, n = null, u = null, a = 0, f = null, h = null, d;
159
+ const g = l !== void 0, b = g ? Math.max(l, e) : 0, p = (c) => {
160
+ a = c;
161
+ const m = f, y = h;
162
+ return f = null, h = null, d = t.apply(y, m), d;
163
+ }, D = (c) => {
164
+ const m = u ? c - u : 0;
165
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);
166
+ }, P = (c) => {
167
+ const m = u ? c - u : e, y = c - a;
168
+ return u === null || m >= e || m < 0 || g && y >= b;
169
+ }, $ = (c) => (i = null, s && f ? p(c) : (f = null, h = null, d)), x = () => {
170
+ const c = Date.now();
171
+ if (P(c)) {
172
+ $(c);
173
173
  return;
174
174
  }
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);
175
+ i = setTimeout(x, D(c));
176
+ }, M = () => {
177
+ const c = Date.now();
178
+ n = null, f && (p(c), i !== null && (clearTimeout(i), i = setTimeout(x, e)));
179
+ }, v = (c) => (a = c, i = setTimeout(x, e), g && (n = setTimeout(M, b)), o ? p(c) : d), E = () => {
180
+ i !== null && clearTimeout(i), n !== null && clearTimeout(n), a = 0, f = null, h = null, u = null, i = null, n = null;
181
+ }, L = () => i === null && n === null ? d : $(Date.now()), j = () => i !== null || n !== null, T = function(...c) {
182
+ const m = Date.now(), y = P(m);
183
+ if (f = c, h = this, u = m, y) {
184
+ if (i === null)
185
+ return v(m);
186
186
  if (g)
187
- return clearTimeout(o), o = setTimeout(y, e), p(m);
187
+ return clearTimeout(i), i = setTimeout(x, e), p(m);
188
188
  }
189
- return o === null && (o = setTimeout(y, e)), d;
189
+ return i === null && (i = setTimeout(x, e)), d;
190
190
  };
191
- return T.cancel = E, T.flush = j, T.pending = k, T;
191
+ return T.cancel = E, T.flush = L, T.pending = j, T;
192
192
  }
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,
193
+ function lt(t, e, r = {}) {
194
+ const { leading: o = !0, trailing: s = !0 } = r;
195
+ return Z(t, e, {
196
+ leading: o,
197
+ trailing: s,
198
198
  maxWait: e
199
199
  });
200
200
  }
@@ -208,30 +208,43 @@ const at = ({
208
208
  } : {
209
209
  role: "button",
210
210
  tabIndex: 0,
211
- onKeyDown: (r) => {
212
- (r.key === "Enter" || r.key === " ") && (r.preventDefault(), t?.(r));
211
+ onKeyDown: (o) => {
212
+ (o.key === "Enter" || o.key === " ") && (o.preventDefault(), t?.(o));
213
213
  },
214
214
  onClick: t
215
- } : void 0;
215
+ } : void 0, C = " ", ut = ({
216
+ label: t,
217
+ placeholder: e
218
+ }) => {
219
+ const r = typeof e == "string" && e.trim().length > 0 ? e : void 0;
220
+ return t ? {
221
+ inputPlaceholder: r ?? C,
222
+ labelStaysFloatedWithPlaceholder: r !== void 0
223
+ } : {
224
+ inputPlaceholder: e ?? C,
225
+ labelStaysFloatedWithPlaceholder: !1
226
+ };
227
+ };
216
228
  export {
217
- tt as DisabledProvider,
218
- M as assignRef,
219
- lt as buildAriaLabel,
220
- nt as cn,
229
+ X as DisabledProvider,
230
+ S as assignRef,
231
+ ct as buildAriaLabel,
232
+ et as cn,
221
233
  z as createSafeContext,
222
- U as debounce,
234
+ Z as debounce,
223
235
  A as formatThousands,
224
236
  at as getButtonA11yProps,
225
- Q as getFontSize,
226
- it as getObjectPath,
227
- ct as getStepperCalculations,
228
- rt as isTextChildren,
229
- Z as mergeRefs,
237
+ J as getFontSize,
238
+ ot as getObjectPath,
239
+ it as getStepperCalculations,
240
+ nt as isTextChildren,
241
+ N as mergeRefs,
242
+ ut as resolveBaseInputPlaceholder,
230
243
  q as shallowEqual,
231
- Y as textFormatter,
232
- ut as throttle,
233
- J as toPascalCase,
234
- et as useDisabledContext,
235
- ot as useMergedRef,
244
+ Q as textFormatter,
245
+ lt as throttle,
246
+ G as toPascalCase,
247
+ tt as useDisabledContext,
248
+ rt as useMergedRef,
236
249
  st as useSplitText
237
250
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/lib/cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,MAAM,CAAC;AAGxC,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
1
+ {"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/lib/cn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIvC,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
@@ -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,GACzB,OAAO,cAAc,EACrB,QAAQ,OAAO,EACf,aAAa,MAAM,KAClB,MAaF,CAAC"}
1
+ {"version":3,"file":"buildAriaLabel.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/buildAriaLabel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,cAAc,GACzB,OAAO,cAAc,EACrB,QAAQ,OAAO,EACf,aAAa,MAAM,KAClB,MAaF,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,GACvB,OAAO,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,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzD,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":"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"}
1
+ {"version":3,"file":"createSafeContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/createSafeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI3C,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,2 @@
1
+ export type Density = 'compact' | 'expanded';
2
+ //# sourceMappingURL=density.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"density.d.ts","sourceRoot":"","sources":["../../../src/lib/density/density.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './density';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/density/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -1,6 +1,24 @@
1
+ declare const FONT_SIZE_BY_SIZE: {
2
+ readonly md: {
3
+ readonly max: 48;
4
+ readonly min: 17;
5
+ readonly scale: 2;
6
+ readonly startAt: 0;
7
+ };
8
+ readonly sm: {
9
+ readonly max: 28;
10
+ readonly min: 12;
11
+ readonly scale: 2;
12
+ readonly startAt: 6;
13
+ };
14
+ };
15
+ export type AmountInputFontSizeSize = keyof typeof FONT_SIZE_BY_SIZE;
1
16
  /**
2
17
  * Calculates the font size based on the number of digits in the input value.
3
- * Scales from 48px (max) to 17px (min) as digit count increases.
18
+ * Scales from max to min as digit count increases.
19
+ * - md: 48px (heading-0-semi-bold) down to 17px, shrinks from the first digit
20
+ * - sm: 28px (heading-2-semi-bold) down to 12px, shrinks after 6 digits
4
21
  */
5
- export declare function getFontSize(value: string): number;
22
+ export declare function getFontSize(value: string, size?: AmountInputFontSizeSize): number;
23
+ export {};
6
24
  //# sourceMappingURL=fontSizeFormatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fontSizeFormatter.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/fontSizeFormatter.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOjD"}
1
+ {"version":3,"file":"fontSizeFormatter.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/fontSizeFormatter.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;CAGb,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,uBAA8B,GACnC,MAAM,CAKR"}
@@ -1,4 +1,4 @@
1
- export { getFontSize } from './fontSizeFormatter';
1
+ export { getFontSize, type AmountInputFontSizeSize } from './fontSizeFormatter';
2
2
  export { formatThousands } from './formatThousands';
3
3
  export { textFormatter } from './textFormatter';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,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,GAAI,SAAS,SAAS,YAGhD,CAAC"}
1
+ {"version":3,"file":"isTextChildren.d.ts","sourceRoot":"","sources":["../../../src/lib/isTextChildren/isTextChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,YAGhD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './resolveBaseInputPlaceholder';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/resolveBaseInputPlaceholder/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,20 @@
1
+ export type ResolveBaseInputPlaceholderArgs = {
2
+ label: string | undefined;
3
+ /** Raw `placeholder` from the input props (before spreading onto the field). */
4
+ placeholder: string | undefined;
5
+ };
6
+ export type ResolveBaseInputPlaceholderResult = {
7
+ /** Value to set on the native input `placeholder`. */
8
+ inputPlaceholder: string;
9
+ /**
10
+ * When a floating label and a non-empty user placeholder are both in use, the label must
11
+ * stay in the “floated” slot (not the empty-field centered position).
12
+ */
13
+ labelStaysFloatedWithPlaceholder: boolean;
14
+ };
15
+ /**
16
+ * Derives the native `placeholder` and floating-label mode for Lumen `BaseInput`.
17
+ * Web and React Native share this so label + example copy, and prefix-only fields, stay consistent.
18
+ */
19
+ export declare const resolveBaseInputPlaceholder: ({ label, placeholder, }: ResolveBaseInputPlaceholderArgs) => ResolveBaseInputPlaceholderResult;
20
+ //# sourceMappingURL=resolveBaseInputPlaceholder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveBaseInputPlaceholder.d.ts","sourceRoot":"","sources":["../../../src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,+BAA+B,GAAG;IAC5C,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,gFAAgF;IAChF,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,sDAAsD;IACtD,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,gCAAgC,EAAE,OAAO,CAAC;CAC3C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,yBAGzC,+BAA+B,KAAG,iCAiBpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/lib/throttle/throttle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,IACnE,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EAC9D,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CAAC,CAAC,CAAC,CAQtB"}
1
+ {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/lib/throttle/throttle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,IACnE,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EAC9D,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CAAC,CAAC,CAAC,CAQtB"}
@@ -1,4 +1,4 @@
1
- import { Ref, RefCallback } from 'react';
1
+ import { RefCallback, Ref } from 'react';
2
2
  type PossibleRef<T> = Ref<T> | undefined;
3
3
  type RefCleanup = void | (() => void);
4
4
  export declare function assignRef<T>(ref: PossibleRef<T>, value: T | null): RefCleanup;
@@ -1 +1 @@
1
- {"version":3,"file":"useMergeRef.d.ts","sourceRoot":"","sources":["../../../src/lib/useMergeRef/useMergeRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAW,KAAK,WAAW,EAAE,MAAM,OAAO,CAAC;AAEvD,KAAK,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AACzC,KAAK,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAEtC,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,UAAU,CAM7E;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAuBtE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAEzE"}
1
+ {"version":3,"file":"useMergeRef.d.ts","sourceRoot":"","sources":["../../../src/lib/useMergeRef/useMergeRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAG9C,KAAK,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AACzC,KAAK,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAEtC,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,UAAU,CAM7E;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAuBtE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAEzE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/lumen-utils-shared",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './lib/density';
1
2
  export * from './lib/string/string';
2
3
  export * from './lib/inputFormatter';
3
4
  export * from './lib/context';
@@ -10,3 +11,4 @@ export * from './lib/throttle';
10
11
  export * from './lib/debounce';
11
12
  export * from './lib/a11y';
12
13
  export * from './lib/shallowEqual';
14
+ export * from './lib/resolveBaseInputPlaceholder';
package/src/lib/cn.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ClassValue, clsx } from 'clsx';
1
+ import type { ClassValue } from 'clsx';
2
+ import { clsx } from 'clsx';
2
3
  import { twMerge } from 'tailwind-merge';
3
4
 
4
5
  export function cn(...inputs: ClassValue[]) {
@@ -1,4 +1,4 @@
1
- import { FormattedValue } from './types';
1
+ import type { FormattedValue } from './types';
2
2
 
3
3
  export const buildAriaLabel = (
4
4
  parts: FormattedValue,
@@ -1,7 +1,7 @@
1
1
  import { renderHook } from '@testing-library/react';
2
2
  import { describe, it, expect } from 'vitest';
3
3
 
4
- import { FormattedValue } from './types';
4
+ import type { FormattedValue } from './types';
5
5
  import { useSplitText } from './useSplitText';
6
6
 
7
7
  const createValue = (
@@ -1,5 +1,5 @@
1
1
  import { useMemo } from 'react';
2
- import { FormattedValue, SplitChar } from './types';
2
+ import type { FormattedValue, SplitChar } from './types';
3
3
 
4
4
  export const useSplitText = (
5
5
  value: FormattedValue,
@@ -1,4 +1,5 @@
1
- import { createContext, FC, ReactNode, useContext, useRef } from 'react';
1
+ import type { FC, ReactNode } from 'react';
2
+ import { createContext, useContext, useRef } from 'react';
2
3
  import { shallowEqual } from '../shallowEqual';
3
4
 
4
5
  export function createSafeContext<ContextValue extends object>(
@@ -0,0 +1 @@
1
+ export type Density = 'compact' | 'expanded';
@@ -0,0 +1 @@
1
+ export * from './density';
@@ -0,0 +1,46 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { getFontSize } from './fontSizeFormatter';
3
+
4
+ describe('getFontSize', () => {
5
+ describe('md (default)', () => {
6
+ it('returns 48px for empty value', () => {
7
+ expect(getFontSize('')).toBe(48);
8
+ });
9
+
10
+ it('returns 46px for single digit', () => {
11
+ expect(getFontSize('5')).toBe(46);
12
+ });
13
+
14
+ it('scales down as digit count increases', () => {
15
+ expect(getFontSize('12345')).toBe(38);
16
+ expect(getFontSize('123456789')).toBe(30);
17
+ });
18
+
19
+ it('does not go below 17px', () => {
20
+ expect(getFontSize('123456789012345678')).toBe(17);
21
+ });
22
+ });
23
+
24
+ describe('sm', () => {
25
+ it('returns 28px for empty value', () => {
26
+ expect(getFontSize('', 'sm')).toBe(28);
27
+ });
28
+
29
+ it('stays at 28px for up to 6 digits (scaling starts after startAt)', () => {
30
+ expect(getFontSize('5', 'sm')).toBe(28);
31
+ expect(getFontSize('123456', 'sm')).toBe(28);
32
+ });
33
+
34
+ it('scales down after 6 digits', () => {
35
+ // 7 digits: 28 - 1 * 2 = 26
36
+ expect(getFontSize('1234567', 'sm')).toBe(26);
37
+ // 10 digits: 28 - 4 * 2 = 20
38
+ expect(getFontSize('1234567890', 'sm')).toBe(20);
39
+ });
40
+
41
+ it('does not go below 12px', () => {
42
+ // 15 digits: 28 - 9 * 2 = 10 → clamped to 12
43
+ expect(getFontSize('123456789012345', 'sm')).toBe(12);
44
+ });
45
+ });
46
+ });
@@ -1,16 +1,22 @@
1
- const MAX_FONT_SIZE = 48;
2
- const MIN_FONT_SIZE = 17;
3
- const SCALE_FACTOR = 2;
1
+ const FONT_SIZE_BY_SIZE = {
2
+ md: { max: 48, min: 17, scale: 2, startAt: 0 },
3
+ sm: { max: 28, min: 12, scale: 2, startAt: 6 },
4
+ } as const;
5
+
6
+ export type AmountInputFontSizeSize = keyof typeof FONT_SIZE_BY_SIZE;
4
7
 
5
8
  /**
6
9
  * Calculates the font size based on the number of digits in the input value.
7
- * Scales from 48px (max) to 17px (min) as digit count increases.
10
+ * Scales from max to min as digit count increases.
11
+ * - md: 48px (heading-0-semi-bold) down to 17px, shrinks from the first digit
12
+ * - sm: 28px (heading-2-semi-bold) down to 12px, shrinks after 6 digits
8
13
  */
9
- export function getFontSize(value: string): number {
14
+ export function getFontSize(
15
+ value: string,
16
+ size: AmountInputFontSizeSize = 'md',
17
+ ): number {
18
+ const { max, min, scale, startAt } = FONT_SIZE_BY_SIZE[size];
10
19
  const digits = value.replace(/\D/g, '').length;
11
- const fontSize = Math.max(
12
- MIN_FONT_SIZE,
13
- MAX_FONT_SIZE - digits * SCALE_FACTOR,
14
- );
20
+ const fontSize = Math.max(min, max - Math.max(0, digits - startAt) * scale);
15
21
  return fontSize;
16
22
  }
@@ -1,3 +1,3 @@
1
- export { getFontSize } from './fontSizeFormatter';
1
+ export { getFontSize, type AmountInputFontSizeSize } from './fontSizeFormatter';
2
2
  export { formatThousands } from './formatThousands';
3
3
  export { textFormatter } from './textFormatter';
@@ -1,4 +1,5 @@
1
- import React, { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
+ import React from 'react';
2
3
  import { describe, it, expect } from 'vitest';
3
4
  import { isTextChildren } from './isTextChildren';
4
5
 
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
 
3
3
  const isStringOrNumber = (element: ReactNode) =>
4
4
  typeof element === 'string' || typeof element === 'number';
@@ -0,0 +1 @@
1
+ export * from './resolveBaseInputPlaceholder';
@@ -0,0 +1,61 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { resolveBaseInputPlaceholder } from './resolveBaseInputPlaceholder';
3
+
4
+ describe('resolveBaseInputPlaceholder', () => {
5
+ it('with label: uses a single space when no user placeholder (float hack)', () => {
6
+ expect(
7
+ resolveBaseInputPlaceholder({ label: 'Email', placeholder: undefined }),
8
+ ).toEqual({
9
+ inputPlaceholder: ' ',
10
+ labelStaysFloatedWithPlaceholder: false,
11
+ });
12
+ });
13
+
14
+ it('with label: uses user placeholder and keeps label floated alongside it', () => {
15
+ expect(
16
+ resolveBaseInputPlaceholder({
17
+ label: 'Username',
18
+ placeholder: 'jane.doe',
19
+ }),
20
+ ).toEqual({
21
+ inputPlaceholder: 'jane.doe',
22
+ labelStaysFloatedWithPlaceholder: true,
23
+ });
24
+ });
25
+
26
+ it('with label: treats whitespace-only placeholder as absent', () => {
27
+ expect(
28
+ resolveBaseInputPlaceholder({ label: 'x', placeholder: ' ' }),
29
+ ).toEqual({
30
+ inputPlaceholder: ' ',
31
+ labelStaysFloatedWithPlaceholder: false,
32
+ });
33
+ });
34
+
35
+ it('without label: defaults omitted placeholder to a single space', () => {
36
+ expect(
37
+ resolveBaseInputPlaceholder({ label: undefined, placeholder: undefined }),
38
+ ).toEqual({
39
+ inputPlaceholder: ' ',
40
+ labelStaysFloatedWithPlaceholder: false,
41
+ });
42
+ });
43
+
44
+ it('without label: passes through user placeholder', () => {
45
+ expect(
46
+ resolveBaseInputPlaceholder({ label: undefined, placeholder: 'Search' }),
47
+ ).toEqual({
48
+ inputPlaceholder: 'Search',
49
+ labelStaysFloatedWithPlaceholder: false,
50
+ });
51
+ });
52
+
53
+ it('without label: keeps empty string (not coerced to space)', () => {
54
+ expect(
55
+ resolveBaseInputPlaceholder({ label: undefined, placeholder: '' }),
56
+ ).toEqual({
57
+ inputPlaceholder: '',
58
+ labelStaysFloatedWithPlaceholder: false,
59
+ });
60
+ });
61
+ });
@@ -0,0 +1,44 @@
1
+ /** Single space: drives floating-label / placeholder-shown behavior when no user-facing placeholder is set. */
2
+ const PLACEHOLDER_FOR_FLOAT = ' ';
3
+
4
+ export type ResolveBaseInputPlaceholderArgs = {
5
+ label: string | undefined;
6
+ /** Raw `placeholder` from the input props (before spreading onto the field). */
7
+ placeholder: string | undefined;
8
+ };
9
+
10
+ export type ResolveBaseInputPlaceholderResult = {
11
+ /** Value to set on the native input `placeholder`. */
12
+ inputPlaceholder: string;
13
+ /**
14
+ * When a floating label and a non-empty user placeholder are both in use, the label must
15
+ * stay in the “floated” slot (not the empty-field centered position).
16
+ */
17
+ labelStaysFloatedWithPlaceholder: boolean;
18
+ };
19
+
20
+ /**
21
+ * Derives the native `placeholder` and floating-label mode for Lumen `BaseInput`.
22
+ * Web and React Native share this so label + example copy, and prefix-only fields, stay consistent.
23
+ */
24
+ export const resolveBaseInputPlaceholder = ({
25
+ label,
26
+ placeholder,
27
+ }: ResolveBaseInputPlaceholderArgs): ResolveBaseInputPlaceholderResult => {
28
+ const userText =
29
+ typeof placeholder === 'string' && placeholder.trim().length > 0
30
+ ? placeholder
31
+ : undefined;
32
+
33
+ if (label) {
34
+ return {
35
+ inputPlaceholder: userText ?? PLACEHOLDER_FOR_FLOAT,
36
+ labelStaysFloatedWithPlaceholder: userText !== undefined,
37
+ };
38
+ }
39
+
40
+ return {
41
+ inputPlaceholder: placeholder ?? PLACEHOLDER_FOR_FLOAT,
42
+ labelStaysFloatedWithPlaceholder: false,
43
+ };
44
+ };
@@ -1,4 +1,5 @@
1
- import { debounce, DebouncedFunction } from '../debounce';
1
+ import type { DebouncedFunction } from '../debounce';
2
+ import { debounce } from '../debounce';
2
3
 
3
4
  export type ThrottleOptions = {
4
5
  /**
@@ -1,4 +1,5 @@
1
- import { Ref, useMemo, type RefCallback } from 'react';
1
+ import type { RefCallback, Ref } from 'react';
2
+ import { useMemo } from 'react';
2
3
 
3
4
  type PossibleRef<T> = Ref<T> | undefined;
4
5
  type RefCleanup = void | (() => void);