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