@momo-kits/stepper 0.0.10 → 0.0.18-beta-1

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 +278 -196
  2. package/Stepper.web.js +64 -18
  3. package/package.json +1 -1
package/Stepper.js CHANGED
@@ -1,232 +1,314 @@
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
  };
115
+
82
116
  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
- }
117
+ constructor(props) {
118
+ super(props);
119
+ this.state = {
120
+ value: props.defaultValue || props.min,
121
+ ownUpdate: false,
122
+ };
123
+ }
90
124
 
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;
125
+ static getDerivedStateFromProps(nextProps, prevState) {
126
+ const {value = undefined} = this?.props || {};
127
+ if (prevState.ownUpdate) {
128
+ return {
129
+ ownUpdate: false,
130
+ };
101
131
  }
102
-
103
- onChangeValue = (value, type) => {
104
- const { onChange } = this.props;
105
- return onChange && typeof onChange === 'function' && onChange(value, type);
132
+ if (nextProps.value !== value && nextProps.value !== prevState.value) {
133
+ return {value: nextProps.value};
106
134
  }
135
+ return null;
136
+ }
137
+
138
+ onChangeValue = (value, type) => {
139
+ const {onChange} = this.props;
140
+ return onChange && typeof onChange === 'function' && onChange(value, type);
141
+ };
107
142
 
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];
143
+ getValue = key => {
144
+ const {isIncreaseValue, isDecreaseValue} = this.props;
145
+ const value = {
146
+ increase: isIncreaseValue ? 1 : 0,
147
+ decrease: isDecreaseValue ? 1 : 0,
115
148
  };
149
+ return value[key];
150
+ };
116
151
 
117
- setValue = (newValue, type) => {
118
- this.setState({
119
- value: newValue,
120
- ownUpdate: true,
121
- }, () => {
122
- this.onChangeValue(newValue, type);
123
- });
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
+ };
165
+
166
+ if (isInput) {
167
+ if (newValue <= max && isIncreaseValue && newValue >= min) {
168
+ onValue(newValue, type);
169
+ }
170
+ } else {
171
+ onValue(newValue, type);
124
172
  }
173
+ };
125
174
 
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
- }
175
+ onPress =
176
+ (isIncrease = true) =>
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')
184
+ : value - this.getValue('decrease');
185
+ if (typeof onConditionCheck === 'function') {
186
+ const passCondition = onConditionCheck(newValue, type);
187
+ if (passCondition) {
188
+ this.setValue(newValue, type);
189
+ }
140
190
  } else {
141
- this.onChangeValue(value, type);
191
+ this.setValue(newValue, type);
142
192
  }
193
+ } else {
194
+ this.onChangeValue(value, type);
195
+ }
143
196
  };
144
197
 
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
- );
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
+ } = this.props;
212
+ const {min} = this.props || 1;
213
+ if (isSingle && value === 0) {
214
+ return (
215
+ <View style={[styles.container, style]}>
216
+ <IconButton
217
+ tintColor={tintColor}
218
+ size={size}
219
+ disabled={value >= max || !isIncreaseValue}
220
+ onPress={this.onPress(true)}
221
+ icon={plus}
222
+ />
223
+ </View>
224
+ );
188
225
  }
226
+ const TextComp = Text[getStyle(size).text];
227
+ return (
228
+ <View style={[styles.container, style]}>
229
+ <IconButton
230
+ style={iconStyle}
231
+ tintColor={tintColor}
232
+ size={size}
233
+ disabled={value === min || disabled}
234
+ onPress={this.onPress(false)}
235
+ icon={minus}
236
+ />
237
+ <View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
238
+ {isInput ? (
239
+ <TextInput
240
+ style={[{textAlignVertical: 'center'}, getSize(size).size]}
241
+ underlineColorAndroid="transparent"
242
+ value={value.toString()}
243
+ textAlign="center"
244
+ maxLength={3}
245
+ keyboardType="number-pad"
246
+ editable={!disabled}
247
+ onChangeText={text => this.setValue(text)}
248
+ />
249
+ ) : (
250
+ <TextComp weight="bold" style={styles.text}>
251
+ {value}
252
+ </TextComp>
253
+ )}
254
+ </View>
255
+ <IconButton
256
+ tintColor={tintColor}
257
+ style={iconStyle}
258
+ size={size}
259
+ disabled={value >= max || !isIncreaseValue || disabled}
260
+ onPress={this.onPress(true)}
261
+ icon={plus}
262
+ />
263
+ </View>
264
+ );
265
+ }
189
266
  }
190
267
 
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>
268
+ const IconButton = ({disabled, onPress, icon, size, tintColor, style}) => (
269
+ <TouchableOpacity
270
+ style={[getStyle(size).size, styles.button, style]} // disabled && styles.disabledBox
271
+ disabled={disabled}
272
+ onPress={onPress}>
273
+ <Image
274
+ source={icon}
275
+ style={[
276
+ getStyle(size).icon,
277
+ {tintColor},
278
+ disabled && styles.disabledIcon,
279
+ ]}
280
+ />
281
+ </TouchableOpacity>
204
282
  );
205
283
 
206
284
  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]),
285
+ size: PropTypes.oneOf(['large', 'medium', 'small']),
286
+ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
287
+ valueStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
288
+ min: PropTypes.number,
289
+ max: PropTypes.number,
290
+ value: PropTypes.number,
291
+ defaultValue: PropTypes.number,
292
+ onChange: PropTypes.func,
293
+ isChangeValue: PropTypes.bool,
294
+ isIncreaseValue: PropTypes.bool,
295
+ isDecreaseValue: PropTypes.bool,
296
+ isSingle: PropTypes.bool,
297
+ disabled: PropTypes.bool,
298
+ tintColor: PropTypes.string,
299
+ iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
300
+ isInput: PropTypes.bool,
221
301
  };
222
302
 
223
303
  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,
304
+ min: 1,
305
+ max: 100,
306
+ isChangeValue: true,
307
+ isIncreaseValue: true,
308
+ isDecreaseValue: true,
309
+ isSingle: false,
310
+ size: 'medium',
311
+ tintColor: Colors.pink_05_b,
312
+ isInput: false,
313
+ disabled: false,
232
314
  };
package/Stepper.web.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import React, { Component } from 'react';
2
2
  import {
3
- View, StyleSheet, TouchableOpacity, Image
3
+ View, StyleSheet, TouchableOpacity, Image, TextInput
4
4
  } from 'react-native';
5
5
  import PropTypes from 'prop-types';
6
6
  import Text from '../../core/components/typography';
7
7
  import Colors from '../../core/colors';
8
- import ValueUtil from '../../core/utils/ValueUtil';
9
8
 
10
9
  const minus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
11
10
  const plus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_plus_circle.png';
@@ -79,6 +78,30 @@ const getStyle = (type) => {
79
78
  };
80
79
  return objStyle[type] || objStyle.medium;
81
80
  };
81
+
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
+
100
+ };
101
+ return objStyle[type] || objStyle.medium;
102
+ };
103
+
104
+
82
105
  export default class Quantity extends Component {
83
106
  constructor(props) {
84
107
  super(props);
@@ -114,13 +137,24 @@ export default class Quantity extends Component {
114
137
  return value[key];
115
138
  };
116
139
 
117
- setValue = (newValue, type) => {
118
- this.setState({
119
- value: newValue,
120
- ownUpdate: true,
121
- }, () => {
122
- this.onChangeValue(newValue, type);
123
- });
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
+ };
150
+
151
+ if(isInput){
152
+ if((newValue <= max && isIncreaseValue) && (newValue >= min)){
153
+ onValue(newValue, type)
154
+ }
155
+ }else {
156
+ onValue(newValue, type)
157
+ }
124
158
  }
125
159
 
126
160
  onPress = (isIncrease = true) => () => {
@@ -145,7 +179,7 @@ export default class Quantity extends Component {
145
179
  render() {
146
180
  const { value } = this.state;
147
181
  const {
148
- style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle
182
+ style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle, isInput
149
183
  } = this.props;
150
184
  const { min } = this.props || 1;
151
185
  if (isSingle && value === 0) {
@@ -173,7 +207,16 @@ export default class Quantity extends Component {
173
207
  icon={minus}
174
208
  />
175
209
  <View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
176
- <TextComp weight="bold" style={styles.text}>{value}</TextComp>
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
+ }
177
220
  </View>
178
221
  <IconButton
179
222
  tintColor={tintColor}
@@ -192,14 +235,14 @@ const IconButton = ({
192
235
  disabled, onPress, icon, size, tintColor, style
193
236
  }) => (
194
237
  <TouchableOpacity
195
- style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
196
- disabled={disabled}
197
- onPress={onPress}
238
+ style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
239
+ disabled={disabled}
240
+ onPress={onPress}
198
241
  >
199
- <Image
200
- source={icon}
201
- style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
202
- />
242
+ <Image
243
+ source={icon}
244
+ style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
245
+ />
203
246
  </TouchableOpacity>
204
247
  );
205
248
 
@@ -218,6 +261,7 @@ Quantity.propTypes = {
218
261
  isSingle: PropTypes.bool,
219
262
  tintColor: PropTypes.string,
220
263
  iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
264
+ isInput: PropTypes.bool,
221
265
  };
222
266
 
223
267
  Quantity.defaultProps = {
@@ -229,4 +273,6 @@ Quantity.defaultProps = {
229
273
  isSingle: false,
230
274
  size: 'medium',
231
275
  tintColor: Colors.pink_05_b,
276
+ isInput: false
232
277
  };
278
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/stepper",
3
- "version": "0.0.10",
3
+ "version": "0.0.18-beta-1",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},