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