@ledgerhq/lumen-utils-shared 0.1.2 → 0.1.4
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 +136 -123
- 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/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/eslint.config.mjs +2 -2
- 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/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/vite.config.ts +1 -0
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,128 +1,128 @@
|
|
|
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 F, useRef as W, useContext as _, useMemo as I } from "react";
|
|
3
|
+
import { clsx as R } from "clsx";
|
|
4
|
+
import { twMerge as w } from "tailwind-merge";
|
|
5
|
+
function Q(t) {
|
|
6
6
|
return t ? t.split(/[-_ ]+/).map((e) => e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()).join("") : "";
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
function
|
|
8
|
+
const B = 48, N = 17, q = 2;
|
|
9
|
+
function Y(t) {
|
|
10
10
|
const e = t.replace(/\D/g, "").length;
|
|
11
11
|
return Math.max(
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
N,
|
|
13
|
+
B - e * q
|
|
14
14
|
);
|
|
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 tt(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
32
|
const a = n.indexOf(".");
|
|
33
33
|
if (a !== -1) {
|
|
34
34
|
let u = n.slice(0, a), f = n.slice(a + 1).replace(/\./g, "");
|
|
35
|
-
|
|
36
|
-
const h =
|
|
35
|
+
s > 0 && u.length > s && (u = u.slice(0, s)), f = f.slice(0, l), u === "" && (u = "0");
|
|
36
|
+
const h = i.endsWith(".") || n.endsWith(".");
|
|
37
37
|
n = f.length > 0 ? `${u}.${f}` : h ? `${u}.` : u;
|
|
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
|
-
function
|
|
42
|
+
function z(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
|
-
function
|
|
50
|
-
const
|
|
51
|
-
const n =
|
|
52
|
-
return
|
|
49
|
+
function K(t, e) {
|
|
50
|
+
const r = F(e), o = ({ children: l, value: i }) => {
|
|
51
|
+
const n = W(i);
|
|
52
|
+
return z(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 = _(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 [et, Z] = K("Disabled", { disabled: !1 }), nt = ({
|
|
71
71
|
consumerName: t,
|
|
72
72
|
contextRequired: e,
|
|
73
|
-
mergeWith:
|
|
73
|
+
mergeWith: r
|
|
74
74
|
}) => {
|
|
75
|
-
const
|
|
75
|
+
const o = Z({
|
|
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 rt(...t) {
|
|
82
|
+
return w(R(t));
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
function
|
|
84
|
+
const O = (t) => typeof t == "string" || typeof t == "number", ot = (t) => Array.isArray(t) ? t.every(O) : O(t);
|
|
85
|
+
function C(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 H(...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(), C(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 = C(o, r);
|
|
102
|
+
typeof s == "function" && e.set(o, s);
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
return I(() =>
|
|
106
|
+
function it(...t) {
|
|
107
|
+
return I(() => H(...t), t);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
110
|
-
let
|
|
111
|
-
for (const
|
|
112
|
-
if (
|
|
109
|
+
const st = (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
|
|
116
|
+
return r;
|
|
117
117
|
}, ct = ({
|
|
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}`, a = e <= 0 ? 0 : i / e, u = (r - s) / 2, f = r / 2, h = r / 2, d = 2 * Math.PI * u, g = d * l, b = g * (1 - a), p = i <= 0, D = `${g} ${d}`, P = p ? g - 2 : b;
|
|
126
126
|
return {
|
|
127
127
|
displayLabel: n,
|
|
128
128
|
progress: a,
|
|
@@ -132,11 +132,11 @@ const it = (t, e) => {
|
|
|
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
|
};
|
|
139
|
-
},
|
|
139
|
+
}, lt = (t) => I(
|
|
140
140
|
() => ({
|
|
141
141
|
integerPart: Array.from(t.integerPart, (e) => ({
|
|
142
142
|
value: e,
|
|
@@ -148,57 +148,57 @@ 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
|
+
), ut = (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,
|
|
157
|
-
const { leading:
|
|
158
|
-
let
|
|
159
|
-
const g = l !== void 0, b = g ? Math.max(l, e) : 0, p = (
|
|
160
|
-
u =
|
|
156
|
+
function U(t, e, r = {}) {
|
|
157
|
+
const { leading: o = !1, trailing: s = !0, maxWait: l } = r;
|
|
158
|
+
let i = 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 = (c) => {
|
|
160
|
+
u = c;
|
|
161
161
|
const m = f, x = h;
|
|
162
162
|
return f = null, h = null, d = t.apply(x, m), d;
|
|
163
|
-
},
|
|
164
|
-
const m = a ?
|
|
163
|
+
}, D = (c) => {
|
|
164
|
+
const m = a ? c - a : 0;
|
|
165
165
|
return e - m;
|
|
166
|
-
}, P = (
|
|
167
|
-
const m = a ?
|
|
166
|
+
}, P = (c) => {
|
|
167
|
+
const m = a ? c - a : e, x = c - u;
|
|
168
168
|
return a === null || m >= e || m < 0 || g && x >= b;
|
|
169
|
-
},
|
|
170
|
-
const
|
|
171
|
-
if (P(
|
|
172
|
-
|
|
169
|
+
}, $ = (c) => (i = null, s && f ? p(c) : (f = null, h = null, d)), y = () => {
|
|
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
|
-
},
|
|
175
|
+
i = setTimeout(y, D(c));
|
|
176
|
+
}, M = () => {
|
|
177
|
+
const c = Date.now();
|
|
178
|
+
n = null, f && (p(c), i !== null && (clearTimeout(i), i = setTimeout(y, e)));
|
|
179
|
+
}, E = (c) => (u = c, i = setTimeout(y, e), g && (n = setTimeout(M, b)), o ? p(c) : d), v = () => {
|
|
180
|
+
i !== null && clearTimeout(i), n !== null && clearTimeout(n), u = 0, f = null, h = null, a = null, i = null, n = null;
|
|
181
|
+
}, L = () => i === null && n === null ? d : $(Date.now()), j = () => i !== null || n !== null, T = function(...c) {
|
|
182
182
|
const m = Date.now(), x = P(m);
|
|
183
|
-
if (f =
|
|
184
|
-
if (
|
|
185
|
-
return
|
|
183
|
+
if (f = c, h = this, a = m, x) {
|
|
184
|
+
if (i === null)
|
|
185
|
+
return E(m);
|
|
186
186
|
if (g)
|
|
187
|
-
return clearTimeout(
|
|
187
|
+
return clearTimeout(i), i = setTimeout(y, e), p(m);
|
|
188
188
|
}
|
|
189
|
-
return
|
|
189
|
+
return i === null && (i = setTimeout(y, e)), d;
|
|
190
190
|
};
|
|
191
|
-
return T.cancel =
|
|
191
|
+
return T.cancel = v, T.flush = L, T.pending = j, T;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
const { leading:
|
|
193
|
+
function at(t, e, r = {}) {
|
|
194
|
+
const { leading: o = !0, trailing: s = !0 } = r;
|
|
195
195
|
return U(t, e, {
|
|
196
|
-
leading:
|
|
197
|
-
trailing:
|
|
196
|
+
leading: o,
|
|
197
|
+
trailing: s,
|
|
198
198
|
maxWait: e
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
|
-
const
|
|
201
|
+
const ft = ({
|
|
202
202
|
onClick: t,
|
|
203
203
|
disabled: e
|
|
204
204
|
}) => t ? e ? {
|
|
@@ -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, S = " ", dt = ({
|
|
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 ?? S,
|
|
222
|
+
labelStaysFloatedWithPlaceholder: r !== void 0
|
|
223
|
+
} : {
|
|
224
|
+
inputPlaceholder: e ?? S,
|
|
225
|
+
labelStaysFloatedWithPlaceholder: !1
|
|
226
|
+
};
|
|
227
|
+
};
|
|
216
228
|
export {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
229
|
+
et as DisabledProvider,
|
|
230
|
+
C as assignRef,
|
|
231
|
+
ut as buildAriaLabel,
|
|
232
|
+
rt as cn,
|
|
233
|
+
K as createSafeContext,
|
|
222
234
|
U as debounce,
|
|
223
235
|
A as formatThousands,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
236
|
+
ft as getButtonA11yProps,
|
|
237
|
+
Y as getFontSize,
|
|
238
|
+
st as getObjectPath,
|
|
227
239
|
ct as getStepperCalculations,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
240
|
+
ot as isTextChildren,
|
|
241
|
+
H as mergeRefs,
|
|
242
|
+
dt as resolveBaseInputPlaceholder,
|
|
243
|
+
z as shallowEqual,
|
|
244
|
+
tt as textFormatter,
|
|
245
|
+
at as throttle,
|
|
246
|
+
Q as toPascalCase,
|
|
247
|
+
nt as useDisabledContext,
|
|
248
|
+
it as useMergedRef,
|
|
249
|
+
lt 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 +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/eslint.config.mjs
CHANGED
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 @@
|
|
|
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
|
+
};
|