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