@momo-kits/stepper 0.0.61-rc.1 → 0.0.62-alpha.2
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/Stepper.js +188 -300
- package/package.json +2 -2
package/Stepper.js
CHANGED
|
@@ -1,356 +1,244 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Colors,
|
|
3
|
+
Image,
|
|
4
|
+
Radius,
|
|
5
|
+
Spacing,
|
|
6
|
+
Text,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
} from '@momo-kits/core-v2';
|
|
3
9
|
import PropTypes from 'prop-types';
|
|
4
|
-
import
|
|
10
|
+
import React, { useState } from 'react';
|
|
11
|
+
import { StyleSheet, TextInput as Input, View } from 'react-native';
|
|
5
12
|
|
|
6
13
|
const minus =
|
|
7
14
|
'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
|
|
8
15
|
const plus =
|
|
9
16
|
'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_plus_circle.png';
|
|
10
17
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
width: 28, // height: 24
|
|
68
|
-
},
|
|
69
|
-
icon: {
|
|
70
|
-
width: 24,
|
|
71
|
-
height: 24,
|
|
72
|
-
resizeMode: 'contain',
|
|
73
|
-
},
|
|
74
|
-
text: 'SubTitle',
|
|
75
|
-
},
|
|
76
|
-
small: {
|
|
77
|
-
size: {
|
|
78
|
-
...styles.borderBox,
|
|
79
|
-
width: 20, // height: 16
|
|
80
|
-
},
|
|
81
|
-
icon: {
|
|
82
|
-
width: 16,
|
|
83
|
-
height: 16,
|
|
84
|
-
resizeMode: 'contain',
|
|
85
|
-
},
|
|
86
|
-
text: 'Caption',
|
|
87
|
-
},
|
|
18
|
+
const Quantity = (props) => {
|
|
19
|
+
const {
|
|
20
|
+
disabled,
|
|
21
|
+
min = 0,
|
|
22
|
+
max = 5,
|
|
23
|
+
defaultValue = 0,
|
|
24
|
+
size,
|
|
25
|
+
onChange,
|
|
26
|
+
onIncreasePress,
|
|
27
|
+
onDecreasePress,
|
|
28
|
+
isInput = false,
|
|
29
|
+
step = 1,
|
|
30
|
+
style,
|
|
31
|
+
} = props;
|
|
32
|
+
|
|
33
|
+
const [value, setValue] = useState(defaultValue);
|
|
34
|
+
|
|
35
|
+
const getStyle = (size) => {
|
|
36
|
+
switch (size) {
|
|
37
|
+
case 'medium':
|
|
38
|
+
return {
|
|
39
|
+
button: {
|
|
40
|
+
width: 28,
|
|
41
|
+
height: 28,
|
|
42
|
+
borderRadius: Radius.M + Radius.XXS,
|
|
43
|
+
},
|
|
44
|
+
icon: { width: 24, height: 24 },
|
|
45
|
+
input: {
|
|
46
|
+
minWidth: 28,
|
|
47
|
+
minHeight: 24,
|
|
48
|
+
borderRadius: Radius.S,
|
|
49
|
+
},
|
|
50
|
+
text: {
|
|
51
|
+
fontSize: 12,
|
|
52
|
+
lineHeight: 16,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
case 'large':
|
|
56
|
+
return {
|
|
57
|
+
button: {
|
|
58
|
+
width: 36,
|
|
59
|
+
height: 36,
|
|
60
|
+
borderRadius: Radius.L + Radius.XXS,
|
|
61
|
+
},
|
|
62
|
+
icon: { width: 24, height: 24 },
|
|
63
|
+
input: {
|
|
64
|
+
minWidth: 32,
|
|
65
|
+
minHeight: 26,
|
|
66
|
+
borderRadius: Radius.S,
|
|
67
|
+
},
|
|
68
|
+
text: {
|
|
69
|
+
fontSize: 12,
|
|
70
|
+
lineHeight: 16,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
88
74
|
};
|
|
89
|
-
return objStyle[type] || objStyle.medium;
|
|
90
|
-
};
|
|
91
75
|
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
width: 32,
|
|
97
|
-
height: 24, // height: 26
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
medium: {
|
|
101
|
-
size: {
|
|
102
|
-
width: 28,
|
|
103
|
-
height: 24, // height: 24
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
small: {
|
|
107
|
-
size: {
|
|
108
|
-
width: 20,
|
|
109
|
-
height: 16, // height: 16
|
|
110
|
-
},
|
|
111
|
-
},
|
|
76
|
+
const validateValue = (value) => {
|
|
77
|
+
if (value < min) value = min;
|
|
78
|
+
if (value > max) value = max;
|
|
79
|
+
return value;
|
|
112
80
|
};
|
|
113
|
-
return objStyle[type] || objStyle.medium;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export default class Quantity extends Component {
|
|
117
|
-
constructor(props) {
|
|
118
|
-
super(props);
|
|
119
|
-
this.state = {
|
|
120
|
-
value: props.defaultValue || props.min,
|
|
121
|
-
ownUpdate: false,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
81
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.state.value,
|
|
130
|
-
'increase',
|
|
131
|
-
this.props.min,
|
|
132
|
-
this.props.max,
|
|
133
|
-
),
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
componentWillUnmount() {
|
|
138
|
-
Keyboard.removeAllListeners('keyboardDidHide');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
static getDerivedStateFromProps(nextProps, prevState) {
|
|
142
|
-
const { value = undefined } = this?.props || {};
|
|
143
|
-
if (prevState.ownUpdate) {
|
|
144
|
-
return {
|
|
145
|
-
ownUpdate: false,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
if (nextProps.value !== value && nextProps.value !== prevState.value) {
|
|
149
|
-
return { value: nextProps.value };
|
|
82
|
+
const onDecrease = () => {
|
|
83
|
+
let newValue = value;
|
|
84
|
+
if (value > min) {
|
|
85
|
+
newValue = value - step;
|
|
150
86
|
}
|
|
151
|
-
|
|
152
|
-
}
|
|
87
|
+
if (newValue < min) newValue = min;
|
|
153
88
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
onChange && typeof onChange === 'function' && onChange(value, type)
|
|
158
|
-
);
|
|
159
|
-
};
|
|
89
|
+
if (onDecreasePress && typeof onDecreasePress === 'function')
|
|
90
|
+
onDecreasePress(newValue);
|
|
160
91
|
|
|
161
|
-
|
|
162
|
-
const { isIncreaseValue, isDecreaseValue } = this.props;
|
|
163
|
-
const value = {
|
|
164
|
-
increase: isIncreaseValue ? parseInt(step) : 0,
|
|
165
|
-
decrease: isDecreaseValue ? parseInt(step) : 0,
|
|
166
|
-
};
|
|
167
|
-
return value[key];
|
|
92
|
+
setValue(newValue);
|
|
168
93
|
};
|
|
169
94
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
ownUpdate: true,
|
|
175
|
-
},
|
|
176
|
-
() => {
|
|
177
|
-
this.onChangeValue(newValue, type);
|
|
178
|
-
},
|
|
179
|
-
);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
checkData = (value, type, min, max) => () => {
|
|
183
|
-
if (value < min) {
|
|
184
|
-
this.setState({ value: min, ownUpdate: true }, () => {
|
|
185
|
-
this.onChangeValue(value, type);
|
|
186
|
-
});
|
|
187
|
-
} else if (value > max) {
|
|
188
|
-
this.setState({ value: max, ownUpdate: true }, () => {
|
|
189
|
-
this.onChangeValue(value, type);
|
|
190
|
-
});
|
|
95
|
+
const onIncrease = () => {
|
|
96
|
+
let newValue = value;
|
|
97
|
+
if (value < max) {
|
|
98
|
+
newValue = value + step;
|
|
191
99
|
}
|
|
100
|
+
if (newValue > max) newValue = max;
|
|
101
|
+
|
|
102
|
+
if (onIncreasePress && typeof onIncreasePress === 'function')
|
|
103
|
+
onIncreasePress(newValue);
|
|
192
104
|
|
|
193
|
-
|
|
105
|
+
setValue(newValue);
|
|
194
106
|
};
|
|
195
107
|
|
|
196
|
-
|
|
197
|
-
(
|
|
198
|
-
()
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
? parseInt(value) + this.getValue('increase', step)
|
|
205
|
-
: parseInt(value) - this.getValue('decrease', step);
|
|
206
|
-
if (typeof onConditionCheck === 'function') {
|
|
207
|
-
const passCondition = onConditionCheck(newValue, type);
|
|
208
|
-
if (passCondition) {
|
|
209
|
-
this.setValue(newValue, type);
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
this.setValue(newValue, type);
|
|
213
|
-
}
|
|
214
|
-
} else {
|
|
215
|
-
this.onChangeValue(value, type);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
108
|
+
const onPressButton = (type) => {
|
|
109
|
+
if (type === 'plus') onIncrease();
|
|
110
|
+
else onDecrease();
|
|
111
|
+
};
|
|
112
|
+
const renderButton = (type, size, icon) => {
|
|
113
|
+
let disabledStatus = props.disabled;
|
|
114
|
+
if (type === 'plus' && value === max) disabledStatus = true;
|
|
115
|
+
if (type === 'minus' && value === min) disabledStatus = true;
|
|
218
116
|
|
|
219
|
-
|
|
220
|
-
const { value } = this.state;
|
|
221
|
-
const {
|
|
222
|
-
style,
|
|
223
|
-
valueStyle,
|
|
224
|
-
size,
|
|
225
|
-
tintColor,
|
|
226
|
-
isIncreaseValue,
|
|
227
|
-
isSingle,
|
|
228
|
-
iconStyle,
|
|
229
|
-
isInput,
|
|
230
|
-
disabled,
|
|
231
|
-
step,
|
|
232
|
-
} = this.props;
|
|
233
|
-
const { min } = this.props || 1;
|
|
234
|
-
const { max } = this.props || 999;
|
|
235
|
-
if (isSingle && value === 0) {
|
|
117
|
+
if (onPressButton)
|
|
236
118
|
return (
|
|
237
|
-
<
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
119
|
+
<TouchableOpacity
|
|
120
|
+
disabled={disabledStatus}
|
|
121
|
+
onPress={() => onPressButton(type)}
|
|
122
|
+
style={[getStyle(size)?.button, styles.button]}>
|
|
123
|
+
<Image
|
|
124
|
+
source={icon}
|
|
125
|
+
style={[
|
|
126
|
+
getStyle(size)?.icon,
|
|
127
|
+
styles.icon,
|
|
128
|
+
disabledStatus && styles.disabledButton,
|
|
129
|
+
]}
|
|
244
130
|
/>
|
|
245
|
-
</
|
|
131
|
+
</TouchableOpacity>
|
|
246
132
|
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const onChangeText = (value) => {
|
|
136
|
+
let newValue = validateValue(parseInt(value)) || '0';
|
|
137
|
+
if (value.length > 1 && value[0] === 0) {
|
|
138
|
+
newValue = value.substring(1);
|
|
247
139
|
}
|
|
248
|
-
const TextComp = Text[getStyle(size).text];
|
|
249
140
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
<View
|
|
261
|
-
style={[styles.numberBox, getStyle(size).size, valueStyle]}>
|
|
141
|
+
if (onChange && typeof onChange === 'function') onChange(newValue);
|
|
142
|
+
|
|
143
|
+
setValue(newValue);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<View style={style}>
|
|
148
|
+
<View style={styles.container}>
|
|
149
|
+
{renderButton('minus', size, minus)}
|
|
150
|
+
<View style={styles.inputContainer}>
|
|
262
151
|
{isInput ? (
|
|
263
|
-
<
|
|
152
|
+
<Input
|
|
153
|
+
textAlign="center"
|
|
154
|
+
keyboardType="number-pad"
|
|
155
|
+
inputMode="numeric"
|
|
156
|
+
selectionColor={Colors.pink_03}
|
|
264
157
|
style={[
|
|
158
|
+
getStyle(size)?.input,
|
|
159
|
+
styles.input,
|
|
160
|
+
disabled && styles.disabledInput,
|
|
265
161
|
{
|
|
266
|
-
|
|
267
|
-
|
|
162
|
+
fontSize: size === 'small' ? 10 : 12,
|
|
163
|
+
color: Colors.black_17,
|
|
268
164
|
},
|
|
269
|
-
getSize(size).size,
|
|
270
165
|
]}
|
|
271
|
-
underlineColorAndroid="transparent"
|
|
272
166
|
value={value.toString()}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
keyboardType="number-pad"
|
|
276
|
-
editable={!disabled}
|
|
277
|
-
onChangeText={(text) => {
|
|
278
|
-
if (text[0] !== '0') {
|
|
279
|
-
this.setValue(text);
|
|
280
|
-
}
|
|
281
|
-
}}
|
|
282
|
-
onEndEditing={this.checkData(
|
|
283
|
-
value,
|
|
284
|
-
'increase',
|
|
285
|
-
min,
|
|
286
|
-
max,
|
|
287
|
-
)}
|
|
167
|
+
onChangeText={onChangeText}
|
|
168
|
+
defaultValue={defaultValue.toString()}
|
|
288
169
|
/>
|
|
289
170
|
) : (
|
|
290
|
-
<
|
|
291
|
-
{
|
|
292
|
-
|
|
171
|
+
<View
|
|
172
|
+
style={[
|
|
173
|
+
getStyle(size)?.input,
|
|
174
|
+
styles.input,
|
|
175
|
+
disabled && styles.disabledInput,
|
|
176
|
+
]}>
|
|
177
|
+
<Text style={getStyle(size)?.text}>
|
|
178
|
+
{value.toString()}
|
|
179
|
+
</Text>
|
|
180
|
+
</View>
|
|
293
181
|
)}
|
|
294
182
|
</View>
|
|
295
|
-
|
|
296
|
-
tintColor={tintColor}
|
|
297
|
-
style={iconStyle}
|
|
298
|
-
size={size}
|
|
299
|
-
disabled={value >= max || !isIncreaseValue || disabled}
|
|
300
|
-
onPress={this.onPress(true, step)}
|
|
301
|
-
icon={plus}
|
|
302
|
-
/>
|
|
183
|
+
{renderButton('plus', size, plus)}
|
|
303
184
|
</View>
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
185
|
+
</View>
|
|
186
|
+
);
|
|
187
|
+
};
|
|
307
188
|
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
189
|
+
const styles = StyleSheet.create({
|
|
190
|
+
button: {
|
|
191
|
+
backgroundColor: Colors.black_03,
|
|
192
|
+
justifyContent: 'center',
|
|
193
|
+
alignItems: 'center',
|
|
194
|
+
},
|
|
195
|
+
icon: {
|
|
196
|
+
tintColor: Colors.pink_03,
|
|
197
|
+
},
|
|
198
|
+
container: {
|
|
199
|
+
flexDirection: 'row',
|
|
200
|
+
},
|
|
201
|
+
input: {
|
|
202
|
+
borderWidth: 1,
|
|
203
|
+
borderColor: Colors.black_04,
|
|
204
|
+
marginHorizontal: Spacing.M,
|
|
205
|
+
justifyContent: 'center',
|
|
206
|
+
alignItems: 'center',
|
|
207
|
+
paddingHorizontal: Spacing.XS,
|
|
208
|
+
},
|
|
209
|
+
inputContainer: {
|
|
210
|
+
alignItems: 'center',
|
|
211
|
+
justifyContent: 'center',
|
|
212
|
+
},
|
|
213
|
+
disabledButton: {
|
|
214
|
+
tintColor: Colors.black_08,
|
|
215
|
+
},
|
|
216
|
+
disabledInput: {
|
|
217
|
+
opacity: 0.4,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
323
220
|
|
|
324
221
|
Quantity.propTypes = {
|
|
325
|
-
size: PropTypes.oneOf(['large', 'medium'
|
|
222
|
+
size: PropTypes.oneOf(['large', 'medium']),
|
|
326
223
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
327
|
-
valueStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
328
224
|
min: PropTypes.number,
|
|
329
225
|
max: PropTypes.number,
|
|
330
|
-
value: PropTypes.number,
|
|
331
226
|
defaultValue: PropTypes.number,
|
|
332
227
|
onChange: PropTypes.func,
|
|
333
|
-
isChangeValue: PropTypes.bool,
|
|
334
|
-
isIncreaseValue: PropTypes.bool,
|
|
335
|
-
isDecreaseValue: PropTypes.bool,
|
|
336
|
-
isSingle: PropTypes.bool,
|
|
337
228
|
disabled: PropTypes.bool,
|
|
338
|
-
tintColor: PropTypes.string,
|
|
339
|
-
iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
340
229
|
isInput: PropTypes.bool,
|
|
341
230
|
step: PropTypes.number,
|
|
231
|
+
onIncreasePress: PropTypes.func,
|
|
232
|
+
onDecreasePress: PropTypes.func,
|
|
342
233
|
};
|
|
343
234
|
|
|
344
235
|
Quantity.defaultProps = {
|
|
345
|
-
min:
|
|
346
|
-
max:
|
|
347
|
-
isChangeValue: true,
|
|
348
|
-
isIncreaseValue: true,
|
|
349
|
-
isDecreaseValue: true,
|
|
350
|
-
isSingle: false,
|
|
236
|
+
min: 0,
|
|
237
|
+
max: 5,
|
|
351
238
|
size: 'medium',
|
|
352
|
-
tintColor: Colors.pink_05_b,
|
|
353
239
|
isInput: false,
|
|
354
240
|
disabled: false,
|
|
355
241
|
step: 1,
|
|
356
242
|
};
|
|
243
|
+
|
|
244
|
+
export default Quantity;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/stepper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.62-alpha.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@momo-kits/core": ">=0.0.5-beta",
|
|
8
|
+
"@momo-kits/core-v2": ">=0.0.5-beta",
|
|
9
9
|
"prop-types": "^15.7.2",
|
|
10
10
|
"react": "16.9.0",
|
|
11
11
|
"react-native": ">=0.55"
|