@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 { applyBackspace as n, applyInput as r, applyText as i, toSlots as a } from "../../lib/codeInput.js";
4
- import { useId as o, useRef as s, useState as c } from "react";
5
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
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 d({ value: d, defaultValue: f = "", onValueChange: p, onComplete: m, length: h = 6, error: g, invalid: _, disabled: v, autoFocus: y, name: b, "aria-label": x = "Verification code", className: S, ref: C, ...w }) {
8
- let [T, E] = t({
9
- value: d,
10
- defaultValue: f,
11
- onChange: p
12
- }), D = s([]), O = o(), k = _ || !!g, [A, j] = c(() => {
13
- let e = a(T, h);
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
- }), M = (e) => e.length === h && e.join("") === T, [N, P] = c({
19
- value: T,
20
- length: h
19
+ }), P = (e) => e.length === g && e.join("") === D, [F, I] = l({
20
+ value: D,
21
+ length: g
21
22
  });
22
- if ((N.value !== T || N.length !== h) && (P({
23
- value: T,
24
- length: h
25
- }), !M(A.proposed) && !M(A.shown))) {
26
- let e = a(T, h);
27
- j({
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 F = M(A.proposed) ? A.proposed : M(A.shown) ? A.shown : a(T, h);
33
- function I(e) {
34
- let t = D.current[Math.max(0, Math.min(e, h - 1))];
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 L(e) {
38
+ function z(e) {
38
39
  if (!e) return;
39
- j({
40
+ N({
40
41
  proposed: e.slots,
41
- shown: F
42
+ shown: L
42
43
  });
43
44
  let t = e.slots.join("");
44
- E(t), e.slots.every(Boolean) && m?.(t), I(e.focus);
45
+ O(t), e.slots.every(Boolean) && h?.(t), R(e.focus);
45
46
  }
46
- function R(e, t) {
47
- t.key === "Backspace" ? (t.preventDefault(), L(n(F, e))) : t.key === "ArrowLeft" ? (t.preventDefault(), I(e - 1)) : t.key === "ArrowRight" && (t.preventDefault(), I(e + 1));
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__ */ u("div", {
50
- ref: C,
51
- ...w,
52
- className: e("flex flex-col gap-1.5", S),
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__ */ l("div", {
55
+ /* @__PURE__ */ u("div", {
55
56
  role: "group",
56
- "aria-label": x,
57
+ "aria-label": S,
57
58
  className: "flex justify-between gap-2",
58
- children: F.map((t, n) => /* @__PURE__ */ l("input", {
59
+ children: L.map((t, r) => /* @__PURE__ */ u("input", {
59
60
  ref: (e) => {
60
- D.current[n] = e;
61
+ k.current[r] = e;
61
62
  },
62
63
  type: "text",
63
64
  inputMode: "numeric",
64
- autoComplete: n === 0 ? "one-time-code" : "off",
65
- autoFocus: y && n === 0,
66
- disabled: v,
67
- "aria-label": `Digit ${n + 1} of ${h}`,
68
- "aria-invalid": k || void 0,
69
- "aria-describedby": g ? O : void 0,
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) => L(r(F, n, e.target.value, e.target.selectionStart)),
73
- onKeyDown: (e) => R(n, 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(), L(i(F, n, e.clipboardData.getData("text")));
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", k ? "border-danger" : "border-border")
78
- }, n))
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
- b && /* @__PURE__ */ l("input", {
81
+ x && /* @__PURE__ */ u("input", {
81
82
  type: "hidden",
82
- name: b,
83
- value: T,
84
- disabled: v
83
+ name: x,
84
+ value: D,
85
+ disabled: y
85
86
  }),
86
- g && /* @__PURE__ */ l("p", {
87
- id: O,
87
+ _ && /* @__PURE__ */ u("p", {
88
+ id: A,
88
89
  role: "alert",
89
90
  className: "text-2xs text-danger-fg",
90
- children: g
91
+ children: _
91
92
  })
92
93
  ]
93
94
  });
94
95
  }
95
96
  //#endregion
96
- export { d as CodeInput };
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 above the input and linked via `aria-describedby`. */
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", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leonardaustin/ui",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "Reusable React component library and application shell for Leonard Austin projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",