@dgshahr/ui-kit 0.0.27 → 0.0.28
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 +1 @@
|
|
|
1
|
-
"use client";"use strict";require('../../assets/styles.css');const l=require("react/jsx-runtime"),
|
|
1
|
+
"use client";"use strict";require('../../assets/styles.css');const l=require("react/jsx-runtime"),k=require("../../clsx-C11secjj.cjs"),y=require("react"),E=require("../Input/index.cjs"),m=require("../../TextFieldWrapper-BC0mP63G.cjs");;/* empty css */const F=j=>{const{inputsNumber:c=4,onChange:o,onEnd:r,className:C,inputsContainerClassName:I,labelContent:d,hintMessage:h,errorMessage:f,isError:v,value:n}=j,[a,p]=y.useState([]);function u(i){const e=document.getElementById(`dgs-ui-kit-otp-input-${i}`);e?.focus(),e?.select()}function w(i,e){const t=[i.code,i.key];if(t.includes("Backspace")||t.includes("Delete")){const s=[...a];s[e]="",e!==0&&(s[e-1]="",u(e-1)),p(s)}else t.includes("ArrowLeft")?u(e+1):t.includes("ArrowRight")&&u(e-1);t.includes(a[e])&&u(e)}function N(i,e){const t=i.currentTarget.value,s=[...a];t.length>1?t.split("").forEach((g,q)=>s[q]=g):s[e]=t,e+1!==c&&t?u(e+1):typeof r=="function"&&s.every(g=>!!g)&&((typeof o=="function"&&!n||typeof o!="function"&&n||typeof o!="function"&&!n||n!==s.join(""))&&r(s.join("")),u(c-1)),p(s),typeof o=="function"&&o(s.join(""))}return y.useEffect(()=>{if(n){const i=n.split("");p(i);const e=c===n.length;u(n.length),e&&typeof r=="function"&&r(n)}},[n]),l.jsxs("div",{className:k.clsx("dgs-ui-kit-space-y-2",C),children:[d?l.jsx(m.FieldLabel,{labelContent:d}):null,l.jsx("div",{className:k.clsx("dgs-ui-kit-flex dgs-ui-kit-items-center dgs-ui-kit-gap-2",I),children:Array.from(Array(c).keys()).map((i,e)=>l.jsx(E,{containerClassName:"dgs-ui-kit-w-12 dgs-ui-kit-h-12 dgs-ui-kit-p-0",className:"dgs-ui-kit-w-full dgs-ui-kit-h-full !dgs-ui-kit-text-center placeholder:!dgs-ui-kit-text-center",placeholder:"-",type:"tel",autoFocus:e===0,onChange:t=>N(t,e),onKeyUp:t=>w(t,e),id:`dgs-ui-kit-otp-input-${e}`,value:a[e],showMaxLength:!1,isError:!!f||v,autoComplete:"off"},i))}),f||h?l.jsx(m.FieldBottomInfo,{errorMessage:f,hintMessage:h}):null]})};module.exports=F;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { TextFieldBaseProps } from '../Wrappers/TextFieldWrapper/TextFieldWrapper';
|
|
3
|
-
interface OtpInputProps extends Pick<TextFieldBaseProps, 'labelContent' | 'errorMessage' | 'isError' | 'hintMessage'> {
|
|
3
|
+
export interface OtpInputProps extends Pick<TextFieldBaseProps, 'labelContent' | 'errorMessage' | 'isError' | 'hintMessage'> {
|
|
4
4
|
inputsNumber?: number;
|
|
5
5
|
onChange?: (value: string) => void;
|
|
6
6
|
onEnd?: (value: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Form/OtpInput/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAyC,KAAK,EAAE,EAAsB,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,kBAAkB,CAAC;AAE1B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Form/OtpInput/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAyC,KAAK,EAAE,EAAsB,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,kBAAkB,CAAC;AAE1B,MAAM,WAAW,aACf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,cAAc,GAAG,SAAS,GAAG,aAAa,CAAC;IAC7F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,QAAA,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CA6G/B,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,83 +1,84 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as
|
|
3
|
-
import { c as
|
|
4
|
-
import { useState as
|
|
5
|
-
import
|
|
2
|
+
import { jsxs as E, jsx as r } from "react/jsx-runtime";
|
|
3
|
+
import { c as h } from "../../clsx-OuTLNxxd.js";
|
|
4
|
+
import { useState as V, useEffect as j } from "react";
|
|
5
|
+
import B from "../Input/index.js";
|
|
6
6
|
import { F, a as A } from "../../TextFieldWrapper-Dva9vxfn.js";
|
|
7
7
|
import '../../assets/styles.css';/* empty css */
|
|
8
|
-
const
|
|
8
|
+
const U = (k) => {
|
|
9
9
|
const {
|
|
10
10
|
inputsNumber: u = 4,
|
|
11
|
-
onChange:
|
|
12
|
-
onEnd:
|
|
13
|
-
className:
|
|
14
|
-
inputsContainerClassName:
|
|
15
|
-
labelContent:
|
|
16
|
-
hintMessage:
|
|
17
|
-
errorMessage:
|
|
11
|
+
onChange: l,
|
|
12
|
+
onEnd: a,
|
|
13
|
+
className: y,
|
|
14
|
+
inputsContainerClassName: C,
|
|
15
|
+
labelContent: m,
|
|
16
|
+
hintMessage: d,
|
|
17
|
+
errorMessage: f,
|
|
18
18
|
isError: I,
|
|
19
|
-
value:
|
|
20
|
-
} =
|
|
21
|
-
function
|
|
22
|
-
const
|
|
23
|
-
|
|
19
|
+
value: o
|
|
20
|
+
} = k, [c, p] = V([]);
|
|
21
|
+
function n(i) {
|
|
22
|
+
const e = document.getElementById(`dgs-ui-kit-otp-input-${i}`);
|
|
23
|
+
e?.focus(), e?.select();
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
} else
|
|
25
|
+
function v(i, e) {
|
|
26
|
+
const t = [i.code, i.key];
|
|
27
|
+
if (t.includes("Backspace") || t.includes("Delete")) {
|
|
28
|
+
const s = [...c];
|
|
29
|
+
s[e] = "", e !== 0 && (s[e - 1] = "", n(e - 1)), p(s);
|
|
30
|
+
} else t.includes("ArrowLeft") ? n(e + 1) : t.includes("ArrowRight") && n(e - 1);
|
|
31
|
+
t.includes(c[e]) && n(e);
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
function w(i, e) {
|
|
34
|
+
const t = i.currentTarget.value, s = [...c];
|
|
35
|
+
t.length > 1 ? t.split("").forEach((g, N) => s[N] = g) : s[e] = t, e + 1 !== u && t ? n(e + 1) : typeof a == "function" && s.every((g) => !!g) && ((typeof l == "function" && !o || typeof l != "function" && o || typeof l != "function" && !o || o !== s.join("")) && a(s.join("")), n(u - 1)), p(s), typeof l == "function" && l(s.join(""));
|
|
35
36
|
}
|
|
36
|
-
return
|
|
37
|
-
if (
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
o
|
|
37
|
+
return j(() => {
|
|
38
|
+
if (o) {
|
|
39
|
+
const i = o.split("");
|
|
40
|
+
p(i);
|
|
41
|
+
const e = u === o.length;
|
|
42
|
+
n(o.length), e && typeof a == "function" && a(o);
|
|
42
43
|
}
|
|
43
|
-
}, [
|
|
44
|
-
|
|
45
|
-
/* @__PURE__ */
|
|
44
|
+
}, [o]), /* @__PURE__ */ E("div", { className: h("dgs-ui-kit-space-y-2", y), children: [
|
|
45
|
+
m ? /* @__PURE__ */ r(F, { labelContent: m }) : null,
|
|
46
|
+
/* @__PURE__ */ r(
|
|
46
47
|
"div",
|
|
47
48
|
{
|
|
48
|
-
className:
|
|
49
|
+
className: h(
|
|
49
50
|
"dgs-ui-kit-flex dgs-ui-kit-items-center dgs-ui-kit-gap-2",
|
|
50
|
-
|
|
51
|
+
C
|
|
51
52
|
),
|
|
52
|
-
children: Array.from(Array(u).keys()).map((
|
|
53
|
-
|
|
53
|
+
children: Array.from(Array(u).keys()).map((i, e) => /* @__PURE__ */ r(
|
|
54
|
+
B,
|
|
54
55
|
{
|
|
55
56
|
containerClassName: "dgs-ui-kit-w-12 dgs-ui-kit-h-12 dgs-ui-kit-p-0",
|
|
56
57
|
className: "dgs-ui-kit-w-full dgs-ui-kit-h-full !dgs-ui-kit-text-center placeholder:!dgs-ui-kit-text-center",
|
|
57
58
|
placeholder: "-",
|
|
58
59
|
type: "tel",
|
|
59
|
-
autoFocus:
|
|
60
|
-
onChange: (
|
|
61
|
-
onKeyUp: (
|
|
62
|
-
id: `dgs-ui-kit-otp-input-${
|
|
63
|
-
|
|
64
|
-
value: r[t],
|
|
60
|
+
autoFocus: e === 0,
|
|
61
|
+
onChange: (t) => w(t, e),
|
|
62
|
+
onKeyUp: (t) => v(t, e),
|
|
63
|
+
id: `dgs-ui-kit-otp-input-${e}`,
|
|
64
|
+
value: c[e],
|
|
65
65
|
showMaxLength: !1,
|
|
66
|
-
isError: !!
|
|
66
|
+
isError: !!f || I,
|
|
67
|
+
autoComplete: "off"
|
|
67
68
|
},
|
|
68
|
-
|
|
69
|
+
i
|
|
69
70
|
))
|
|
70
71
|
}
|
|
71
72
|
),
|
|
72
|
-
|
|
73
|
+
f || d ? /* @__PURE__ */ r(
|
|
73
74
|
A,
|
|
74
75
|
{
|
|
75
|
-
errorMessage:
|
|
76
|
-
hintMessage:
|
|
76
|
+
errorMessage: f,
|
|
77
|
+
hintMessage: d
|
|
77
78
|
}
|
|
78
79
|
) : null
|
|
79
80
|
] });
|
|
80
81
|
};
|
|
81
82
|
export {
|
|
82
|
-
|
|
83
|
+
U as default
|
|
83
84
|
};
|