@leonardaustin/ui 0.26.0 → 0.26.1
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.
|
@@ -36,4 +36,4 @@ export interface CodeInputProps extends Omit<ComponentPropsWithRef<"div">, "chil
|
|
|
36
36
|
* Handles typing, paste, SMS autofill, Backspace/Delete and arrow keys; each
|
|
37
37
|
* box keeps its position, so clearing one never shifts the others.
|
|
38
38
|
*/
|
|
39
|
-
export declare function CodeInput({ value: valueProp, defaultValue, onValueChange, onComplete, length, error, invalid, disabled, autoFocus, name, "aria-label": ariaLabel, className, ref, ...rest }: CodeInputProps): import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
export declare function CodeInput({ value: valueProp, defaultValue, onValueChange, onComplete, length, error, invalid, disabled, autoFocus, name, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, className, ref, ...rest }: CodeInputProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,96 +1,97 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
2
|
import { useControllableState as t } from "../../hooks/useControllableState.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { describeField as n } from "./FieldContext.js";
|
|
4
|
+
import { applyBackspace as r, applyInput as i, applyText as a, toSlots as o } from "../../lib/codeInput.js";
|
|
5
|
+
import { useId as s, useRef as c, useState as l } from "react";
|
|
6
|
+
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
6
7
|
//#region src/components/ui/CodeInput.tsx
|
|
7
|
-
function
|
|
8
|
-
let [
|
|
9
|
-
value:
|
|
10
|
-
defaultValue:
|
|
11
|
-
onChange:
|
|
12
|
-
}),
|
|
13
|
-
let e =
|
|
8
|
+
function f({ value: f, defaultValue: p = "", onValueChange: m, onComplete: h, length: g = 6, error: _, invalid: v, disabled: y, autoFocus: b, name: x, "aria-label": S = "Verification code", "aria-describedby": C, className: w, ref: T, ...E }) {
|
|
9
|
+
let [D, O] = t({
|
|
10
|
+
value: f,
|
|
11
|
+
defaultValue: p,
|
|
12
|
+
onChange: m
|
|
13
|
+
}), k = c([]), A = s(), j = v || !!_, [M, N] = l(() => {
|
|
14
|
+
let e = o(D, g);
|
|
14
15
|
return {
|
|
15
16
|
proposed: e,
|
|
16
17
|
shown: e
|
|
17
18
|
};
|
|
18
|
-
}),
|
|
19
|
-
value:
|
|
20
|
-
length:
|
|
19
|
+
}), P = (e) => e.length === g && e.join("") === D, [F, I] = l({
|
|
20
|
+
value: D,
|
|
21
|
+
length: g
|
|
21
22
|
});
|
|
22
|
-
if ((
|
|
23
|
-
value:
|
|
24
|
-
length:
|
|
25
|
-
}), !M
|
|
26
|
-
let e =
|
|
27
|
-
|
|
23
|
+
if ((F.value !== D || F.length !== g) && (I({
|
|
24
|
+
value: D,
|
|
25
|
+
length: g
|
|
26
|
+
}), !P(M.proposed) && !P(M.shown))) {
|
|
27
|
+
let e = o(D, g);
|
|
28
|
+
N({
|
|
28
29
|
proposed: e,
|
|
29
30
|
shown: e
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
|
-
let
|
|
33
|
-
function
|
|
34
|
-
let t =
|
|
33
|
+
let L = P(M.proposed) ? M.proposed : P(M.shown) ? M.shown : o(D, g);
|
|
34
|
+
function R(e) {
|
|
35
|
+
let t = k.current[Math.max(0, Math.min(e, g - 1))];
|
|
35
36
|
t?.focus(), t?.select();
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
+
function z(e) {
|
|
38
39
|
if (!e) return;
|
|
39
|
-
|
|
40
|
+
N({
|
|
40
41
|
proposed: e.slots,
|
|
41
|
-
shown:
|
|
42
|
+
shown: L
|
|
42
43
|
});
|
|
43
44
|
let t = e.slots.join("");
|
|
44
|
-
|
|
45
|
+
O(t), e.slots.every(Boolean) && h?.(t), R(e.focus);
|
|
45
46
|
}
|
|
46
|
-
function
|
|
47
|
-
t.key === "Backspace" ? (t.preventDefault(),
|
|
47
|
+
function B(e, t) {
|
|
48
|
+
t.key === "Backspace" ? (t.preventDefault(), z(r(L, e))) : t.key === "ArrowLeft" ? (t.preventDefault(), R(e - 1)) : t.key === "ArrowRight" && (t.preventDefault(), R(e + 1));
|
|
48
49
|
}
|
|
49
|
-
return /* @__PURE__ */
|
|
50
|
-
ref:
|
|
51
|
-
...
|
|
52
|
-
className: e("flex flex-col gap-1.5",
|
|
50
|
+
return /* @__PURE__ */ d("div", {
|
|
51
|
+
ref: T,
|
|
52
|
+
...E,
|
|
53
|
+
className: e("flex flex-col gap-1.5", w),
|
|
53
54
|
children: [
|
|
54
|
-
/* @__PURE__ */
|
|
55
|
+
/* @__PURE__ */ u("div", {
|
|
55
56
|
role: "group",
|
|
56
|
-
"aria-label":
|
|
57
|
+
"aria-label": S,
|
|
57
58
|
className: "flex justify-between gap-2",
|
|
58
|
-
children:
|
|
59
|
+
children: L.map((t, r) => /* @__PURE__ */ u("input", {
|
|
59
60
|
ref: (e) => {
|
|
60
|
-
|
|
61
|
+
k.current[r] = e;
|
|
61
62
|
},
|
|
62
63
|
type: "text",
|
|
63
64
|
inputMode: "numeric",
|
|
64
|
-
autoComplete:
|
|
65
|
-
autoFocus:
|
|
66
|
-
disabled:
|
|
67
|
-
"aria-label": `Digit ${
|
|
68
|
-
"aria-invalid":
|
|
69
|
-
"aria-describedby":
|
|
65
|
+
autoComplete: r === 0 ? "one-time-code" : "off",
|
|
66
|
+
autoFocus: b && r === 0,
|
|
67
|
+
disabled: y,
|
|
68
|
+
"aria-label": `Digit ${r + 1} of ${g}`,
|
|
69
|
+
"aria-invalid": j || void 0,
|
|
70
|
+
"aria-describedby": n(C, _ ? A : void 0),
|
|
70
71
|
value: t,
|
|
71
72
|
onFocus: (e) => e.target.select(),
|
|
72
|
-
onChange: (e) =>
|
|
73
|
-
onKeyDown: (e) =>
|
|
73
|
+
onChange: (e) => z(i(L, r, e.target.value, e.target.selectionStart)),
|
|
74
|
+
onKeyDown: (e) => B(r, e),
|
|
74
75
|
onPaste: (e) => {
|
|
75
|
-
e.preventDefault(),
|
|
76
|
+
e.preventDefault(), z(a(L, r, e.clipboardData.getData("text")));
|
|
76
77
|
},
|
|
77
|
-
className: e("bg-bg-secondary text-text-primary h-10 w-10 rounded-md border text-center font-mono text-sm", "transition-colors duration-[100ms]", "focus:border-accent focus:outline-none", "disabled:cursor-not-allowed disabled:opacity-40",
|
|
78
|
-
},
|
|
78
|
+
className: e("bg-bg-secondary text-text-primary h-10 w-10 min-w-0 shrink rounded-md border text-center font-mono text-sm", "transition-colors duration-[100ms]", "focus:border-accent focus:outline-none", "disabled:cursor-not-allowed disabled:opacity-40", j ? "border-danger" : "border-border")
|
|
79
|
+
}, r))
|
|
79
80
|
}),
|
|
80
|
-
|
|
81
|
+
x && /* @__PURE__ */ u("input", {
|
|
81
82
|
type: "hidden",
|
|
82
|
-
name:
|
|
83
|
-
value:
|
|
84
|
-
disabled:
|
|
83
|
+
name: x,
|
|
84
|
+
value: D,
|
|
85
|
+
disabled: y
|
|
85
86
|
}),
|
|
86
|
-
|
|
87
|
-
id:
|
|
87
|
+
_ && /* @__PURE__ */ u("p", {
|
|
88
|
+
id: A,
|
|
88
89
|
role: "alert",
|
|
89
90
|
className: "text-2xs text-danger-fg",
|
|
90
|
-
children:
|
|
91
|
+
children: _
|
|
91
92
|
})
|
|
92
93
|
]
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
//#endregion
|
|
96
|
-
export {
|
|
97
|
+
export { f as CodeInput };
|
|
@@ -5,7 +5,7 @@ export interface TextInputProps extends ComponentPropsWithRef<"input"> {
|
|
|
5
5
|
label?: string;
|
|
6
6
|
/** Error message shown next to the label; also marks the input invalid and turns the border red. */
|
|
7
7
|
error?: string;
|
|
8
|
-
/** Helper text shown
|
|
8
|
+
/** Helper text shown below the label and linked via `aria-describedby`. */
|
|
9
9
|
hint?: string;
|
|
10
10
|
/** Opt-in larger control, or inherit ControlSizeProvider. */
|
|
11
11
|
controlSize?: ControlSize;
|
|
@@ -15,11 +15,6 @@ function a({ label: a, error: o, icon: s, className: c, id: l, readOnly: u, hint
|
|
|
15
15
|
return /* @__PURE__ */ i("div", {
|
|
16
16
|
className: "flex flex-col gap-1.5",
|
|
17
17
|
children: [
|
|
18
|
-
d && /* @__PURE__ */ r("p", {
|
|
19
|
-
id: x,
|
|
20
|
-
className: "text-text-secondary text-xs",
|
|
21
|
-
children: d
|
|
22
|
-
}),
|
|
23
18
|
(a || o) && /* @__PURE__ */ i("div", {
|
|
24
19
|
className: "flex items-center justify-between",
|
|
25
20
|
children: [a && /* @__PURE__ */ r("label", {
|
|
@@ -32,6 +27,11 @@ function a({ label: a, error: o, icon: s, className: c, id: l, readOnly: u, hint
|
|
|
32
27
|
children: o
|
|
33
28
|
})]
|
|
34
29
|
}),
|
|
30
|
+
d && /* @__PURE__ */ r("p", {
|
|
31
|
+
id: x,
|
|
32
|
+
className: "text-text-secondary text-xs",
|
|
33
|
+
children: d
|
|
34
|
+
}),
|
|
35
35
|
/* @__PURE__ */ i("div", {
|
|
36
36
|
className: "relative",
|
|
37
37
|
children: [s && /* @__PURE__ */ r("span", {
|