@momo-kits/stepper 0.0.23-beta-2 → 0.0.30

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