@momo-kits/stepper 0.0.19 → 0.0.24

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