Skip to content

Commit ebd4fc8

Browse files
committed
add
1 parent 6069d2a commit ebd4fc8

File tree

2 files changed

+60
-63
lines changed

2 files changed

+60
-63
lines changed

src/components/Stepper/index.scss

+19-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ $baseClass: 'vant-stepper';
1818
display: flex;
1919
justify-content: center;
2020
align-items: center;
21-
img{
21+
margin: 0px;
22+
padding: 0px;
23+
img {
2224
width: 12px;
2325
height: auto;
2426
}
@@ -52,8 +54,8 @@ $baseClass: 'vant-stepper';
5254
border: 4px solid rgba(0, 0, 0, 0.1);
5355
border-left-color: white;
5456
border-radius: 50%;
55-
width: 25px;
56-
height: 25px;
57+
width: 28px;
58+
height: 28px;
5759
animation: donut-spin 1.2s linear infinite;
5860
position: relative;
5961

@@ -71,12 +73,13 @@ $baseClass: 'vant-stepper';
7173
border-radius: 10px;
7274
margin: auto;
7375
opacity: 0;
76+
7477
}
7578
}
7679

7780
button.#{$baseClass} {
78-
width: 25px;
79-
height: 25px;
81+
width: 28px;
82+
height: 28px;
8083
text-align: center;
8184
display: flex;
8285
justify-content: center;
@@ -90,19 +93,25 @@ button.#{$baseClass} {
9093
&__theme {
9194
border-radius: 50%;
9295
outline: none;
93-
}
96+
width: 22px;
97+
height: 22px;
98+
background-color: rgb(132, 225, 241);
99+
}
100+
94101
}
95102
input.#{$baseClass} {
96-
width: 30px;
97-
height: 25px;
103+
width: 32px;
104+
height: 28px;
98105

99106
&__disableInput {
100107
cursor: not-allowed;
101108
opacity: $button-disabled-opacity;
102109
}
103110
&__theme {
104111
border-radius: 50%;
105-
112+
width: 32px;
113+
height: 22px;
114+
background-color: white;
106115
}
107116
}
108117
.step-container button p {
@@ -116,3 +125,4 @@ input.#{$baseClass} {
116125
font-size: 20px;
117126
margin: 0;
118127
}
128+

src/components/Stepper/index.tsx

+41-54
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export default function Stepper({
3939
const animationDiv = document.getElementById('loading');
4040
const animationBackground = document.getElementById('loading-background');
4141
const [minusBt, setMinusBt] = useState({});
42+
const [plusBt, setPlusBt] = useState({});
43+
const [inputBt, setInputBt] = useState({});
4244

4345
const handleIncrementBtProps = {
4446
className: classnames(baseClass, [{ disabled }, { theme }]),
@@ -49,7 +51,7 @@ export default function Stepper({
4951
style: {}
5052
};
5153
const inputProps = {
52-
className: classnames(baseClass, [{ disableInput }]),
54+
className: classnames(baseClass, [{ disableInput }, { theme }]),
5355
style: {}
5456
};
5557

@@ -135,67 +137,50 @@ export default function Stepper({
135137
}
136138
}, [disabled, value, max, min, handleDecrementProps, handleIncrementBtProps]);
137139
useEffect(() => {
138-
if (value === 0) {
139-
const btStyle = { cursor: 'not-allowed', opacity: '0.2' };
140-
setMinusBt(btStyle);
140+
if (size) {
141+
const Size = `${size}px`;
142+
setMinusBt({ width: Size, height: Size });
143+
setInputBt({ width: Size, height: Size });
144+
setPlusBt({ width: Size, height: Size });
145+
if (value === 0 || value === min) {
146+
const btStyle = {
147+
cursor: 'not-allowed',
148+
width: Size,
149+
height: Size,
150+
opacity: '0.2'
151+
};
152+
setMinusBt(btStyle);
153+
} else if (value === max) {
154+
const btStyle = {
155+
cursor: 'not-allowed',
156+
width: Size,
157+
height: Size,
158+
opacity: '0.2'
159+
};
160+
setPlusBt(btStyle);
161+
} else {
162+
setMinusBt({ width: Size, height: Size });
163+
setInputBt({ width: Size, height: Size });
164+
setPlusBt({ width: Size, height: Size });
165+
}
141166
} else {
142-
setMinusBt({});
167+
if (value === 0 || value === min) {
168+
const btStyle = { cursor: 'not-allowed', opacity: '0.2' };
169+
setMinusBt(btStyle);
170+
} else if (value === max) {
171+
const btStyle = { cursor: 'not-allowed', opacity: '0.2' };
172+
setPlusBt(btStyle);
173+
} else {
174+
setMinusBt({});
175+
setPlusBt({});
176+
}
143177
}
144178
}, [value]);
145179

146180
if (disabled) {
147181
Object.assign(handleDecrementProps, { disabled });
148182
Object.assign(handleIncrementBtProps, { disabled });
149183
}
150-
if (theme) {
151-
Object.assign(handleIncrementBtProps, {
152-
style: {
153-
...handleIncrementBtProps.style,
154-
background: '#ee0a24',
155-
color: 'white'
156-
}
157-
});
158-
Object.assign(handleDecrementProps, {
159-
style: {
160-
...handleDecrementProps.style,
161-
border: '1px solid #ee0a24',
162-
color: '#ee0a24',
163-
background: 'white'
164-
}
165-
});
166-
Object.assign(inputProps, {
167-
style: {
168-
...inputProps.style,
169-
background: 'white'
170-
}
171-
});
172-
}
173-
174-
if (size) {
175-
const Size = `${size}px`;
176-
177-
Object.assign(handleDecrementProps, {
178-
style: {
179-
...handleDecrementProps.style,
180-
width: Size,
181-
height: Size
182-
}
183-
});
184-
Object.assign(handleIncrementBtProps, {
185-
style: {
186-
...handleIncrementBtProps.style,
187-
width: Size,
188-
height: Size
189-
}
190-
});
191-
Object.assign(inputProps, {
192-
style: {
193-
...inputProps.style,
194-
width: Size,
195-
height: Size
196-
}
197-
});
198-
}
199184

200185
useEffect(() => {
201186
if (disableInput) {
@@ -222,12 +207,14 @@ export default function Stepper({
222207
{...inputProps}
223208
onChange={handleInputChange}
224209
disabled={isInput}
210+
style={inputBt}
225211
/>
226212

227213
<button
228214
onClick={handleIncrement}
229215
{...handleIncrementBtProps}
230216
disabled={isPlus}
217+
style={plusBt}
231218
>
232219
<img
233220
src='https://res.cloudinary.com/dlapk94rx/image/upload/v1595307854/icons8-plus-24_wnv2uo.png'

0 commit comments

Comments
 (0)