@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.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +145 -132
- package/dist/lib/cn.d.ts.map +1 -1
- package/dist/lib/components/amountDisplayHelpers/buildAriaLabel.d.ts.map +1 -1
- package/dist/lib/components/amountDisplayHelpers/useSplitText.d.ts.map +1 -1
- package/dist/lib/context/createSafeContext.d.ts.map +1 -1
- package/dist/lib/density/density.d.ts +2 -0
- package/dist/lib/density/density.d.ts.map +1 -0
- package/dist/lib/density/index.d.ts +2 -0
- package/dist/lib/density/index.d.ts.map +1 -0
- package/dist/lib/inputFormatter/fontSizeFormatter.d.ts +20 -2
- package/dist/lib/inputFormatter/fontSizeFormatter.d.ts.map +1 -1
- package/dist/lib/inputFormatter/index.d.ts +1 -1
- package/dist/lib/inputFormatter/index.d.ts.map +1 -1
- package/dist/lib/isTextChildren/isTextChildren.d.ts.map +1 -1
- package/dist/lib/resolveBaseInputPlaceholder/index.d.ts +2 -0
- package/dist/lib/resolveBaseInputPlaceholder/index.d.ts.map +1 -0
- package/dist/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.d.ts +20 -0
- package/dist/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.d.ts.map +1 -0
- package/dist/lib/throttle/throttle.d.ts.map +1 -1
- package/dist/lib/useMergeRef/useMergeRef.d.ts +1 -1
- package/dist/lib/useMergeRef/useMergeRef.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/lib/cn.ts +2 -1
- package/src/lib/components/amountDisplayHelpers/buildAriaLabel.ts +1 -1
- package/src/lib/components/amountDisplayHelpers/useSplitText.test.ts +1 -1
- package/src/lib/components/amountDisplayHelpers/useSplitText.ts +1 -1
- package/src/lib/context/createSafeContext.tsx +2 -1
- package/src/lib/density/density.ts +1 -0
- package/src/lib/density/index.ts +1 -0
- package/src/lib/inputFormatter/fontSizeFormatter.test.ts +46 -0
- package/src/lib/inputFormatter/fontSizeFormatter.ts +15 -9
- package/src/lib/inputFormatter/index.ts +1 -1
- package/src/lib/isTextChildren/isTextChildren.test.ts +2 -1
- package/src/lib/isTextChildren/isTextChildren.ts +1 -1
- package/src/lib/resolveBaseInputPlaceholder/index.ts +1 -0
- package/src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.test.ts +61 -0
- package/src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.ts +44 -0
- package/src/lib/throttle/throttle.ts +2 -1
- 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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { clsx as
|
|
4
|
-
import { twMerge as
|
|
5
|
-
function
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
19
|
-
return
|
|
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
|
|
21
|
+
function Q(t, e = {}) {
|
|
22
22
|
const {
|
|
23
|
-
allowDecimals:
|
|
24
|
-
thousandsSeparator:
|
|
25
|
-
maxIntegerLength:
|
|
23
|
+
allowDecimals: r = !0,
|
|
24
|
+
thousandsSeparator: o = !0,
|
|
25
|
+
maxIntegerLength: s = 9,
|
|
26
26
|
maxDecimalLength: l = 9
|
|
27
|
-
} = e,
|
|
28
|
-
let n =
|
|
29
|
-
if (n = n.replace(/^0+(?=\d)/, ""), !
|
|
30
|
-
return n = n.replace(/\D/g, ""),
|
|
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
|
|
33
|
-
if (
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
const h =
|
|
37
|
-
n = f.length > 0 ? `${
|
|
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
|
-
|
|
40
|
-
return
|
|
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
|
|
45
|
-
return
|
|
46
|
-
(
|
|
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
|
|
51
|
-
const n =
|
|
52
|
-
return q(n.current,
|
|
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
|
-
|
|
55
|
-
function
|
|
54
|
+
o.displayName = t + "Provider";
|
|
55
|
+
function s({
|
|
56
56
|
consumerName: l,
|
|
57
|
-
contextRequired:
|
|
57
|
+
contextRequired: i
|
|
58
58
|
}) {
|
|
59
|
-
const n =
|
|
59
|
+
const n = w(r);
|
|
60
60
|
if (n)
|
|
61
61
|
return n;
|
|
62
|
-
if (
|
|
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 [
|
|
68
|
+
return [o, s];
|
|
69
69
|
}
|
|
70
|
-
const [
|
|
70
|
+
const [X, K] = z("Disabled", { disabled: !1 }), tt = ({
|
|
71
71
|
consumerName: t,
|
|
72
72
|
contextRequired: e,
|
|
73
|
-
mergeWith:
|
|
73
|
+
mergeWith: r
|
|
74
74
|
}) => {
|
|
75
|
-
const
|
|
75
|
+
const o = K({
|
|
76
76
|
consumerName: t,
|
|
77
77
|
contextRequired: e ?? !1
|
|
78
78
|
});
|
|
79
|
-
return !!(
|
|
79
|
+
return !!(r?.disabled || o.disabled);
|
|
80
80
|
};
|
|
81
|
-
function
|
|
82
|
-
return
|
|
81
|
+
function et(...t) {
|
|
82
|
+
return R(B(t));
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
function
|
|
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
|
|
90
|
+
function N(...t) {
|
|
91
91
|
const e = /* @__PURE__ */ new Map();
|
|
92
|
-
return (
|
|
93
|
-
if (
|
|
94
|
-
t.forEach((
|
|
95
|
-
const
|
|
96
|
-
typeof
|
|
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((
|
|
101
|
-
const
|
|
102
|
-
typeof
|
|
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
|
|
107
|
-
return I(() =>
|
|
106
|
+
function rt(...t) {
|
|
107
|
+
return I(() => N(...t), t);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
110
|
-
let
|
|
111
|
-
for (const
|
|
112
|
-
if (
|
|
109
|
+
const ot = (t, e) => {
|
|
110
|
+
let r = t;
|
|
111
|
+
for (const o of e) {
|
|
112
|
+
if (r == null)
|
|
113
113
|
return;
|
|
114
|
-
|
|
114
|
+
r = r[o];
|
|
115
115
|
}
|
|
116
|
-
return
|
|
117
|
-
},
|
|
116
|
+
return r;
|
|
117
|
+
}, it = ({
|
|
118
118
|
currentStep: t,
|
|
119
119
|
totalSteps: e,
|
|
120
|
-
size:
|
|
121
|
-
label:
|
|
122
|
-
strokeWidth:
|
|
120
|
+
size: r,
|
|
121
|
+
label: o,
|
|
122
|
+
strokeWidth: s = 4,
|
|
123
123
|
arcPercentage: l = 0.75
|
|
124
124
|
}) => {
|
|
125
|
-
const
|
|
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:
|
|
129
|
-
r:
|
|
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
|
-
),
|
|
152
|
-
if (e) return
|
|
153
|
-
const
|
|
154
|
-
return t.currencyPosition === "end" ? `${
|
|
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
|
|
157
|
-
const { leading:
|
|
158
|
-
let
|
|
159
|
-
const g = l !== void 0, b = g ? Math.max(l, e) : 0, p = (
|
|
160
|
-
|
|
161
|
-
const m = f,
|
|
162
|
-
return f = null, h = null, d = t.apply(
|
|
163
|
-
},
|
|
164
|
-
const m =
|
|
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 = (
|
|
167
|
-
const m =
|
|
168
|
-
return
|
|
169
|
-
},
|
|
170
|
-
const
|
|
171
|
-
if (P(
|
|
172
|
-
|
|
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
|
-
|
|
176
|
-
},
|
|
177
|
-
const
|
|
178
|
-
n = null, f && (p(
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
},
|
|
182
|
-
const m = Date.now(),
|
|
183
|
-
if (f =
|
|
184
|
-
if (
|
|
185
|
-
return
|
|
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(
|
|
187
|
+
return clearTimeout(i), i = setTimeout(x, e), p(m);
|
|
188
188
|
}
|
|
189
|
-
return
|
|
189
|
+
return i === null && (i = setTimeout(x, e)), d;
|
|
190
190
|
};
|
|
191
|
-
return T.cancel = E, T.flush =
|
|
191
|
+
return T.cancel = E, T.flush = L, T.pending = j, T;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
const { leading:
|
|
195
|
-
return
|
|
196
|
-
leading:
|
|
197
|
-
trailing:
|
|
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: (
|
|
212
|
-
(
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
X as DisabledProvider,
|
|
230
|
+
S as assignRef,
|
|
231
|
+
ct as buildAriaLabel,
|
|
232
|
+
et as cn,
|
|
221
233
|
z as createSafeContext,
|
|
222
|
-
|
|
234
|
+
Z as debounce,
|
|
223
235
|
A as formatThousands,
|
|
224
236
|
at as getButtonA11yProps,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
};
|
package/dist/lib/cn.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/lib/cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
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;
|
|
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;
|
|
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,
|
|
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 @@
|
|
|
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 @@
|
|
|
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
|
|
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":"
|
|
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;
|
|
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;
|
|
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 @@
|
|
|
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,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMergeRef.d.ts","sourceRoot":"","sources":["../../../src/lib/useMergeRef/useMergeRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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
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,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,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
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(
|
|
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
|
}
|
|
@@ -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
|
+
};
|