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