react-core-ts 1.1.21 → 1.1.23
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/ReactOTPInput.d.ts +16 -0
- package/dist/ReactOTPInput.js +125 -0
- package/dist/ReactOTPInput.js.map +1 -0
- package/dist/ReactRadioButton.d.ts +4 -0
- package/dist/ReactRadioButton.js +30 -0
- package/dist/ReactRadioButton.js.map +1 -0
- package/dist/commontypes.d.ts +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/styles/components/tooltip.css +441 -0
- package/dist/styles/global.css +2 -1
- package/dist/styles/styles/components/tooltip.css +441 -0
- package/dist/styles/styles/global.css +2 -1
- package/package.json +1 -1
- package/src/ReactOTPInput.tsx +195 -0
- package/src/ReactRadioButton.tsx +62 -0
- package/src/commontypes.ts +10 -0
- package/src/index.tsx +2 -0
- package/src/styles/components/tooltip.css +441 -0
- package/src/styles/global.css +2 -1
package/dist/styles/global.css
CHANGED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
.tooltip-container {
|
|
2
|
+
position: relative;
|
|
3
|
+
transition:
|
|
4
|
+
background-color 0.3s,
|
|
5
|
+
width 0.3s,
|
|
6
|
+
height 0.3s,
|
|
7
|
+
color 0.3s;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.bottom {
|
|
11
|
+
.tooltip {
|
|
12
|
+
position: absolute;
|
|
13
|
+
bottom: -40;
|
|
14
|
+
right: 3px;
|
|
15
|
+
transform: translateX(0%);
|
|
16
|
+
padding: 0.3em 0.6em;
|
|
17
|
+
opacity: 0;
|
|
18
|
+
width: max-content;
|
|
19
|
+
max-width: 100%;
|
|
20
|
+
z-index: 999;
|
|
21
|
+
font-size: 12px;
|
|
22
|
+
color: #fff !important;
|
|
23
|
+
pointer-events: none;
|
|
24
|
+
transition: all 0.3s;
|
|
25
|
+
border: 1px solid #e55353;
|
|
26
|
+
background-color: #e55353;
|
|
27
|
+
border-radius: 6px;
|
|
28
|
+
color: rgb(34, 34, 34);
|
|
29
|
+
|
|
30
|
+
&.info {
|
|
31
|
+
color: #ffffff !important;
|
|
32
|
+
border: 1px solid #ffffff;
|
|
33
|
+
background-color: #000000;
|
|
34
|
+
right: 1px;
|
|
35
|
+
top: 5px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&.card {
|
|
39
|
+
color: #ffffff !important;
|
|
40
|
+
border: 1px solid #ffffff;
|
|
41
|
+
background-color: #000000;
|
|
42
|
+
right: -8px;
|
|
43
|
+
top: 5px;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.tooltip::before {
|
|
48
|
+
position: absolute;
|
|
49
|
+
content: '';
|
|
50
|
+
height: 0.6em;
|
|
51
|
+
width: 0.6em;
|
|
52
|
+
right: 20px;
|
|
53
|
+
z-index: 999;
|
|
54
|
+
top: -4px;
|
|
55
|
+
border: 1px solid #e55353;
|
|
56
|
+
border-right: none;
|
|
57
|
+
border-bottom: none;
|
|
58
|
+
transform: translate(50%) rotate(45deg);
|
|
59
|
+
background-color: #e55353;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.info.tooltip::before {
|
|
63
|
+
border: 1px solid #000000;
|
|
64
|
+
background-color: #000000;
|
|
65
|
+
right: 14px;
|
|
66
|
+
position: absolute;
|
|
67
|
+
content: '';
|
|
68
|
+
height: 0.6em;
|
|
69
|
+
width: 0.6em;
|
|
70
|
+
z-index: 999;
|
|
71
|
+
top: -4px;
|
|
72
|
+
border-right: none;
|
|
73
|
+
border-bottom: none;
|
|
74
|
+
transform: translate(50%) rotate(45deg);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.card.tooltip::before {
|
|
78
|
+
border: 1px solid #000000;
|
|
79
|
+
background-color: #000000;
|
|
80
|
+
right: 14px;
|
|
81
|
+
position: absolute;
|
|
82
|
+
content: '';
|
|
83
|
+
height: 0.6em;
|
|
84
|
+
width: 0.6em;
|
|
85
|
+
z-index: 999;
|
|
86
|
+
top: -3px;
|
|
87
|
+
border-right: none;
|
|
88
|
+
border-bottom: none;
|
|
89
|
+
transform: translate(50%) rotate(45deg);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.tooltip-container:hover .tooltip {
|
|
93
|
+
top: 46px;
|
|
94
|
+
opacity: 1;
|
|
95
|
+
visibility: visible;
|
|
96
|
+
z-index: 999;
|
|
97
|
+
pointer-events: auto;
|
|
98
|
+
|
|
99
|
+
&.info {
|
|
100
|
+
top: 30px;
|
|
101
|
+
max-width: 500px;
|
|
102
|
+
position: absolute;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&.card {
|
|
106
|
+
top: 20px;
|
|
107
|
+
max-width: 300px;
|
|
108
|
+
position: absolute;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
.top-tool {
|
|
113
|
+
.tooltip {
|
|
114
|
+
position: absolute;
|
|
115
|
+
bottom: 45px !important;
|
|
116
|
+
left: 0;
|
|
117
|
+
top: auto !important;
|
|
118
|
+
transform: translateX(0%);
|
|
119
|
+
padding: 0.3em 0.6em;
|
|
120
|
+
opacity: 0;
|
|
121
|
+
width: max-content;
|
|
122
|
+
white-space: normal;
|
|
123
|
+
z-index: 999;
|
|
124
|
+
font-size: 12px;
|
|
125
|
+
max-width: 100%;
|
|
126
|
+
color: #ff681d !important;
|
|
127
|
+
pointer-events: none;
|
|
128
|
+
transition: all 0.3s;
|
|
129
|
+
border: 1px solid #ff681d;
|
|
130
|
+
background-color: #fff;
|
|
131
|
+
border-radius: 6px;
|
|
132
|
+
color: rgb(34, 34, 34);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.tooltip::before {
|
|
136
|
+
position: absolute;
|
|
137
|
+
content: '';
|
|
138
|
+
height: 0.6em;
|
|
139
|
+
width: 0.6em;
|
|
140
|
+
z-index: 999;
|
|
141
|
+
bottom: -4px;
|
|
142
|
+
border: 1px solid #ff681d;
|
|
143
|
+
border-left: none;
|
|
144
|
+
border-top: none;
|
|
145
|
+
transform: translate(50%) rotate(45deg);
|
|
146
|
+
background-color: #fff;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.tooltip-container:hover .tooltip {
|
|
150
|
+
bottom: 45px !important;
|
|
151
|
+
opacity: 1;
|
|
152
|
+
top: auto !important;
|
|
153
|
+
visibility: visible;
|
|
154
|
+
z-index: 999;
|
|
155
|
+
pointer-events: auto;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
.bottom-tool {
|
|
159
|
+
.tooltip {
|
|
160
|
+
position: absolute;
|
|
161
|
+
bottom: -40;
|
|
162
|
+
transform: translateX(0%);
|
|
163
|
+
padding: 0.3em 0.6em;
|
|
164
|
+
opacity: 0;
|
|
165
|
+
width: max-content;
|
|
166
|
+
max-width: 100%;
|
|
167
|
+
z-index: 999;
|
|
168
|
+
font-size: 12px;
|
|
169
|
+
color: #ff681d !important;
|
|
170
|
+
white-space: wrap;
|
|
171
|
+
pointer-events: none;
|
|
172
|
+
transition:
|
|
173
|
+
background-color 0.3s,
|
|
174
|
+
width 0.3s,
|
|
175
|
+
height 0.3s,
|
|
176
|
+
color 0.3s;
|
|
177
|
+
border: 1px solid #ff681d;
|
|
178
|
+
background-color: #fff;
|
|
179
|
+
border-radius: 6px;
|
|
180
|
+
color: rgb(34, 34, 34);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.tooltip::before {
|
|
184
|
+
position: absolute;
|
|
185
|
+
content: '';
|
|
186
|
+
height: 0.6em;
|
|
187
|
+
width: 0.6em;
|
|
188
|
+
z-index: 999;
|
|
189
|
+
top: -4px;
|
|
190
|
+
border: 1px solid #ff681d;
|
|
191
|
+
border-right: none;
|
|
192
|
+
border-bottom: none;
|
|
193
|
+
transform: translate(50%) rotate(45deg);
|
|
194
|
+
background-color: #fff;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.tooltip-container:hover .tooltip {
|
|
198
|
+
top: 46px;
|
|
199
|
+
opacity: 1;
|
|
200
|
+
visibility: visible;
|
|
201
|
+
z-index: 999;
|
|
202
|
+
pointer-events: auto;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.right {
|
|
207
|
+
.tooltip {
|
|
208
|
+
position: absolute;
|
|
209
|
+
top: 2.5px;
|
|
210
|
+
left: calc(100% + 9px);
|
|
211
|
+
transform: translateX(0%);
|
|
212
|
+
padding: 8px;
|
|
213
|
+
opacity: 0;
|
|
214
|
+
min-width: 200px;
|
|
215
|
+
max-width: 200px;
|
|
216
|
+
min-height: calc(100% - 16px);
|
|
217
|
+
height: auto;
|
|
218
|
+
z-index: 999;
|
|
219
|
+
font-size: 12px;
|
|
220
|
+
color: #fff !important;
|
|
221
|
+
pointer-events: none;
|
|
222
|
+
transition:
|
|
223
|
+
background-color 0.3s,
|
|
224
|
+
width 0.3s,
|
|
225
|
+
height 0.3s,
|
|
226
|
+
color 0.3s;
|
|
227
|
+
border: 1px solid #e55353;
|
|
228
|
+
background-color: #e55353;
|
|
229
|
+
border-radius: 6px;
|
|
230
|
+
color: rgb(34, 34, 34);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.tooltip-card {
|
|
234
|
+
padding: 3px 10px 4px;
|
|
235
|
+
top: -4px;
|
|
236
|
+
min-width: 175px;
|
|
237
|
+
background-color: #3d414a;
|
|
238
|
+
border: 1px solid #3d414a;
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.tooltip::before {
|
|
243
|
+
position: absolute;
|
|
244
|
+
content: '';
|
|
245
|
+
height: 0.6em;
|
|
246
|
+
width: 0.6em;
|
|
247
|
+
left: -8px;
|
|
248
|
+
top: 14px;
|
|
249
|
+
z-index: 999;
|
|
250
|
+
transform: translateY(10px);
|
|
251
|
+
border: 1px solid #e55353;
|
|
252
|
+
border-top: none;
|
|
253
|
+
border-right: none;
|
|
254
|
+
transform: translate(50%) rotate(45deg);
|
|
255
|
+
background-color: #e55353;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.tooltip-card::before {
|
|
259
|
+
top: 8px;
|
|
260
|
+
background-color: #3d414a;
|
|
261
|
+
border: 1px solid #3d414a;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.tooltip-container:hover {
|
|
265
|
+
.tooltip {
|
|
266
|
+
top: 2.5px;
|
|
267
|
+
opacity: 1;
|
|
268
|
+
visibility: visible;
|
|
269
|
+
z-index: 999;
|
|
270
|
+
pointer-events: auto;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.tooltip-card {
|
|
274
|
+
top: -4px;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.left {
|
|
280
|
+
.tooltip {
|
|
281
|
+
position: absolute;
|
|
282
|
+
top: 2.5px;
|
|
283
|
+
right: calc(100% + 9px);
|
|
284
|
+
transform: translateX(0%);
|
|
285
|
+
padding: 8px;
|
|
286
|
+
opacity: 0;
|
|
287
|
+
min-width: 200px;
|
|
288
|
+
max-width: 200px;
|
|
289
|
+
min-height: calc(100% - 16px);
|
|
290
|
+
z-index: 999;
|
|
291
|
+
font-size: 12px;
|
|
292
|
+
color: #fff !important;
|
|
293
|
+
pointer-events: none;
|
|
294
|
+
transition:
|
|
295
|
+
background-color 0.3s,
|
|
296
|
+
width 0.3s,
|
|
297
|
+
height 0.3s,
|
|
298
|
+
color 0.3s;
|
|
299
|
+
border: 1px solid #e55353;
|
|
300
|
+
background-color: #e55353;
|
|
301
|
+
border-radius: 6px;
|
|
302
|
+
color: rgb(34, 34, 34);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.tooltip::before {
|
|
306
|
+
position: absolute;
|
|
307
|
+
content: '';
|
|
308
|
+
height: 0.6em;
|
|
309
|
+
width: 0.6em;
|
|
310
|
+
right: 0px;
|
|
311
|
+
top: 14px;
|
|
312
|
+
z-index: 999;
|
|
313
|
+
transform: translateY(10px);
|
|
314
|
+
border: 1px solid #e55353;
|
|
315
|
+
border-bottom: none;
|
|
316
|
+
border-left: none;
|
|
317
|
+
transform: translate(50%) rotate(45deg);
|
|
318
|
+
background-color: #e55353;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.tooltip-container:hover .tooltip {
|
|
322
|
+
top: 2.5px;
|
|
323
|
+
opacity: 1;
|
|
324
|
+
visibility: visible;
|
|
325
|
+
z-index: 999;
|
|
326
|
+
pointer-events: auto;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.top {
|
|
331
|
+
.tooltip {
|
|
332
|
+
position: absolute;
|
|
333
|
+
top: -40;
|
|
334
|
+
left: 0;
|
|
335
|
+
transform: translateX(0%);
|
|
336
|
+
padding: 0.3em 0.6em;
|
|
337
|
+
opacity: 0;
|
|
338
|
+
width: 100%;
|
|
339
|
+
z-index: 999;
|
|
340
|
+
font-size: 12px;
|
|
341
|
+
color: #fff !important;
|
|
342
|
+
pointer-events: none;
|
|
343
|
+
transition:
|
|
344
|
+
background-color 0.3s,
|
|
345
|
+
width 0.3s,
|
|
346
|
+
height 0.3s,
|
|
347
|
+
color 0.3s;
|
|
348
|
+
border: 1px solid #e55353;
|
|
349
|
+
background-color: #e55353;
|
|
350
|
+
border-radius: 6px;
|
|
351
|
+
color: rgb(34, 34, 34);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.tooltip::before {
|
|
355
|
+
position: absolute;
|
|
356
|
+
content: '';
|
|
357
|
+
height: 0.6em;
|
|
358
|
+
width: 0.6em;
|
|
359
|
+
right: 20px;
|
|
360
|
+
z-index: 999;
|
|
361
|
+
bottom: -4px;
|
|
362
|
+
border: 1px solid #e55353;
|
|
363
|
+
border-left: none;
|
|
364
|
+
border-top: none;
|
|
365
|
+
transform: translate(50%) rotate(45deg);
|
|
366
|
+
background-color: #e55353;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.tooltip-container:hover .tooltip {
|
|
370
|
+
top: -40px;
|
|
371
|
+
opacity: 1;
|
|
372
|
+
visibility: visible;
|
|
373
|
+
z-index: 999;
|
|
374
|
+
pointer-events: auto;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
.custom-tooltip-container {
|
|
379
|
+
position: relative;
|
|
380
|
+
display: inline-block;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.custom-text {
|
|
384
|
+
font-size: 18px;
|
|
385
|
+
cursor: pointer;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.custom-tooltip {
|
|
389
|
+
position: absolute;
|
|
390
|
+
top: 100%;
|
|
391
|
+
left: 20%;
|
|
392
|
+
opacity: 0;
|
|
393
|
+
visibility: hidden;
|
|
394
|
+
font-size: 12px;
|
|
395
|
+
background: #deefff;
|
|
396
|
+
border-color: #bee0ff;
|
|
397
|
+
padding: 5px;
|
|
398
|
+
align-items: center;
|
|
399
|
+
transition:
|
|
400
|
+
opacity 0.3s,
|
|
401
|
+
visibility 0.3s,
|
|
402
|
+
top 0.3s,
|
|
403
|
+
background 0.3s;
|
|
404
|
+
z-index: 1;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.custom-tooltip::before {
|
|
408
|
+
content: '';
|
|
409
|
+
position: absolute;
|
|
410
|
+
bottom: 100%;
|
|
411
|
+
left: 20%;
|
|
412
|
+
/* Center the arrow */
|
|
413
|
+
border-width: 9px;
|
|
414
|
+
/* Slightly larger to act as border */
|
|
415
|
+
border-style: solid;
|
|
416
|
+
border-color: transparent transparent #bee0ff transparent;
|
|
417
|
+
/* Border color */
|
|
418
|
+
transform: translateX(-20%);
|
|
419
|
+
z-index: -1;
|
|
420
|
+
/* Ensure it's behind the ::after pseudo-element */
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.custom-tooltip::after {
|
|
424
|
+
content: '';
|
|
425
|
+
position: absolute;
|
|
426
|
+
bottom: 100%;
|
|
427
|
+
left: 20%;
|
|
428
|
+
border-width: 8px;
|
|
429
|
+
border-style: solid;
|
|
430
|
+
border-color: transparent transparent #deefff transparent;
|
|
431
|
+
transform: translateX(-20%);
|
|
432
|
+
z-index: 1;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.custom-tooltip-container:hover .custom-tooltip {
|
|
436
|
+
top: 100%;
|
|
437
|
+
opacity: 1;
|
|
438
|
+
visibility: visible;
|
|
439
|
+
background: #deefff;
|
|
440
|
+
transform: translate(-20%, 10px);
|
|
441
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { FieldErrors } from "react-hook-form";
|
|
3
|
+
|
|
4
|
+
type OTPInputProps = {
|
|
5
|
+
BoxLength?: number;
|
|
6
|
+
value?: string;
|
|
7
|
+
onChangeOTP: (otp: string) => void;
|
|
8
|
+
label?: string;
|
|
9
|
+
errors?: FieldErrors;
|
|
10
|
+
name: string;
|
|
11
|
+
id: string;
|
|
12
|
+
labelTitle?: string;
|
|
13
|
+
initialTime?: number;
|
|
14
|
+
callbackFn?: (data: boolean) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const OTPInput: React.FC<OTPInputProps> = ({
|
|
18
|
+
BoxLength = 6,
|
|
19
|
+
onChangeOTP,
|
|
20
|
+
value = "",
|
|
21
|
+
label,
|
|
22
|
+
errors,
|
|
23
|
+
name,
|
|
24
|
+
id,
|
|
25
|
+
labelTitle,
|
|
26
|
+
initialTime = 240,
|
|
27
|
+
callbackFn,
|
|
28
|
+
}) => {
|
|
29
|
+
// Initialize OTP state from value prop
|
|
30
|
+
const [otp, setOtp] = useState<string[]>(
|
|
31
|
+
value.split("").concat(Array(BoxLength - value.length).fill(""))
|
|
32
|
+
);
|
|
33
|
+
const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
|
|
34
|
+
const [remainingTime, setRemainingTime] = useState<number>(initialTime);
|
|
35
|
+
const [isTimerCompleted, setIsTimerCompleted] = useState<boolean>(false);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
// Synchronize local otp state with value prop changes
|
|
39
|
+
setOtp(value.split("").concat(Array(BoxLength - value.length).fill("")));
|
|
40
|
+
}, [value, BoxLength]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (otp) onChangeOTP(otp.join(""));
|
|
44
|
+
}, [otp]);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (remainingTime > 0) {
|
|
48
|
+
const timerId = setInterval(() => {
|
|
49
|
+
setRemainingTime((prev) => prev - 1);
|
|
50
|
+
}, 1000);
|
|
51
|
+
|
|
52
|
+
return () => clearInterval(timerId);
|
|
53
|
+
} else {
|
|
54
|
+
setIsTimerCompleted(true);
|
|
55
|
+
}
|
|
56
|
+
}, [remainingTime]);
|
|
57
|
+
|
|
58
|
+
const formatTime = (time: number) => {
|
|
59
|
+
const minutes = Math.floor(time / 60);
|
|
60
|
+
const seconds = time % 60;
|
|
61
|
+
return `${minutes}:${seconds < 10 ? `0${seconds}` : seconds}`;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const handleChange = (
|
|
65
|
+
e: React.ChangeEvent<HTMLInputElement>,
|
|
66
|
+
index: number
|
|
67
|
+
) => {
|
|
68
|
+
const value = e.target.value;
|
|
69
|
+
if (/[^0-9]/.test(value)) return;
|
|
70
|
+
|
|
71
|
+
const newOtp = [...otp];
|
|
72
|
+
newOtp[index] = value;
|
|
73
|
+
setOtp(newOtp);
|
|
74
|
+
|
|
75
|
+
if (value !== "" && index < BoxLength - 1) {
|
|
76
|
+
inputRefs.current[index + 1]?.focus(); // Move focus to next input
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handleKeyDown = (
|
|
81
|
+
e: React.KeyboardEvent<HTMLInputElement>,
|
|
82
|
+
index: number
|
|
83
|
+
) => {
|
|
84
|
+
if (e.key === "Backspace" && otp[index] === "" && index > 0) {
|
|
85
|
+
inputRefs.current[index - 1]?.focus(); // Move focus to previous input
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {
|
|
90
|
+
const pastedData = e.clipboardData.getData("Text").slice(0, BoxLength);
|
|
91
|
+
if (/[^0-9]/.test(pastedData)) return;
|
|
92
|
+
|
|
93
|
+
const newOtp = pastedData
|
|
94
|
+
.split("")
|
|
95
|
+
.concat(Array(BoxLength - pastedData.length).fill(""));
|
|
96
|
+
setOtp(newOtp);
|
|
97
|
+
|
|
98
|
+
// Move focus to the last filled input field
|
|
99
|
+
const lastIndex = newOtp.findIndex((val) => val === "");
|
|
100
|
+
if (lastIndex !== -1) {
|
|
101
|
+
inputRefs.current[lastIndex]?.focus();
|
|
102
|
+
} else {
|
|
103
|
+
inputRefs.current[BoxLength - 1]?.focus();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const getErrors = (err: any) => {
|
|
108
|
+
let errMsg = "";
|
|
109
|
+
if (err.message) {
|
|
110
|
+
errMsg = err?.message;
|
|
111
|
+
}
|
|
112
|
+
return errMsg;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const handleError = (data: any) => {
|
|
116
|
+
if (
|
|
117
|
+
getErrors(data[name]) === "required" ||
|
|
118
|
+
getErrors(data[name]) === "Required"
|
|
119
|
+
) {
|
|
120
|
+
return `${label ?? labelTitle} is ${getErrors(data[name])}`;
|
|
121
|
+
} else {
|
|
122
|
+
return getErrors(data[name]) ?? "";
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// Reset time function added
|
|
127
|
+
const resetTimer = () => {
|
|
128
|
+
setRemainingTime(initialTime);
|
|
129
|
+
setIsTimerCompleted(false);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handleResend = () => {
|
|
133
|
+
if (isTimerCompleted) {
|
|
134
|
+
callbackFn?.(isTimerCompleted);
|
|
135
|
+
resetTimer();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div>
|
|
141
|
+
{label && (
|
|
142
|
+
<div className="mb-2 me-2">
|
|
143
|
+
<label className={`text-grey-label font-normal text-common`}>
|
|
144
|
+
{label}
|
|
145
|
+
</label>
|
|
146
|
+
</div>
|
|
147
|
+
)}
|
|
148
|
+
<div className="flex flex-col w-fit">
|
|
149
|
+
<div className="flex gap-x-5 ">
|
|
150
|
+
{Array(BoxLength)
|
|
151
|
+
.fill("")
|
|
152
|
+
.map((_, index) => (
|
|
153
|
+
<input
|
|
154
|
+
key={index}
|
|
155
|
+
name={name}
|
|
156
|
+
id={id}
|
|
157
|
+
type="text"
|
|
158
|
+
value={otp[index]}
|
|
159
|
+
onChange={(e) => handleChange(e, index)}
|
|
160
|
+
onKeyDown={(e) => handleKeyDown(e, index)}
|
|
161
|
+
onPaste={handlePaste}
|
|
162
|
+
ref={(el) => (inputRefs.current[index] = el)}
|
|
163
|
+
maxLength={1}
|
|
164
|
+
onFocus={(e) => (e.target.style.borderColor = "#667085")}
|
|
165
|
+
onBlur={(e) => (e.target.style.borderColor = "#D0D5DD")}
|
|
166
|
+
className="w-[54px] h-10 text-center text-lg border border-[#D0D5DD] focus:border-[#667085] transition-colors duration-200 outline-none rounded-sm"
|
|
167
|
+
/>
|
|
168
|
+
))}
|
|
169
|
+
</div>
|
|
170
|
+
<div className="flex items-center pt-3">
|
|
171
|
+
<p className="text-common text-[#475467]">Didn't receive a code? </p>
|
|
172
|
+
<span
|
|
173
|
+
className={`text-common text-[#003C71] ml-2 ${
|
|
174
|
+
!isTimerCompleted ? "cursor-not-allowed" : "cursor-pointer"
|
|
175
|
+
}`}
|
|
176
|
+
onClick={handleResend}
|
|
177
|
+
>
|
|
178
|
+
Resend Code
|
|
179
|
+
</span>
|
|
180
|
+
</div>
|
|
181
|
+
<div>
|
|
182
|
+
<span className="text-common text-[#475467]">
|
|
183
|
+
Remaining Time: {formatTime(remainingTime)}
|
|
184
|
+
</span>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<div className="flex justify-center items-center text-[#F94110] text-base font-medium ">
|
|
188
|
+
{errors && errors[name] && <span> {handleError(errors)}</span>}
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export default OTPInput;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { RadioProps } from "./commontypes";
|
|
4
|
+
|
|
5
|
+
const Radio: React.FC<RadioProps> = ({
|
|
6
|
+
name,
|
|
7
|
+
id,
|
|
8
|
+
label,
|
|
9
|
+
checked,
|
|
10
|
+
value = undefined,
|
|
11
|
+
handleChange,
|
|
12
|
+
disabled = false,
|
|
13
|
+
customLabel,
|
|
14
|
+
}) => {
|
|
15
|
+
const radioRef = useRef<HTMLInputElement>(null);
|
|
16
|
+
const onChange = (e: any) => {
|
|
17
|
+
handleChange?.(e);
|
|
18
|
+
};
|
|
19
|
+
const labelClick = () => {
|
|
20
|
+
if (radioRef.current) {
|
|
21
|
+
radioRef.current.click();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return (
|
|
25
|
+
<div
|
|
26
|
+
className={`labels label-text flex items-center justify-start ${
|
|
27
|
+
!customLabel && "gap-0"
|
|
28
|
+
} ${disabled ? " opacity-70" : ""} `}
|
|
29
|
+
>
|
|
30
|
+
<div>
|
|
31
|
+
<label
|
|
32
|
+
className={`radio-button ${
|
|
33
|
+
disabled ? "cursor-not-allowed" : "cursor-pointer"
|
|
34
|
+
}`}
|
|
35
|
+
>
|
|
36
|
+
<input
|
|
37
|
+
type="radio"
|
|
38
|
+
checked={checked}
|
|
39
|
+
disabled={disabled}
|
|
40
|
+
ref={radioRef}
|
|
41
|
+
name={name}
|
|
42
|
+
data-testid="app-common-radio"
|
|
43
|
+
value={value}
|
|
44
|
+
id={id}
|
|
45
|
+
onChange={onChange}
|
|
46
|
+
/>
|
|
47
|
+
<span className="radio"></span>
|
|
48
|
+
</label>{" "}
|
|
49
|
+
</div>
|
|
50
|
+
<div
|
|
51
|
+
className={`text-common font-normal cursor-pointer ${
|
|
52
|
+
checked ? "text-secondary" : ""
|
|
53
|
+
}`}
|
|
54
|
+
onClick={labelClick}
|
|
55
|
+
>
|
|
56
|
+
{label}
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default Radio;
|