virtual-ui-lib 1.0.38 → 1.0.39

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 CHANGED
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/index.js
30
30
  var index_exports = {};
31
31
  __export(index_exports, {
32
+ OtpInput: () => OtpInput,
32
33
  StatCard: () => StatCard,
33
34
  ToastNotification: () => ToastNotification
34
35
  });
@@ -162,8 +163,80 @@ var StatCard = ({
162
163
  margin: "10px 0"
163
164
  } }, change >= 0 ? "+" + change + "%" : change + "%"), /* @__PURE__ */ import_react2.default.createElement("svg", { style: { marginTop: "12px" }, width: "100%", height: "30", viewBox: "0 0 100 30", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ import_react2.default.createElement("polyline", { fill: "none", stroke: change >= 0 ? accent : negativeAccent, strokeWidth: "2", points: "0,15 10,10 20,20 30,15 40,22 50,8 60,18 70,15 80,18 90,10 100,15" })));
164
165
  };
166
+
167
+ // src/components/OtpInput/OtpInput.jsx
168
+ var import_react3 = __toESM(require("react"));
169
+ var OtpInput = ({
170
+ length = 6,
171
+ boxSize = "48px",
172
+ borderColor = "#7c3aed",
173
+ bgColor = "#1e293b",
174
+ textColor = "#f1f5f9",
175
+ radius = "8px",
176
+ onComplete
177
+ }) => {
178
+ const [otp, setOtp] = (0, import_react3.useState)(Array(length).fill(""));
179
+ const inputsRef = (0, import_react3.useRef)([]);
180
+ const handleChange = (index, value) => {
181
+ if (/\d/.test(value) || value === "") {
182
+ const newOtp = [...otp];
183
+ newOtp[index] = value;
184
+ setOtp(newOtp);
185
+ if (value !== "" && index < length - 1) {
186
+ inputsRef.current[index + 1].focus();
187
+ } else if (value === "" && index > 0) {
188
+ inputsRef.current[index - 1].focus();
189
+ }
190
+ if (newOtp.join("").length === length) {
191
+ onComplete(newOtp.join(""));
192
+ }
193
+ }
194
+ };
195
+ const handlePaste = (e) => {
196
+ const pastedData = e.clipboardData.getData("text").slice(0, length).split("");
197
+ const newOtp = Array(length).fill("").map((_, index) => pastedData[index] || "");
198
+ setOtp(newOtp);
199
+ if (newOtp.join("").length === length) {
200
+ onComplete(newOtp.join(""));
201
+ }
202
+ e.preventDefault();
203
+ };
204
+ (0, import_react3.useEffect)(() => {
205
+ inputsRef.current[0].focus();
206
+ }, []);
207
+ return /* @__PURE__ */ import_react3.default.createElement("div", { style: { display: "flex", gap: "10px", justifyContent: "center", padding: "20px", background: bgColor, borderRadius: radius, border: "1px solid rgba(255,255,255,0.1)", boxShadow: "0 4px 20px rgba(0,0,0,0.6)" }, onPaste: handlePaste }, otp.map((value, index) => /* @__PURE__ */ import_react3.default.createElement(
208
+ "input",
209
+ {
210
+ key: index,
211
+ ref: (el) => inputsRef.current[index] = el,
212
+ type: "text",
213
+ maxLength: "1",
214
+ value,
215
+ onChange: (e) => handleChange(index, e.target.value),
216
+ onFocus: (e) => e.target.select(),
217
+ onKeyDown: (e) => {
218
+ if (e.key === "Backspace" && !value && index > 0) {
219
+ inputsRef.current[index - 1].focus();
220
+ }
221
+ },
222
+ style: {
223
+ width: boxSize,
224
+ height: boxSize,
225
+ fontSize: "24px",
226
+ textAlign: "center",
227
+ borderRadius: radius,
228
+ border: `2px solid ${borderColor}`,
229
+ background: bgColor,
230
+ color: textColor,
231
+ transition: "border-color 0.2s",
232
+ outline: "none"
233
+ }
234
+ }
235
+ )), otp.join("").length === length && /* @__PURE__ */ import_react3.default.createElement("span", { style: { color: "#4ade80", fontSize: "20px" } }, "\u2705"));
236
+ };
165
237
  // Annotate the CommonJS export names for ESM import in node:
166
238
  0 && (module.exports = {
239
+ OtpInput,
167
240
  StatCard,
168
241
  ToastNotification
169
242
  });
package/dist/index.mjs CHANGED
@@ -126,7 +126,79 @@ var StatCard = ({
126
126
  margin: "10px 0"
127
127
  } }, change >= 0 ? "+" + change + "%" : change + "%"), /* @__PURE__ */ React2.createElement("svg", { style: { marginTop: "12px" }, width: "100%", height: "30", viewBox: "0 0 100 30", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2.createElement("polyline", { fill: "none", stroke: change >= 0 ? accent : negativeAccent, strokeWidth: "2", points: "0,15 10,10 20,20 30,15 40,22 50,8 60,18 70,15 80,18 90,10 100,15" })));
128
128
  };
129
+
130
+ // src/components/OtpInput/OtpInput.jsx
131
+ import React3, { useEffect as useEffect3, useRef, useState as useState3 } from "react";
132
+ var OtpInput = ({
133
+ length = 6,
134
+ boxSize = "48px",
135
+ borderColor = "#7c3aed",
136
+ bgColor = "#1e293b",
137
+ textColor = "#f1f5f9",
138
+ radius = "8px",
139
+ onComplete
140
+ }) => {
141
+ const [otp, setOtp] = useState3(Array(length).fill(""));
142
+ const inputsRef = useRef([]);
143
+ const handleChange = (index, value) => {
144
+ if (/\d/.test(value) || value === "") {
145
+ const newOtp = [...otp];
146
+ newOtp[index] = value;
147
+ setOtp(newOtp);
148
+ if (value !== "" && index < length - 1) {
149
+ inputsRef.current[index + 1].focus();
150
+ } else if (value === "" && index > 0) {
151
+ inputsRef.current[index - 1].focus();
152
+ }
153
+ if (newOtp.join("").length === length) {
154
+ onComplete(newOtp.join(""));
155
+ }
156
+ }
157
+ };
158
+ const handlePaste = (e) => {
159
+ const pastedData = e.clipboardData.getData("text").slice(0, length).split("");
160
+ const newOtp = Array(length).fill("").map((_, index) => pastedData[index] || "");
161
+ setOtp(newOtp);
162
+ if (newOtp.join("").length === length) {
163
+ onComplete(newOtp.join(""));
164
+ }
165
+ e.preventDefault();
166
+ };
167
+ useEffect3(() => {
168
+ inputsRef.current[0].focus();
169
+ }, []);
170
+ return /* @__PURE__ */ React3.createElement("div", { style: { display: "flex", gap: "10px", justifyContent: "center", padding: "20px", background: bgColor, borderRadius: radius, border: "1px solid rgba(255,255,255,0.1)", boxShadow: "0 4px 20px rgba(0,0,0,0.6)" }, onPaste: handlePaste }, otp.map((value, index) => /* @__PURE__ */ React3.createElement(
171
+ "input",
172
+ {
173
+ key: index,
174
+ ref: (el) => inputsRef.current[index] = el,
175
+ type: "text",
176
+ maxLength: "1",
177
+ value,
178
+ onChange: (e) => handleChange(index, e.target.value),
179
+ onFocus: (e) => e.target.select(),
180
+ onKeyDown: (e) => {
181
+ if (e.key === "Backspace" && !value && index > 0) {
182
+ inputsRef.current[index - 1].focus();
183
+ }
184
+ },
185
+ style: {
186
+ width: boxSize,
187
+ height: boxSize,
188
+ fontSize: "24px",
189
+ textAlign: "center",
190
+ borderRadius: radius,
191
+ border: `2px solid ${borderColor}`,
192
+ background: bgColor,
193
+ color: textColor,
194
+ transition: "border-color 0.2s",
195
+ outline: "none"
196
+ }
197
+ }
198
+ )), otp.join("").length === length && /* @__PURE__ */ React3.createElement("span", { style: { color: "#4ade80", fontSize: "20px" } }, "\u2705"));
199
+ };
129
200
  export {
201
+ OtpInput,
130
202
  StatCard,
131
203
  ToastNotification
132
204
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtual-ui-lib",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "description": "Virtual UI React Component Library",
5
5
  "author": "Ankush",
6
6
  "license": "ISC",