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