virtual-ui-lib 1.0.23 → 1.0.24
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.
- package/dist/index.js +77 -2
- package/dist/index.mjs +75 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,7 +39,8 @@ __export(index_exports, {
|
|
|
39
39
|
GridLayout: () => GridLayout,
|
|
40
40
|
ImageUploadPreview: () => ImageUploadPreview,
|
|
41
41
|
Loader: () => Loader,
|
|
42
|
-
Navbar: () => Navbar
|
|
42
|
+
Navbar: () => Navbar,
|
|
43
|
+
OTPInput: () => OTPInput
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(index_exports);
|
|
45
46
|
|
|
@@ -647,6 +648,79 @@ var Loader = ({
|
|
|
647
648
|
`)
|
|
648
649
|
);
|
|
649
650
|
};
|
|
651
|
+
|
|
652
|
+
// src/components/OTPInput/OTPInput.jsx
|
|
653
|
+
var import_react12 = __toESM(require("react"));
|
|
654
|
+
var OTPInput = ({
|
|
655
|
+
length = 4,
|
|
656
|
+
bg = "#0f172a",
|
|
657
|
+
borderColorDefault = "#4b5563",
|
|
658
|
+
borderColorFocus = "#2563eb",
|
|
659
|
+
borderColorError = "#e11d48",
|
|
660
|
+
borderColorSuccess = "#059669",
|
|
661
|
+
color = "#f1f5f9",
|
|
662
|
+
radius = "8px",
|
|
663
|
+
onChange,
|
|
664
|
+
error = false,
|
|
665
|
+
success = false
|
|
666
|
+
}) => {
|
|
667
|
+
const [otp, setOtp] = (0, import_react12.useState)(Array(length).fill(""));
|
|
668
|
+
const inputRefs = (0, import_react12.useRef)(Array(length).fill().map(() => import_react12.default.createRef()));
|
|
669
|
+
(0, import_react12.useEffect)(() => {
|
|
670
|
+
inputRefs.current[0].current.focus();
|
|
671
|
+
}, []);
|
|
672
|
+
const handleChange = (index, value) => {
|
|
673
|
+
if (/[^0-9]/.test(value)) return;
|
|
674
|
+
const newOtp = [...otp];
|
|
675
|
+
newOtp[index] = value;
|
|
676
|
+
setOtp(newOtp);
|
|
677
|
+
onChange(newOtp.join(""));
|
|
678
|
+
if (value && index < length - 1) {
|
|
679
|
+
inputRefs.current[index + 1].current.focus();
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
const handleKeyDown = (index, event) => {
|
|
683
|
+
if (event.key === "Backspace" && !otp[index] && index > 0) {
|
|
684
|
+
inputRefs.current[index - 1].current.focus();
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
const handlePaste = (event) => {
|
|
688
|
+
const pastedData = event.clipboardData.getData("text").split("").slice(0, length);
|
|
689
|
+
const newOtp = pastedData.map((char, index) => char.match(/\d/) ? char : "");
|
|
690
|
+
setOtp(newOtp);
|
|
691
|
+
newOtp.forEach((_, index) => {
|
|
692
|
+
if (inputRefs.current[index]) {
|
|
693
|
+
inputRefs.current[index].current.focus();
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
onChange(newOtp.join(""));
|
|
697
|
+
event.preventDefault();
|
|
698
|
+
};
|
|
699
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", { style: { display: "flex", justifyContent: "center", gap: "10px" }, onPaste: handlePaste }, otp.map((value, index) => /* @__PURE__ */ import_react12.default.createElement(
|
|
700
|
+
"input",
|
|
701
|
+
{
|
|
702
|
+
key: index,
|
|
703
|
+
ref: inputRefs.current[index],
|
|
704
|
+
value,
|
|
705
|
+
onChange: (e) => handleChange(index, e.target.value),
|
|
706
|
+
onKeyDown: (event) => handleKeyDown(index, event),
|
|
707
|
+
style: {
|
|
708
|
+
width: "40px",
|
|
709
|
+
height: "50px",
|
|
710
|
+
borderRadius: radius,
|
|
711
|
+
border: `2px solid ${error ? borderColorError : success ? borderColorSuccess : index === otp.findIndex((v) => v !== "") ? borderColorFocus : borderColorDefault}`,
|
|
712
|
+
background: bg,
|
|
713
|
+
color,
|
|
714
|
+
fontSize: "20px",
|
|
715
|
+
textAlign: "center",
|
|
716
|
+
outline: "none",
|
|
717
|
+
transition: "border-color 0.3s ease, transform 0.2s ease",
|
|
718
|
+
transform: `scale(${index === otp.findIndex((v) => v !== "") ? 1.05 : 1})`
|
|
719
|
+
},
|
|
720
|
+
autoFocus: index === 0
|
|
721
|
+
}
|
|
722
|
+
)));
|
|
723
|
+
};
|
|
650
724
|
// Annotate the CommonJS export names for ESM import in node:
|
|
651
725
|
0 && (module.exports = {
|
|
652
726
|
AlertBanner,
|
|
@@ -659,5 +733,6 @@ var Loader = ({
|
|
|
659
733
|
GridLayout,
|
|
660
734
|
ImageUploadPreview,
|
|
661
735
|
Loader,
|
|
662
|
-
Navbar
|
|
736
|
+
Navbar,
|
|
737
|
+
OTPInput
|
|
663
738
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -602,6 +602,79 @@ var Loader = ({
|
|
|
602
602
|
`)
|
|
603
603
|
);
|
|
604
604
|
};
|
|
605
|
+
|
|
606
|
+
// src/components/OTPInput/OTPInput.jsx
|
|
607
|
+
import React12, { useEffect as useEffect6, useRef as useRef2, useState as useState9 } from "react";
|
|
608
|
+
var OTPInput = ({
|
|
609
|
+
length = 4,
|
|
610
|
+
bg = "#0f172a",
|
|
611
|
+
borderColorDefault = "#4b5563",
|
|
612
|
+
borderColorFocus = "#2563eb",
|
|
613
|
+
borderColorError = "#e11d48",
|
|
614
|
+
borderColorSuccess = "#059669",
|
|
615
|
+
color = "#f1f5f9",
|
|
616
|
+
radius = "8px",
|
|
617
|
+
onChange,
|
|
618
|
+
error = false,
|
|
619
|
+
success = false
|
|
620
|
+
}) => {
|
|
621
|
+
const [otp, setOtp] = useState9(Array(length).fill(""));
|
|
622
|
+
const inputRefs = useRef2(Array(length).fill().map(() => React12.createRef()));
|
|
623
|
+
useEffect6(() => {
|
|
624
|
+
inputRefs.current[0].current.focus();
|
|
625
|
+
}, []);
|
|
626
|
+
const handleChange = (index, value) => {
|
|
627
|
+
if (/[^0-9]/.test(value)) return;
|
|
628
|
+
const newOtp = [...otp];
|
|
629
|
+
newOtp[index] = value;
|
|
630
|
+
setOtp(newOtp);
|
|
631
|
+
onChange(newOtp.join(""));
|
|
632
|
+
if (value && index < length - 1) {
|
|
633
|
+
inputRefs.current[index + 1].current.focus();
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
const handleKeyDown = (index, event) => {
|
|
637
|
+
if (event.key === "Backspace" && !otp[index] && index > 0) {
|
|
638
|
+
inputRefs.current[index - 1].current.focus();
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
const handlePaste = (event) => {
|
|
642
|
+
const pastedData = event.clipboardData.getData("text").split("").slice(0, length);
|
|
643
|
+
const newOtp = pastedData.map((char, index) => char.match(/\d/) ? char : "");
|
|
644
|
+
setOtp(newOtp);
|
|
645
|
+
newOtp.forEach((_, index) => {
|
|
646
|
+
if (inputRefs.current[index]) {
|
|
647
|
+
inputRefs.current[index].current.focus();
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
onChange(newOtp.join(""));
|
|
651
|
+
event.preventDefault();
|
|
652
|
+
};
|
|
653
|
+
return /* @__PURE__ */ React12.createElement("div", { style: { display: "flex", justifyContent: "center", gap: "10px" }, onPaste: handlePaste }, otp.map((value, index) => /* @__PURE__ */ React12.createElement(
|
|
654
|
+
"input",
|
|
655
|
+
{
|
|
656
|
+
key: index,
|
|
657
|
+
ref: inputRefs.current[index],
|
|
658
|
+
value,
|
|
659
|
+
onChange: (e) => handleChange(index, e.target.value),
|
|
660
|
+
onKeyDown: (event) => handleKeyDown(index, event),
|
|
661
|
+
style: {
|
|
662
|
+
width: "40px",
|
|
663
|
+
height: "50px",
|
|
664
|
+
borderRadius: radius,
|
|
665
|
+
border: `2px solid ${error ? borderColorError : success ? borderColorSuccess : index === otp.findIndex((v) => v !== "") ? borderColorFocus : borderColorDefault}`,
|
|
666
|
+
background: bg,
|
|
667
|
+
color,
|
|
668
|
+
fontSize: "20px",
|
|
669
|
+
textAlign: "center",
|
|
670
|
+
outline: "none",
|
|
671
|
+
transition: "border-color 0.3s ease, transform 0.2s ease",
|
|
672
|
+
transform: `scale(${index === otp.findIndex((v) => v !== "") ? 1.05 : 1})`
|
|
673
|
+
},
|
|
674
|
+
autoFocus: index === 0
|
|
675
|
+
}
|
|
676
|
+
)));
|
|
677
|
+
};
|
|
605
678
|
export {
|
|
606
679
|
AlertBanner,
|
|
607
680
|
Button,
|
|
@@ -613,5 +686,6 @@ export {
|
|
|
613
686
|
GridLayout,
|
|
614
687
|
ImageUploadPreview,
|
|
615
688
|
Loader,
|
|
616
|
-
Navbar
|
|
689
|
+
Navbar,
|
|
690
|
+
OTPInput
|
|
617
691
|
};
|