@momo-kits/stepper 0.0.33-beta → 0.0.36

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 CHANGED
@@ -1,12 +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
4
  import { Text, Colors, Image, TouchableOpacity } from '@momo-kits/core';
7
5
 
8
- const minus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
9
- 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';
10
10
 
11
11
  const styles = StyleSheet.create({
12
12
  container: {
@@ -19,7 +19,7 @@ const styles = StyleSheet.create({
19
19
  tintColor: Colors.pink_03,
20
20
  },
21
21
  text: {
22
- color: Colors.black_17
22
+ color: Colors.black_17,
23
23
  },
24
24
  numberBox: {
25
25
  justifyContent: 'center',
@@ -31,68 +31,121 @@ const styles = StyleSheet.create({
31
31
  justifyContent: 'center',
32
32
  alignItems: 'center',
33
33
  backgroundColor: Colors.white,
34
- borderColor: 'transparent'
34
+ borderColor: 'transparent',
35
35
  },
36
36
  borderBox: {
37
- borderColor: Colors.black_04, borderWidth: 1, borderRadius: 6
37
+ borderColor: Colors.black_04,
38
+ borderWidth: 1,
39
+ borderRadius: 6,
38
40
  },
39
41
  disabledIcon: {
40
42
  tintColor: Colors.black_09,
41
43
  },
42
44
  disabledBox: {
43
- borderColor: Colors.black_03, backgroundColor: Colors.black_03
44
- }
45
+ borderColor: Colors.black_03,
46
+ backgroundColor: Colors.black_03,
47
+ },
45
48
  });
46
49
 
47
50
  const getStyle = (type) => {
48
51
  const objStyle = {
49
52
  large: {
50
53
  size: {
51
- ...styles.borderBox, width: 32, // height: 26
54
+ ...styles.borderBox,
55
+ width: 32, // height: 26
52
56
  },
53
57
  icon: {
54
- width: 24, height: 24, resizeMode: 'contain'
58
+ width: 24,
59
+ height: 24,
60
+ resizeMode: 'contain',
55
61
  },
56
- text: 'Title'
62
+ text: 'Title',
57
63
  },
58
64
  medium: {
59
65
  size: {
60
- ...styles.borderBox, width: 28, // height: 24
66
+ ...styles.borderBox,
67
+ width: 28, // height: 24
61
68
  },
62
69
  icon: {
63
- width: 24, height: 24, resizeMode: 'contain'
70
+ width: 24,
71
+ height: 24,
72
+ resizeMode: 'contain',
64
73
  },
65
- text: 'SubTitle'
74
+ text: 'SubTitle',
66
75
  },
67
76
  small: {
68
77
  size: {
69
- ...styles.borderBox, width: 20, // height: 16
78
+ ...styles.borderBox,
79
+ width: 20, // height: 16
70
80
  },
71
81
  icon: {
72
- width: 16, height: 16, resizeMode: 'contain'
82
+ width: 16,
83
+ height: 16,
84
+ resizeMode: 'contain',
73
85
  },
74
- text: 'Caption'
75
- }
86
+ text: 'Caption',
87
+ },
88
+ };
89
+ return objStyle[type] || objStyle.medium;
90
+ };
76
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
+ },
77
112
  };
78
113
  return objStyle[type] || objStyle.medium;
79
114
  };
115
+
80
116
  export default class Quantity extends Component {
81
117
  constructor(props) {
82
118
  super(props);
83
119
  this.state = {
84
120
  value: props.defaultValue || props.min,
85
- ownUpdate: false
121
+ ownUpdate: false,
86
122
  };
87
123
  }
88
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
+
89
141
  static getDerivedStateFromProps(nextProps, prevState) {
90
142
  const { value = undefined } = this?.props || {};
91
143
  if (prevState.ownUpdate) {
92
144
  return {
93
145
  ownUpdate: false,
94
146
  };
95
- } if (nextProps.value !== value && nextProps.value !== prevState.value) {
147
+ }
148
+ if (nextProps.value !== value && nextProps.value !== prevState.value) {
96
149
  return { value: nextProps.value };
97
150
  }
98
151
  return null;
@@ -100,85 +153,151 @@ export default class Quantity extends Component {
100
153
 
101
154
  onChangeValue = (value, type) => {
102
155
  const { onChange } = this.props;
103
- return onChange && typeof onChange === 'function' && onChange(value, type);
104
- }
156
+ return (
157
+ onChange && typeof onChange === 'function' && onChange(value, type)
158
+ );
159
+ };
105
160
 
106
- getValue = (key) => {
161
+ getValue = (key, step) => {
107
162
  const { isIncreaseValue, isDecreaseValue } = this.props;
108
163
  const value = {
109
- increase: isIncreaseValue ? 1 : 0,
110
- decrease: isDecreaseValue ? 1 : 0,
164
+ increase: isIncreaseValue ? parseInt(step) : 0,
165
+ decrease: isDecreaseValue ? parseInt(step) : 0,
111
166
  };
112
167
  return value[key];
113
168
  };
114
169
 
115
- setValue = (newValue, type) => {
116
- this.setState({
117
- value: newValue,
118
- ownUpdate: true,
119
- }, () => {
120
- this.onChangeValue(newValue, type);
121
- });
122
- }
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
+ };
123
181
 
124
- onPress = (isIncrease = true) => () => {
125
- const { isChangeValue, onConditionCheck } = this.props;
126
- const { value } = this.state;
127
- const type = isIncrease ? 'increase' : 'decrease';
128
- if (isChangeValue) {
129
- const newValue = isIncrease ? value + this.getValue('increase') : value - this.getValue('decrease');
130
- if (typeof onConditionCheck === 'function') {
131
- const passCondition = onConditionCheck(newValue, type);
132
- 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 {
133
212
  this.setValue(newValue, type);
134
213
  }
135
214
  } else {
136
- this.setValue(newValue, type);
215
+ this.onChangeValue(value, type);
137
216
  }
138
- } else {
139
- this.onChangeValue(value, type);
140
- }
141
- };
217
+ };
142
218
 
143
219
  render() {
144
220
  const { value } = this.state;
145
221
  const {
146
- 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,
147
232
  } = this.props;
148
233
  const { min } = this.props || 1;
234
+ const { max } = this.props || 999;
149
235
  if (isSingle && value === 0) {
150
236
  return (
151
237
  <View style={[styles.container, style]}>
152
238
  <IconButton
153
239
  tintColor={tintColor}
154
240
  size={size}
155
- disabled={(value >= max || !isIncreaseValue)}
156
- onPress={this.onPress(true)}
241
+ disabled={value >= max || !isIncreaseValue}
242
+ onPress={this.onPress(true, step)}
157
243
  icon={plus}
158
244
  />
159
245
  </View>
160
246
  );
161
247
  }
162
248
  const TextComp = Text[getStyle(size).text];
249
+
163
250
  return (
164
251
  <View style={[styles.container, style]}>
165
252
  <IconButton
166
253
  style={iconStyle}
167
254
  tintColor={tintColor}
168
255
  size={size}
169
- disabled={value === min}
170
- onPress={this.onPress(false)}
256
+ disabled={value === min || disabled}
257
+ onPress={this.onPress(false, step)}
171
258
  icon={minus}
172
259
  />
173
- <View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
174
- <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}
292
+ </TextComp>
293
+ )}
175
294
  </View>
176
295
  <IconButton
177
296
  tintColor={tintColor}
178
297
  style={iconStyle}
179
298
  size={size}
180
- disabled={(value >= max || !isIncreaseValue)}
181
- onPress={this.onPress(true)}
299
+ disabled={value >= max || !isIncreaseValue || disabled}
300
+ onPress={this.onPress(true, step)}
182
301
  icon={plus}
183
302
  />
184
303
  </View>
@@ -186,17 +305,18 @@ export default class Quantity extends Component {
186
305
  }
187
306
  }
188
307
 
189
- const IconButton = ({
190
- disabled, onPress, icon, size, tintColor, style
191
- }) => (
308
+ const IconButton = ({ disabled, onPress, icon, size, tintColor, style }) => (
192
309
  <TouchableOpacity
193
- style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
310
+ style={[getStyle(size).size, styles.button, style]} // disabled && styles.disabledBox
194
311
  disabled={disabled}
195
- onPress={onPress}
196
- >
312
+ onPress={onPress}>
197
313
  <Image
198
314
  source={icon}
199
- style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
315
+ style={[
316
+ getStyle(size).icon,
317
+ { tintColor },
318
+ disabled && styles.disabledIcon,
319
+ ]}
200
320
  />
201
321
  </TouchableOpacity>
202
322
  );
@@ -214,8 +334,11 @@ Quantity.propTypes = {
214
334
  isIncreaseValue: PropTypes.bool,
215
335
  isDecreaseValue: PropTypes.bool,
216
336
  isSingle: PropTypes.bool,
337
+ disabled: PropTypes.bool,
217
338
  tintColor: PropTypes.string,
218
339
  iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
340
+ isInput: PropTypes.bool,
341
+ step: PropTypes.number,
219
342
  };
220
343
 
221
344
  Quantity.defaultProps = {
@@ -227,4 +350,7 @@ Quantity.defaultProps = {
227
350
  isSingle: false,
228
351
  size: 'medium',
229
352
  tintColor: Colors.pink_05_b,
353
+ isInput: false,
354
+ disabled: false,
355
+ step: 1,
230
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
- import Text from '../typography';
7
- import Colors from '../../colors';
8
- import ValueUtil from '../../utils/ValueUtil';
10
+ import Text from '../../core/components/typography';
11
+ import Colors from '../../core/colors';
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
+ }
107
144
 
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];
145
+ onChangeValue = (value, type) => {
146
+ const {onChange} = this.props;
147
+ return onChange && typeof onChange === 'function' && onChange(value, type);
148
+ };
149
+
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={ValueUtil.getImageSource(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,
232
- };
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,
319
+ };
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import Stepper from './Stepper';
2
2
 
3
- export default Stepper;
3
+ export default Stepper;
package/package.json CHANGED
@@ -1,22 +1,15 @@
1
1
  {
2
2
  "name": "@momo-kits/stepper",
3
- "version": "0.0.33-beta",
3
+ "version": "0.0.36",
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
- "devDependencies": {
14
- "metro-react-native-babel-preset": "^0.64.0",
15
- "@babel/core": "^7.12.9",
16
- "@babel/runtime": "^7.12.5"
17
- },
18
- "license": "MoMo",
19
- "jest": {
20
- "preset": "react-native"
21
- }
13
+ "devDependencies": {},
14
+ "license": "MoMo"
22
15
  }
package/publish.sh CHANGED
@@ -26,4 +26,4 @@ cd ..
26
26
  rm -rf dist
27
27
 
28
28
 
29
- echo '{"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"}'
package/babel.config.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- presets: ['module:metro-react-native-babel-preset'],
3
- };