1
1
import React , { Component } from 'react' ;
2
2
import { render } from 'react-dom' ;
3
+
3
4
import OtpInput from '../../lib' ;
4
5
import './styles.css' ;
5
6
6
7
class Demo extends Component {
7
8
constructor ( props ) {
8
9
super ( props ) ;
10
+
9
11
this . state = {
10
12
otp : '' ,
11
13
numInputs : 4 ,
12
14
separator : '-' ,
13
15
isDisabled : false ,
14
16
hasErrored : false ,
15
17
isInputNum : false ,
18
+ minLength : 0 ,
19
+ maxLength : 40 ,
16
20
} ;
17
21
}
18
22
@@ -21,12 +25,17 @@ class Demo extends Component {
21
25
} ;
22
26
23
27
handleChange = e => {
28
+ const { minLength, maxLength } = this . state ;
24
29
let currVal = e . target . value ;
25
- if ( currVal < 0 ) currVal = 0 ;
26
- if ( currVal > 10 ) {
27
- currVal = 10 ;
28
- alert ( "No. of Inputs cannot be greater than 10" ) ;
30
+
31
+ if ( currVal < minLength || currVal > maxLength ) {
32
+ currVal = 4 ;
33
+
34
+ console . error (
35
+ `Please enter a value between ${ minLength } and ${ maxLength } `
36
+ ) ;
29
37
}
38
+
30
39
this . setState ( { [ e . target . name ] : currVal } ) ;
31
40
} ;
32
41
@@ -45,12 +54,24 @@ class Demo extends Component {
45
54
} ;
46
55
47
56
render ( ) {
48
- const { otp, numInputs, separator, isDisabled, hasErrored, isInputNum } = this . state ;
57
+ const {
58
+ otp,
59
+ numInputs,
60
+ separator,
61
+ isDisabled,
62
+ hasErrored,
63
+ isInputNum,
64
+ minLength,
65
+ maxLength,
66
+ } = this . state ;
49
67
50
68
return (
51
69
< div className = "container" >
52
70
< div className = "side-bar" >
53
- < a href = "https://github.com/ajayns/react-otp-input" target = "_blank" >
71
+ < a
72
+ href = "https://github.com/devfolioco/react-otp-input"
73
+ target = "_blank"
74
+ >
54
75
< div className = "side-bar__segment side-bar__segment--header" >
55
76
< h2 > react-otp-input</ h2 >
56
77
</ div >
@@ -64,8 +85,8 @@ class Demo extends Component {
64
85
type = "number"
65
86
value = { numInputs }
66
87
onChange = { this . handleChange }
67
- min = "0"
68
- max = "10"
88
+ min = { minLength }
89
+ max = { maxLength }
69
90
/>
70
91
</ label >
71
92
</ div >
@@ -132,7 +153,7 @@ class Demo extends Component {
132
153
</ label >
133
154
</ div >
134
155
< div className = "side-bar__segment side-bar__segment--bottom" >
135
- < a href = "https://github.com/ajayns /react-otp-input" >
156
+ < a href = "https://github.com/devfolioco /react-otp-input" >
136
157
Documentation and Source
137
158
</ a >
138
159
</ div >
0 commit comments