@@ -33,17 +33,17 @@ export default function Stepper({
33
33
loading
34
34
} : IProps ) {
35
35
const [ value , setValue ] = useState ( 0 ) ;
36
- const [ minus , setMinus ] = useState ( false ) ;
37
- const [ plus , setPlus ] = useState ( false ) ;
38
- const [ Input , setInput ] = useState ( false ) ;
36
+ const [ isMinus , setIsMinus ] = useState ( false ) ;
37
+ const [ isPlus , setIsPlus ] = useState ( false ) ;
38
+ const [ isInput , setIsInput ] = useState ( false ) ;
39
39
const animationDiv = document . getElementById ( 'loading' ) ;
40
40
const animationBackground = document . getElementById ( 'loading-background' ) ;
41
41
42
- const plusBtProps = {
42
+ const handleIncrementBtProps = {
43
43
className : classnames ( baseClass , [ { disabled } , { theme } ] ) ,
44
44
style : { }
45
45
} ;
46
- const minusBtProps = {
46
+ const handleDecrementProps = {
47
47
className : classnames ( baseClass , [ { disabled } , { theme } ] ) ,
48
48
style : { }
49
49
} ;
@@ -75,13 +75,13 @@ export default function Stepper({
75
75
setValue ( value + 1 ) ;
76
76
}
77
77
} ;
78
- const handleMinus = ( ) => {
78
+ const handleDecrement = ( ) => {
79
79
const canMinus = value - step ;
80
80
if ( loading ) {
81
81
ReactDOM . findDOMNode ( animationDiv ) . style . opacity = 1 ;
82
82
ReactDOM . findDOMNode ( animationBackground ) . style . opacity = 1 ;
83
83
84
- const handleMinus = ( ) => {
84
+ const Decrement = ( ) => {
85
85
if ( step ) {
86
86
setValue ( value - step ) ;
87
87
ReactDOM . findDOMNode ( animationDiv ) . style . opacity = 0 ;
@@ -92,7 +92,7 @@ export default function Stepper({
92
92
ReactDOM . findDOMNode ( animationBackground ) . style . opacity = 0 ;
93
93
}
94
94
} ;
95
- setTimeout ( handleMinus , 2000 ) ;
95
+ setTimeout ( Decrement , 2000 ) ;
96
96
} else if ( step ) {
97
97
if ( canMinus >= 0 ) {
98
98
setValue ( value - step ) ;
@@ -104,37 +104,47 @@ export default function Stepper({
104
104
}
105
105
} ;
106
106
const handleInputChange = ( e ) => {
107
- if ( e . target . value ) {
107
+ const result = e . target . value ;
108
+ if ( loading ) {
109
+ ReactDOM . findDOMNode ( animationDiv ) . style . opacity = 1 ;
110
+ ReactDOM . findDOMNode ( animationBackground ) . style . opacity = 1 ;
111
+ const changeInput = ( ) => {
112
+ setValue ( result ) ;
113
+ ReactDOM . findDOMNode ( animationDiv ) . style . opacity = 0 ;
114
+ ReactDOM . findDOMNode ( animationBackground ) . style . opacity = 0 ;
115
+ } ;
116
+ setTimeout ( changeInput , 2000 ) ;
117
+ } else {
108
118
setValue ( Number ( e . target . value ) ) ;
109
119
}
110
120
} ;
111
121
useEffect ( ( ) => {
112
122
if ( value === 0 || value === min ) {
113
- setMinus ( true ) ;
123
+ setIsMinus ( true ) ;
114
124
} else if ( value === max ) {
115
- setPlus ( true ) ;
125
+ setIsPlus ( true ) ;
116
126
} else {
117
- setMinus ( false ) ;
118
- setPlus ( false ) ;
127
+ setIsMinus ( false ) ;
128
+ setIsPlus ( false ) ;
119
129
}
120
130
} , [ value , max , min ] ) ;
121
131
122
132
if ( disabled ) {
123
- Object . assign ( minusBtProps , { disabled } ) ;
124
- Object . assign ( plusBtProps , { disabled } ) ;
133
+ Object . assign ( handleDecrementProps , { disabled } ) ;
134
+ Object . assign ( handleIncrementBtProps , { disabled } ) ;
125
135
Object . assign ( inputProps , { disabled } ) ;
126
136
}
127
137
if ( theme ) {
128
- Object . assign ( plusBtProps , {
138
+ Object . assign ( handleIncrementBtProps , {
129
139
style : {
130
- ...plusBtProps . style ,
140
+ ...handleIncrementBtProps . style ,
131
141
background : '#ee0a24' ,
132
142
color : 'white'
133
143
}
134
144
} ) ;
135
- Object . assign ( minusBtProps , {
145
+ Object . assign ( handleDecrementProps , {
136
146
style : {
137
- ...minusBtProps . style ,
147
+ ...handleDecrementProps . style ,
138
148
border : '1px solid #ee0a24' ,
139
149
color : '#ee0a24' ,
140
150
background : 'white'
@@ -151,16 +161,16 @@ export default function Stepper({
151
161
if ( size ) {
152
162
const Size = `${ size } px` ;
153
163
154
- Object . assign ( minusBtProps , {
164
+ Object . assign ( handleDecrementProps , {
155
165
style : {
156
- ...minusBtProps . style ,
166
+ ...handleDecrementProps . style ,
157
167
width : Size ,
158
168
height : Size
159
169
}
160
170
} ) ;
161
- Object . assign ( plusBtProps , {
171
+ Object . assign ( handleIncrementBtProps , {
162
172
style : {
163
- ...plusBtProps . style ,
173
+ ...handleIncrementBtProps . style ,
164
174
width : Size ,
165
175
height : Size
166
176
}
@@ -176,33 +186,41 @@ export default function Stepper({
176
186
177
187
useEffect ( ( ) => {
178
188
if ( disableInput ) {
179
- setInput ( true ) ;
189
+ setIsInput ( true ) ;
180
190
}
181
191
} , [ disableInput ] ) ;
182
192
useEffect ( ( ) => {
183
193
if ( disabled ) {
184
- setMinus ( true ) ;
194
+ setIsMinus ( true ) ;
185
195
}
186
196
} , [ disabled ] ) ;
187
197
useEffect ( ( ) => {
188
198
if ( disabled ) {
189
- setPlus ( true ) ;
199
+ setIsPlus ( true ) ;
190
200
}
191
201
} , [ disabled ] ) ;
192
202
193
203
return (
194
204
< div className = 'step-container' >
195
- < button onClick = { handleMinus } { ...minusBtProps } disabled = { minus } >
205
+ < button
206
+ onClick = { handleDecrement }
207
+ { ...handleDecrementProps }
208
+ disabled = { isMinus }
209
+ >
196
210
-
197
211
</ button >
198
212
< input
199
213
value = { value }
200
214
{ ...inputProps }
201
215
onChange = { handleInputChange }
202
- disabled = { Input }
216
+ disabled = { isInput }
203
217
/>
204
218
205
- < button onClick = { handleIncrement } { ...plusBtProps } disabled = { plus } >
219
+ < button
220
+ onClick = { handleIncrement }
221
+ { ...handleIncrementBtProps }
222
+ disabled = { isPlus }
223
+ >
206
224
+
207
225
</ button >
208
226
{ loading && (
0 commit comments