@alfadocs/ui-kit 0.33.0 → 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