Skip to content

Commit 6f61e01

Browse files
committed
fix
1 parent c1c990a commit 6f61e01

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

src/components/Stepper/index.tsx

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ export default function Stepper({
3333
loading
3434
}: IProps) {
3535
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);
3939
const animationDiv = document.getElementById('loading');
4040
const animationBackground = document.getElementById('loading-background');
4141

42-
const plusBtProps = {
42+
const handleIncrementBtProps = {
4343
className: classnames(baseClass, [{ disabled }, { theme }]),
4444
style: {}
4545
};
46-
const minusBtProps = {
46+
const handleDecrementProps = {
4747
className: classnames(baseClass, [{ disabled }, { theme }]),
4848
style: {}
4949
};
@@ -75,13 +75,13 @@ export default function Stepper({
7575
setValue(value + 1);
7676
}
7777
};
78-
const handleMinus = () => {
78+
const handleDecrement = () => {
7979
const canMinus = value - step;
8080
if (loading) {
8181
ReactDOM.findDOMNode(animationDiv).style.opacity = 1;
8282
ReactDOM.findDOMNode(animationBackground).style.opacity = 1;
8383

84-
const handleMinus = () => {
84+
const Decrement = () => {
8585
if (step) {
8686
setValue(value - step);
8787
ReactDOM.findDOMNode(animationDiv).style.opacity = 0;
@@ -92,7 +92,7 @@ export default function Stepper({
9292
ReactDOM.findDOMNode(animationBackground).style.opacity = 0;
9393
}
9494
};
95-
setTimeout(handleMinus, 2000);
95+
setTimeout(Decrement, 2000);
9696
} else if (step) {
9797
if (canMinus >= 0) {
9898
setValue(value - step);
@@ -104,37 +104,47 @@ export default function Stepper({
104104
}
105105
};
106106
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 {
108118
setValue(Number(e.target.value));
109119
}
110120
};
111121
useEffect(() => {
112122
if (value === 0 || value === min) {
113-
setMinus(true);
123+
setIsMinus(true);
114124
} else if (value === max) {
115-
setPlus(true);
125+
setIsPlus(true);
116126
} else {
117-
setMinus(false);
118-
setPlus(false);
127+
setIsMinus(false);
128+
setIsPlus(false);
119129
}
120130
}, [value, max, min]);
121131

122132
if (disabled) {
123-
Object.assign(minusBtProps, { disabled });
124-
Object.assign(plusBtProps, { disabled });
133+
Object.assign(handleDecrementProps, { disabled });
134+
Object.assign(handleIncrementBtProps, { disabled });
125135
Object.assign(inputProps, { disabled });
126136
}
127137
if (theme) {
128-
Object.assign(plusBtProps, {
138+
Object.assign(handleIncrementBtProps, {
129139
style: {
130-
...plusBtProps.style,
140+
...handleIncrementBtProps.style,
131141
background: '#ee0a24',
132142
color: 'white'
133143
}
134144
});
135-
Object.assign(minusBtProps, {
145+
Object.assign(handleDecrementProps, {
136146
style: {
137-
...minusBtProps.style,
147+
...handleDecrementProps.style,
138148
border: '1px solid #ee0a24',
139149
color: '#ee0a24',
140150
background: 'white'
@@ -151,16 +161,16 @@ export default function Stepper({
151161
if (size) {
152162
const Size = `${size}px`;
153163

154-
Object.assign(minusBtProps, {
164+
Object.assign(handleDecrementProps, {
155165
style: {
156-
...minusBtProps.style,
166+
...handleDecrementProps.style,
157167
width: Size,
158168
height: Size
159169
}
160170
});
161-
Object.assign(plusBtProps, {
171+
Object.assign(handleIncrementBtProps, {
162172
style: {
163-
...plusBtProps.style,
173+
...handleIncrementBtProps.style,
164174
width: Size,
165175
height: Size
166176
}
@@ -176,33 +186,41 @@ export default function Stepper({
176186

177187
useEffect(() => {
178188
if (disableInput) {
179-
setInput(true);
189+
setIsInput(true);
180190
}
181191
}, [disableInput]);
182192
useEffect(() => {
183193
if (disabled) {
184-
setMinus(true);
194+
setIsMinus(true);
185195
}
186196
}, [disabled]);
187197
useEffect(() => {
188198
if (disabled) {
189-
setPlus(true);
199+
setIsPlus(true);
190200
}
191201
}, [disabled]);
192202

193203
return (
194204
<div className='step-container'>
195-
<button onClick={handleMinus} {...minusBtProps} disabled={minus}>
205+
<button
206+
onClick={handleDecrement}
207+
{...handleDecrementProps}
208+
disabled={isMinus}
209+
>
196210
-
197211
</button>
198212
<input
199213
value={value}
200214
{...inputProps}
201215
onChange={handleInputChange}
202-
disabled={Input}
216+
disabled={isInput}
203217
/>
204218

205-
<button onClick={handleIncrement} {...plusBtProps} disabled={plus}>
219+
<button
220+
onClick={handleIncrement}
221+
{...handleIncrementBtProps}
222+
disabled={isPlus}
223+
>
206224
+
207225
</button>
208226
{loading && (

0 commit comments

Comments
 (0)