@alfadocs/ui-kit 0.33.1 → 0.33.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.
@@ -1,11 +1,12 @@
1
- import { jsxs as Z, jsx as A } from "react/jsx-runtime";
2
- import { forwardRef as x, useId as ee, useRef as R, useState as te, useEffect as re, useCallback as L, useMemo as se } from "react";
1
+ import { jsxs as x, jsx as A } from "react/jsx-runtime";
2
+ import { forwardRef as ee, useId as te, useRef as R, useState as se, useEffect as re, useCallback as L, useMemo as ae } from "react";
3
3
  import { c as N } from "./index-D2ZczOXr.js";
4
- import { useTranslation as ae } from "react-i18next";
5
- import { u as oe } from "./use-controllable-state-BiY4xTzM.js";
6
- import { u as ie } from "./form-field-context-B3APVHKx.js";
7
- import { u as ne } from "./registry-nPAVE19X.js";
8
- const ce = {
4
+ import { useTranslation as oe } from "react-i18next";
5
+ import { u as ie } from "./use-controllable-state-BiY4xTzM.js";
6
+ import { u as ne } from "./use-web-otp-D_utzp6S.js";
7
+ import { u as ce } from "./form-field-context-B3APVHKx.js";
8
+ import { u as ue } from "./registry-nPAVE19X.js";
9
+ const le = {
9
10
  id: "otp-input",
10
11
  capabilities: ["edit_inline", "submit"],
11
12
  state: {
@@ -61,7 +62,7 @@ const ce = {
61
62
  description: "Sourced from the id prop."
62
63
  }
63
64
  }
64
- }, ue = N("ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]"), le = N(
65
+ }, de = N("ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]"), pe = N(
65
66
  [
66
67
  "ds:w-[var(--min-target-size)] ds:h-[var(--min-target-size)]",
67
68
  "ds:rounded-[var(--radius-sm)]",
@@ -85,89 +86,95 @@ const ce = {
85
86
  function M(e) {
86
87
  return e.replace(/[\u0660-\u0669]/g, (a) => String(a.charCodeAt(0) - 1632)).replace(/[\u06F0-\u06F9]/g, (a) => String(a.charCodeAt(0) - 1776));
87
88
  }
88
- function g(e, a) {
89
+ function y(e, a) {
89
90
  return M(e).replace(/\D/g, "").slice(0, a);
90
91
  }
91
- function de(e, a) {
92
- const m = g(e, a), l = new Array(a).fill("");
92
+ function fe(e, a) {
93
+ const m = y(e, a), l = new Array(a).fill("");
93
94
  for (let n = 0; n < m.length; n += 1)
94
95
  l[n] = m[n];
95
96
  return l;
96
97
  }
97
- const pe = x(
98
+ const me = ee(
98
99
  ({
99
100
  length: e = 6,
100
101
  value: a,
101
102
  defaultValue: m,
102
103
  onChange: l,
103
104
  onComplete: n,
104
- disabled: S,
105
- error: O,
106
- label: y,
105
+ disabled: O,
106
+ error: S,
107
+ label: w,
107
108
  id: F,
108
- className: $
109
- }, j) => {
110
- const { t: z } = ae(), v = ie(), H = ee(), K = y ? H : void 0, [_, P] = oe({
109
+ className: $,
110
+ webOtp: j = !1
111
+ }, z) => {
112
+ const { t: H } = oe(), b = ce(), W = te(), K = w ? W : void 0, [_, C] = ie({
111
113
  value: a,
112
- defaultValue: g(m ?? "", e)
113
- }), p = g(_ ?? "", e), q = de(p, e), w = v.disabled || !!S, B = v.invalid || !!O, W = B ? "error" : "default", C = R([]), I = R(p.length === e), d = R(p);
114
+ defaultValue: y(m ?? "", e)
115
+ }), p = y(_ ?? "", e), q = fe(p, e), v = b.disabled || !!O, P = b.invalid || !!S, G = P ? "error" : "default", B = R([]), I = R(p.length === e), d = R(p);
114
116
  d.current = p;
115
- const G = () => {
116
- const r = p.length;
117
- return r >= e ? e - 1 : r;
118
- }, [f, h] = te(G);
117
+ const J = () => {
118
+ const s = p.length;
119
+ return s >= e ? e - 1 : s;
120
+ }, [f, h] = se(J);
119
121
  re(() => {
120
122
  f >= e && h(e - 1);
121
123
  }, [f, e]);
122
124
  const c = L(
123
- (r) => {
124
- const t = Math.max(0, Math.min(e - 1, r));
125
+ (s) => {
126
+ const t = Math.max(0, Math.min(e - 1, s));
125
127
  h(t);
126
- const s = C.current[t];
127
- s && (s.focus(), s.select());
128
+ const r = B.current[t];
129
+ r && (r.focus(), r.select());
128
130
  },
129
131
  [e]
130
132
  ), u = L(
131
- (r) => {
132
- const t = g(r, e);
133
- P(t), d.current = t, l == null || l(t), t.length === e ? I.current || (I.current = !0, n == null || n(t)) : I.current = !1;
133
+ (s) => {
134
+ const t = y(s, e);
135
+ C(t), d.current = t, l == null || l(t), t.length === e ? I.current || (I.current = !0, n == null || n(t)) : I.current = !1;
134
136
  },
135
- [P, e, l, n]
136
- ), J = (r) => (t) => {
137
- const s = t.target.value, o = M(s).replace(/\D/g, ""), i = d.current;
137
+ [C, e, l, n]
138
+ );
139
+ ne({
140
+ enabled: j && !v,
141
+ onCode: u
142
+ });
143
+ const Q = (s) => (t) => {
144
+ const r = t.target.value, o = M(r).replace(/\D/g, ""), i = d.current;
138
145
  if (o.length === 0) {
139
- if (s === "" && r < i.length) {
140
- const T = i.slice(0, r) + i.slice(r + 1);
146
+ if (r === "" && s < i.length) {
147
+ const T = i.slice(0, s) + i.slice(s + 1);
141
148
  u(T);
142
149
  }
143
150
  return;
144
151
  }
145
- const b = i.slice(0, r), k = i.slice(r + o.length), V = (b + o + k).slice(0, e);
152
+ const g = i.slice(0, s), k = i.slice(s + o.length), V = (g + o + k).slice(0, e);
146
153
  u(V);
147
- const D = Math.min(r + o.length, e - 1);
154
+ const D = Math.min(s + o.length, e - 1);
148
155
  c(D);
149
- }, Q = (r) => (t) => {
150
- const s = d.current;
156
+ }, U = (s) => (t) => {
157
+ const r = d.current;
151
158
  if (t.key === "Backspace") {
152
- if (s[r]) {
159
+ if (r[s]) {
153
160
  t.preventDefault();
154
- const o = s.slice(0, r) + s.slice(r + 1);
161
+ const o = r.slice(0, s) + r.slice(s + 1);
155
162
  u(o);
156
163
  return;
157
164
  }
158
- if (r > 0) {
165
+ if (s > 0) {
159
166
  t.preventDefault();
160
- const o = s.slice(0, r - 1) + s.slice(r);
161
- u(o), c(r - 1);
167
+ const o = r.slice(0, s - 1) + r.slice(s);
168
+ u(o), c(s - 1);
162
169
  }
163
170
  return;
164
171
  }
165
172
  if (t.key === "ArrowLeft") {
166
- t.preventDefault(), r > 0 && c(r - 1);
173
+ t.preventDefault(), s > 0 && c(s - 1);
167
174
  return;
168
175
  }
169
176
  if (t.key === "ArrowRight") {
170
- t.preventDefault(), r < e - 1 && c(r + 1);
177
+ t.preventDefault(), s < e - 1 && c(s + 1);
171
178
  return;
172
179
  }
173
180
  if (t.key === "Home") {
@@ -175,56 +182,56 @@ const pe = x(
175
182
  return;
176
183
  }
177
184
  t.key === "End" && (t.preventDefault(), c(e - 1));
178
- }, U = (r) => (t) => {
185
+ }, X = (s) => (t) => {
179
186
  const o = t.clipboardData.getData("text").replace(/\s+/g, ""), i = M(o);
180
187
  if (!/^[0-9]+$/.test(i)) return;
181
188
  t.preventDefault();
182
- const b = d.current, k = b.slice(0, r), V = b.slice(r + i.length), D = (k + i + V).slice(0, e);
189
+ const g = d.current, k = g.slice(0, s), V = g.slice(s + i.length), D = (k + i + V).slice(0, e);
183
190
  u(D);
184
- const T = Math.min(r + i.length, e - 1);
191
+ const T = Math.min(s + i.length, e - 1);
185
192
  c(T);
186
- }, X = (r) => (t) => {
187
- h(r), t.currentTarget.select();
188
- }, E = v.id, Y = se(
193
+ }, Y = (s) => (t) => {
194
+ h(s), t.currentTarget.select();
195
+ }, E = b.id, Z = ae(
189
196
  () => ({
190
197
  getValue: () => d.current,
191
- setValue: (r) => u(r),
198
+ setValue: (s) => u(s),
192
199
  clear: () => u(""),
193
200
  focus: () => c(f),
194
201
  isComplete: () => d.current.length === e
195
202
  }),
196
203
  [u, c, f, e]
197
204
  );
198
- return ne(ce, Y, F), /* @__PURE__ */ Z("div", { className: ue({ className: $ }), children: [
199
- y ? /* @__PURE__ */ A(
205
+ return ue(le, Z, F), /* @__PURE__ */ x("div", { className: de({ className: $ }), children: [
206
+ w ? /* @__PURE__ */ A(
200
207
  "label",
201
208
  {
202
209
  id: K,
203
210
  htmlFor: `${E}-0`,
204
211
  className: "type-label ds:text-foreground",
205
- children: y
212
+ children: w
206
213
  }
207
214
  ) : null,
208
215
  /* @__PURE__ */ A(
209
216
  "div",
210
217
  {
211
- ref: j,
218
+ ref: z,
212
219
  role: "group",
213
220
  dir: "ltr",
214
221
  "aria-labelledby": K,
215
- "aria-invalid": B || void 0,
216
- "aria-describedby": v.describedBy || void 0,
217
- "aria-disabled": w || void 0,
222
+ "aria-invalid": P || void 0,
223
+ "aria-describedby": b.describedBy || void 0,
224
+ "aria-disabled": v || void 0,
218
225
  "data-component": "otp-input",
219
226
  "data-component-id": F,
220
227
  className: "ds:inline-flex ds:items-center ds:gap-[var(--spacing-sm)]",
221
- children: q.map((r, t) => {
222
- const s = !w && t === f;
228
+ children: q.map((s, t) => {
229
+ const r = !v && t === f;
223
230
  return /* @__PURE__ */ A(
224
231
  "input",
225
232
  {
226
233
  ref: (o) => {
227
- C.current[t] = o;
234
+ B.current[t] = o;
228
235
  },
229
236
  id: `${E}-${t}`,
230
237
  type: "text",
@@ -232,18 +239,18 @@ const pe = x(
232
239
  pattern: "[0-9]*",
233
240
  autoComplete: t === 0 ? "one-time-code" : "off",
234
241
  maxLength: 1,
235
- value: r,
236
- disabled: w,
237
- tabIndex: s ? 0 : -1,
238
- "aria-label": z("inputs.otp.digitLabel", {
242
+ value: s,
243
+ disabled: v,
244
+ tabIndex: r ? 0 : -1,
245
+ "aria-label": H("inputs.otp.digitLabel", {
239
246
  current: t + 1,
240
247
  total: e
241
248
  }),
242
- onChange: J(t),
243
- onKeyDown: Q(t),
244
- onPaste: U(t),
245
- onFocus: X(t),
246
- className: le({ tone: W })
249
+ onChange: Q(t),
250
+ onKeyDown: U(t),
251
+ onPaste: X(t),
252
+ onFocus: Y(t),
253
+ className: pe({ tone: G })
247
254
  },
248
255
  t
249
256
  );
@@ -253,8 +260,8 @@ const pe = x(
253
260
  ] });
254
261
  }
255
262
  );
256
- pe.displayName = "OTPInput";
263
+ me.displayName = "OTPInput";
257
264
  export {
258
- pe as O
265
+ me as O
259
266
  };
260
- //# sourceMappingURL=otp-input-BEg_sn8A.js.map
267
+ //# sourceMappingURL=otp-input-CDTWT5EK.js.map
@@ -0,0 +1,33 @@
1
+ import { useRef as f, useEffect as l } from "react";
2
+ function p({
3
+ onCode: i,
4
+ onError: o,
5
+ enabled: c = !0
6
+ }) {
7
+ const s = f(i), e = f(o);
8
+ s.current = i, e.current = o, l(() => {
9
+ if (!c || typeof window > "u" || !("OTPCredential" in window)) return;
10
+ const u = new AbortController(), a = {
11
+ otp: { transport: ["sms"] },
12
+ signal: u.signal
13
+ };
14
+ let r = !1;
15
+ return navigator.credentials.get(a).then((t) => {
16
+ if (r) return;
17
+ const n = t;
18
+ n != null && n.code && s.current(n.code);
19
+ }).catch((t) => {
20
+ var n;
21
+ r || t instanceof DOMException && t.name === "AbortError" || (n = e.current) == null || n.call(
22
+ e,
23
+ t instanceof Error ? t : new Error(String(t))
24
+ );
25
+ }), () => {
26
+ r = !0, u.abort();
27
+ };
28
+ }, [c]);
29
+ }
30
+ export {
31
+ p as u
32
+ };
33
+ //# sourceMappingURL=use-web-otp-D_utzp6S.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "packageVersion": "0.33.1",
3
+ "packageVersion": "0.33.2",
4
4
  "components": [
5
5
  {
6
6
  "kind": "component",
@@ -1,4 +1,4 @@
1
- import { O as r } from "../../_chunks/otp-input-BEg_sn8A.js";
1
+ import { O as r } from "../../_chunks/otp-input-CDTWT5EK.js";
2
2
  export {
3
3
  r as OTPInput
4
4
  };
@@ -18,6 +18,22 @@ export interface OTPInputProps {
18
18
  /** Stable id, used to address this instance from the agent runtime. */
19
19
  id?: string;
20
20
  className?: string;
21
+ /**
22
+ * Opt into Chrome-Android's WebOTP API for one-tap SMS autofill. When
23
+ * the browser surfaces a matching SMS-bound credential, the kit spreads
24
+ * the code across every digit box and fires `onComplete` automatically.
25
+ *
26
+ * Falls back silently to manual entry on Firefox / desktop / iOS — those
27
+ * platforms either don't ship the API at all or rely on the
28
+ * `autocomplete="one-time-code"` QuickType heuristic the kit already
29
+ * applies to the first input.
30
+ *
31
+ * Prerequisites the prop can't enforce: page must be HTTPS, and the SMS
32
+ * body must end with `@<origin> #<code>` on its last line (Chrome's
33
+ * spec — without it the browser refuses to surface the message).
34
+ * Default `false` so the listener stays opt-in.
35
+ */
36
+ webOtp?: boolean;
21
37
  }
22
38
  export declare const OTPInput: import("react").ForwardRefExoticComponent<OTPInputProps & import("react").RefAttributes<HTMLDivElement>>;
23
39
  //# sourceMappingURL=otp-input.d.ts.map
@@ -16,4 +16,5 @@ export { useFocusTrap, type UseFocusTrapOptions } from './use-focus-trap';
16
16
  export { useDirection, useDocumentDirection, type Direction, } from './use-direction';
17
17
  export { usePersistentState } from './use-persistent-state';
18
18
  export { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect';
19
+ export { useWebOtp, type UseWebOtpOptions } from './use-web-otp';
19
20
  //# sourceMappingURL=index.d.ts.map
@@ -1,27 +1,28 @@
1
1
  import { u as v } from "../_chunks/use-prefers-reduced-motion-BMwIQRjB.js";
2
2
  import { u as D } from "../_chunks/use-media-query-CcAx5SMM.js";
3
3
  import { u as _ } from "../_chunks/use-scroll-to-first-error-4Za-u5Nw.js";
4
- import { u as g } from "../_chunks/use-count-up-BLLetaZ8.js";
5
- import { u as w } from "../_chunks/use-locale-BkCIHujH.js";
6
- import { A as O, T as R, a as H, r as M, t as Y, u as q } from "../_chunks/use-theme-C2dHKUAN.js";
4
+ import { u as O } from "../_chunks/use-count-up-BLLetaZ8.js";
5
+ import { u as k } from "../_chunks/use-locale-BkCIHujH.js";
6
+ import { A as K, T as R, a as H, r as M, t as Y, u as q } from "../_chunks/use-theme-C2dHKUAN.js";
7
7
  import { u as G } from "../_chunks/use-controllable-state-BiY4xTzM.js";
8
8
  import { u as U } from "../_chunks/use-copy-to-clipboard-Cyfc_dlv.js";
9
9
  import { u as j } from "../_chunks/use-debounced-callback-BisrB-Fq.js";
10
10
  import { useState as x, useRef as b, useEffect as E } from "react";
11
- import { u as z, a as J } from "../_chunks/use-direction-Dp8h70PP.js";
12
- import { u as W } from "../_chunks/use-persistent-state-i23OWy6G.js";
11
+ import { u as W, a as z } from "../_chunks/use-direction-Dp8h70PP.js";
12
+ import { u as N } from "../_chunks/use-persistent-state-i23OWy6G.js";
13
13
  import { u as Z } from "../_chunks/use-isomorphic-layout-effect-BGfaCOP1.js";
14
+ import { u as ee } from "../_chunks/use-web-otp-D_utzp6S.js";
14
15
  function S(e, o) {
15
- const [t, c] = x(e), n = b(null);
16
+ const [t, c] = x(e), u = b(null);
16
17
  return E(() => {
17
18
  if (o <= 0) {
18
- n.current !== null && (clearTimeout(n.current), n.current = null), c(e);
19
+ u.current !== null && (clearTimeout(u.current), u.current = null), c(e);
19
20
  return;
20
21
  }
21
22
  const s = setTimeout(() => {
22
- c(e), n.current = null;
23
+ c(e), u.current = null;
23
24
  }, o);
24
- return n.current = s, () => clearTimeout(s);
25
+ return u.current = s, () => clearTimeout(s);
25
26
  }, [e, o]), t;
26
27
  }
27
28
  const T = [
@@ -49,57 +50,58 @@ function p(e) {
49
50
  });
50
51
  }
51
52
  function C(e, o = {}) {
52
- const { enabled: t = !0, autoFocus: c = !0, restoreFocus: n = !0 } = o, s = b(null);
53
+ const { enabled: t = !0, autoFocus: c = !0, restoreFocus: u = !0 } = o, s = b(null);
53
54
  E(() => {
54
55
  if (!t) return;
55
56
  const a = e.current;
56
57
  if (!a) return;
57
58
  if (s.current = typeof document < "u" && document.activeElement instanceof HTMLElement ? document.activeElement : null, c) {
58
- const u = p(a)[0] ?? (a.tabIndex >= -1 ? a : null);
59
- u == null || u.focus();
59
+ const n = p(a)[0] ?? (a.tabIndex >= -1 ? a : null);
60
+ n == null || n.focus();
60
61
  }
61
62
  function f(r) {
62
63
  if (r.key !== "Tab") return;
63
- const u = e.current;
64
- if (!u) return;
65
- const i = p(u);
64
+ const n = e.current;
65
+ if (!n) return;
66
+ const i = p(n);
66
67
  if (i.length === 0) {
67
68
  r.preventDefault();
68
69
  return;
69
70
  }
70
71
  const d = i[0], m = i[i.length - 1], l = document.activeElement;
71
- r.shiftKey ? (l === d || !u.contains(l)) && (r.preventDefault(), m.focus()) : (l === m || !u.contains(l)) && (r.preventDefault(), d.focus());
72
+ r.shiftKey ? (l === d || !n.contains(l)) && (r.preventDefault(), m.focus()) : (l === m || !n.contains(l)) && (r.preventDefault(), d.focus());
72
73
  }
73
74
  return a.addEventListener("keydown", f), () => {
74
- if (a.removeEventListener("keydown", f), n && s.current) {
75
+ if (a.removeEventListener("keydown", f), u && s.current) {
75
76
  const r = s.current;
76
77
  requestAnimationFrame(() => {
77
78
  r.isConnected && r.focus();
78
79
  });
79
80
  }
80
81
  };
81
- }, [t, c, n, e]);
82
+ }, [t, c, u, e]);
82
83
  }
83
84
  export {
84
- O as ACCESSIBILITY_STORAGE_KEY,
85
+ K as ACCESSIBILITY_STORAGE_KEY,
85
86
  R as THEME_CLASS,
86
87
  H as THEME_STORAGE_KEY,
87
88
  M as resolveTheme,
88
89
  Y as themeClassList,
89
90
  G as useControllableState,
90
91
  U as useCopyToClipboard,
91
- g as useCountUp,
92
+ O as useCountUp,
92
93
  j as useDebouncedCallback,
93
94
  S as useDebouncedValue,
94
- z as useDirection,
95
- J as useDocumentDirection,
95
+ W as useDirection,
96
+ z as useDocumentDirection,
96
97
  C as useFocusTrap,
97
98
  Z as useIsomorphicLayoutEffect,
98
- w as useLocale,
99
+ k as useLocale,
99
100
  D as useMediaQuery,
100
- W as usePersistentState,
101
+ N as usePersistentState,
101
102
  v as usePrefersReducedMotion,
102
103
  _ as useScrollToFirstError,
103
- q as useTheme
104
+ q as useTheme,
105
+ ee as useWebOtp
104
106
  };
105
107
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ export interface UseWebOtpOptions {
2
+ /**
3
+ * Invoked once with the full code when the browser surfaces a matching
4
+ * SMS. Setting state from inside `onCode` is safe — the hook will not
5
+ * fire again for the same lifecycle (it auto-aborts after success).
6
+ */
7
+ onCode: (code: string) => void;
8
+ /**
9
+ * Optional error sink. `AbortError` (the normal cleanup path) is NEVER
10
+ * forwarded — only real failures (permission denied, malformed SMS, etc.).
11
+ * When omitted the hook silently swallows everything so a consumer that
12
+ * doesn't care about telemetry can call the hook bare.
13
+ */
14
+ onError?: (error: Error) => void;
15
+ /**
16
+ * Gate the listener. When `false` the hook is a no-op; flipping back to
17
+ * `true` reinstalls the listener. Default `true`.
18
+ */
19
+ enabled?: boolean;
20
+ }
21
+ export declare function useWebOtp({ onCode, onError, enabled, }: UseWebOtpOptions): void;
22
+ //# sourceMappingURL=use-web-otp.d.ts.map
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ import { F as ba } from "./_chunks/form-field-BOm9hK35.js";
27
27
  import { F as Ra, u as Ia } from "./_chunks/form-field-context-B3APVHKx.js";
28
28
  import { M as Fa, m as Ea, a as La } from "./_chunks/multi-select-DOLO3K_z.js";
29
29
  import { N as ka, u as Oa } from "./_chunks/number-input-Dj5L3pXK.js";
30
- import { O as ya } from "./_chunks/otp-input-BEg_sn8A.js";
30
+ import { O as ya } from "./_chunks/otp-input-CDTWT5EK.js";
31
31
  import { P as Ma, u as Da } from "./_chunks/use-password-requirements-DsgduV1x.js";
32
32
  import { P as Va, c as va, p as Ha, a as Wa } from "./_chunks/phone-input-DfZbPPvh.js";
33
33
  import { R as Ua, r as Ka } from "./_chunks/recaptcha-widget-CFYyLSEX.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfadocs/ui-kit",
3
- "version": "0.33.1",
3
+ "version": "0.33.2",
4
4
  "type": "module",
5
5
  "description": "AlfaDocs shared design system — tokens, components, patterns, and translations for platform, booking, and alfascribe.",
6
6
  "license": "BUSL-1.1",