@momo-kits/stepper 0.0.63-beta → 0.0.65-alpha.8

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