@momo-kits/stepper 0.0.18-beta-5 → 0.0.19-beta-3

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