@momo-kits/stepper 0.0.74-beta → 0.72.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 +234 -210
- package/Stepper.web.js +234 -208
- package/package.json +13 -13
- package/publish.sh +2 -2
package/Stepper.js
CHANGED
|
@@ -1,232 +1,256 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Colors,
|
|
3
|
+
Image,
|
|
4
|
+
Radius,
|
|
5
|
+
Spacing,
|
|
6
|
+
Text,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
} from '@momo-kits/core-v2';
|
|
5
9
|
import PropTypes from 'prop-types';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
} from '@momo-kits/core';
|
|
10
|
+
import React, {useState} from 'react';
|
|
11
|
+
import {StyleSheet, TextInput as Input, View} from 'react-native';
|
|
9
12
|
|
|
10
|
-
const minus =
|
|
11
|
-
|
|
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';
|
|
12
17
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
alignItems: 'center',
|
|
29
|
-
marginHorizontal: 6,
|
|
30
|
-
backgroundColor: Colors.white,
|
|
31
|
-
},
|
|
32
|
-
button: {
|
|
33
|
-
justifyContent: 'center',
|
|
34
|
-
alignItems: 'center',
|
|
35
|
-
backgroundColor: Colors.white,
|
|
36
|
-
borderColor: 'transparent'
|
|
37
|
-
},
|
|
38
|
-
borderBox: {
|
|
39
|
-
borderColor: Colors.black_04, borderWidth: 1, borderRadius: 6
|
|
40
|
-
},
|
|
41
|
-
disabledIcon: {
|
|
42
|
-
tintColor: Colors.black_09,
|
|
43
|
-
},
|
|
44
|
-
disabledBox: {
|
|
45
|
-
borderColor: Colors.black_03, backgroundColor: Colors.black_03
|
|
46
|
-
}
|
|
47
|
-
});
|
|
18
|
+
const Quantity = props => {
|
|
19
|
+
const {
|
|
20
|
+
disabled,
|
|
21
|
+
min = 0,
|
|
22
|
+
max = 5,
|
|
23
|
+
defaultValue = 0,
|
|
24
|
+
size,
|
|
25
|
+
onChange,
|
|
26
|
+
onIncreasePress,
|
|
27
|
+
onDecreasePress,
|
|
28
|
+
isInput = false,
|
|
29
|
+
step = 1,
|
|
30
|
+
style,
|
|
31
|
+
tintColor,
|
|
32
|
+
} = props;
|
|
48
33
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
34
|
+
const [value, setValue] = useState(defaultValue);
|
|
35
|
+
|
|
36
|
+
const getStyle = size => {
|
|
37
|
+
switch (size) {
|
|
38
|
+
case 'medium':
|
|
39
|
+
return {
|
|
40
|
+
button: {
|
|
41
|
+
width: 28,
|
|
42
|
+
height: 28,
|
|
43
|
+
borderRadius: Radius.M + Radius.XXS,
|
|
44
|
+
},
|
|
45
|
+
icon: {
|
|
46
|
+
width: 24,
|
|
47
|
+
height: 24,
|
|
48
|
+
},
|
|
49
|
+
input: {
|
|
50
|
+
minWidth: 28,
|
|
51
|
+
minHeight: 24,
|
|
52
|
+
borderRadius: Radius.S,
|
|
53
|
+
},
|
|
54
|
+
text: {
|
|
55
|
+
fontSize: 12,
|
|
56
|
+
lineHeight: 16,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
case 'large':
|
|
60
|
+
return {
|
|
61
|
+
button: {
|
|
62
|
+
width: 36,
|
|
63
|
+
height: 36,
|
|
64
|
+
borderRadius: Radius.L + Radius.XXS,
|
|
65
|
+
},
|
|
66
|
+
icon: {
|
|
67
|
+
width: 24,
|
|
68
|
+
height: 24,
|
|
69
|
+
},
|
|
70
|
+
input: {
|
|
71
|
+
minWidth: 32,
|
|
72
|
+
minHeight: 26,
|
|
73
|
+
borderRadius: Radius.S,
|
|
74
|
+
},
|
|
75
|
+
text: {
|
|
76
|
+
fontSize: 12,
|
|
77
|
+
lineHeight: 16,
|
|
78
|
+
},
|
|
88
79
|
};
|
|
89
80
|
}
|
|
81
|
+
};
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
const validateValue = value => {
|
|
84
|
+
if (value < min) value = min;
|
|
85
|
+
if (value > max) value = max;
|
|
86
|
+
return value;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const onDecrease = () => {
|
|
90
|
+
let newValue = value;
|
|
91
|
+
if (value > min) {
|
|
92
|
+
newValue = value - step;
|
|
101
93
|
}
|
|
94
|
+
if (newValue < min) newValue = min;
|
|
102
95
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return onChange && typeof onChange === 'function' && onChange(value, type);
|
|
96
|
+
if (onDecreasePress && typeof onDecreasePress === 'function') {
|
|
97
|
+
onDecreasePress(newValue);
|
|
106
98
|
}
|
|
107
99
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
setValue = (newValue, type) => {
|
|
118
|
-
this.setState({
|
|
119
|
-
value: newValue,
|
|
120
|
-
ownUpdate: true,
|
|
121
|
-
}, () => {
|
|
122
|
-
this.onChangeValue(newValue, type);
|
|
123
|
-
});
|
|
100
|
+
setValue(newValue);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const onIncrease = () => {
|
|
104
|
+
let newValue = value;
|
|
105
|
+
if (value < max) {
|
|
106
|
+
newValue = value + step;
|
|
124
107
|
}
|
|
108
|
+
if (newValue > max) newValue = max;
|
|
125
109
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.setValue(newValue, type);
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
this.onChangeValue(value, type);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
render() {
|
|
146
|
-
const { value } = this.state;
|
|
147
|
-
const {
|
|
148
|
-
style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle
|
|
149
|
-
} = this.props;
|
|
150
|
-
const { min } = this.props || 1;
|
|
151
|
-
if (isSingle && value === 0) {
|
|
152
|
-
return (
|
|
153
|
-
<View style={[styles.container, style]}>
|
|
154
|
-
<IconButton
|
|
155
|
-
tintColor={tintColor}
|
|
156
|
-
size={size}
|
|
157
|
-
disabled={(value >= max || !isIncreaseValue)}
|
|
158
|
-
onPress={this.onPress(true)}
|
|
159
|
-
icon={plus}
|
|
160
|
-
/>
|
|
161
|
-
</View>
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
const TextComp = Text[getStyle(size).text];
|
|
165
|
-
return (
|
|
166
|
-
<View style={[styles.container, style]}>
|
|
167
|
-
<IconButton
|
|
168
|
-
style={iconStyle}
|
|
169
|
-
tintColor={tintColor}
|
|
170
|
-
size={size}
|
|
171
|
-
disabled={value === min}
|
|
172
|
-
onPress={this.onPress(false)}
|
|
173
|
-
icon={minus}
|
|
174
|
-
/>
|
|
175
|
-
<View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
|
|
176
|
-
<TextComp weight="bold" style={styles.text}>{value}</TextComp>
|
|
177
|
-
</View>
|
|
178
|
-
<IconButton
|
|
179
|
-
tintColor={tintColor}
|
|
180
|
-
style={iconStyle}
|
|
181
|
-
size={size}
|
|
182
|
-
disabled={(value >= max || !isIncreaseValue)}
|
|
183
|
-
onPress={this.onPress(true)}
|
|
184
|
-
icon={plus}
|
|
185
|
-
/>
|
|
186
|
-
</View>
|
|
187
|
-
);
|
|
110
|
+
if (onIncreasePress && typeof onIncreasePress === 'function') {
|
|
111
|
+
onIncreasePress(newValue);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setValue(newValue);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const onPressButton = type => {
|
|
118
|
+
if (type === 'plus') {
|
|
119
|
+
onIncrease();
|
|
120
|
+
} else {
|
|
121
|
+
onDecrease();
|
|
188
122
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
123
|
+
};
|
|
124
|
+
const renderButton = (type, size, icon) => {
|
|
125
|
+
let disabledStatus = props.disabled;
|
|
126
|
+
if (type === 'plus' && value === max) disabledStatus = true;
|
|
127
|
+
if (type === 'minus' && value === min) disabledStatus = true;
|
|
128
|
+
|
|
129
|
+
if (onPressButton) {
|
|
130
|
+
return (
|
|
131
|
+
<TouchableOpacity
|
|
132
|
+
disabled={disabledStatus}
|
|
133
|
+
onPress={() => onPressButton(type)}
|
|
134
|
+
style={[getStyle(size)?.button, styles.button]}>
|
|
135
|
+
<Image
|
|
200
136
|
source={icon}
|
|
201
|
-
style={[
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
137
|
+
style={[
|
|
138
|
+
getStyle(size)?.icon,
|
|
139
|
+
{tintColor},
|
|
140
|
+
disabledStatus && styles.disabledButton,
|
|
141
|
+
]}
|
|
142
|
+
/>
|
|
143
|
+
</TouchableOpacity>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const onChangeText = value => {
|
|
149
|
+
let newValue = validateValue(parseInt(value)) || '0';
|
|
150
|
+
if (value.length > 1 && value[0] === 0) {
|
|
151
|
+
newValue = value.substring(1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (onChange && typeof onChange === 'function') onChange(newValue);
|
|
155
|
+
|
|
156
|
+
setValue(newValue);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<View style={style}>
|
|
161
|
+
<View style={styles.container}>
|
|
162
|
+
{renderButton('minus', size, minus)}
|
|
163
|
+
<View style={styles.inputContainer}>
|
|
164
|
+
{isInput ? (
|
|
165
|
+
<Input
|
|
166
|
+
textAlign="center"
|
|
167
|
+
keyboardType="number-pad"
|
|
168
|
+
inputMode="numeric"
|
|
169
|
+
selectionColor={Colors.pink_03}
|
|
170
|
+
style={[
|
|
171
|
+
getStyle(size)?.input,
|
|
172
|
+
styles.input,
|
|
173
|
+
disabled && styles.disabledInput,
|
|
174
|
+
{
|
|
175
|
+
fontSize: size === 'small' ? 10 : 12,
|
|
176
|
+
color: Colors.black_17,
|
|
177
|
+
},
|
|
178
|
+
]}
|
|
179
|
+
value={value.toString()}
|
|
180
|
+
onChangeText={onChangeText}
|
|
181
|
+
defaultValue={defaultValue.toString()}
|
|
182
|
+
/>
|
|
183
|
+
) : (
|
|
184
|
+
<View
|
|
185
|
+
style={[
|
|
186
|
+
getStyle(size)?.input,
|
|
187
|
+
styles.input,
|
|
188
|
+
disabled && styles.disabledInput,
|
|
189
|
+
]}>
|
|
190
|
+
<Text style={getStyle(size)?.text}>{value.toString()}</Text>
|
|
191
|
+
</View>
|
|
192
|
+
)}
|
|
193
|
+
</View>
|
|
194
|
+
{renderButton('plus', size, plus)}
|
|
195
|
+
</View>
|
|
196
|
+
</View>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const styles = StyleSheet.create({
|
|
201
|
+
button: {
|
|
202
|
+
backgroundColor: Colors.black_03,
|
|
203
|
+
justifyContent: 'center',
|
|
204
|
+
alignItems: 'center',
|
|
205
|
+
},
|
|
206
|
+
icon: {},
|
|
207
|
+
container: {
|
|
208
|
+
flexDirection: 'row',
|
|
209
|
+
},
|
|
210
|
+
input: {
|
|
211
|
+
borderWidth: 1,
|
|
212
|
+
borderColor: Colors.black_04,
|
|
213
|
+
marginHorizontal: Spacing.M,
|
|
214
|
+
justifyContent: 'center',
|
|
215
|
+
alignItems: 'center',
|
|
216
|
+
paddingHorizontal: Spacing.XS,
|
|
217
|
+
paddingVertical: Spacing.ZERO,
|
|
218
|
+
},
|
|
219
|
+
inputContainer: {
|
|
220
|
+
alignItems: 'center',
|
|
221
|
+
justifyContent: 'center',
|
|
222
|
+
},
|
|
223
|
+
disabledButton: {
|
|
224
|
+
tintColor: Colors.black_08,
|
|
225
|
+
},
|
|
226
|
+
disabledInput: {
|
|
227
|
+
opacity: 0.4,
|
|
228
|
+
},
|
|
229
|
+
});
|
|
205
230
|
|
|
206
231
|
Quantity.propTypes = {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
tintColor: PropTypes.string,
|
|
220
|
-
iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
232
|
+
size: PropTypes.oneOf(['large', 'medium']),
|
|
233
|
+
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
234
|
+
min: PropTypes.number,
|
|
235
|
+
max: PropTypes.number,
|
|
236
|
+
defaultValue: PropTypes.number,
|
|
237
|
+
onChange: PropTypes.func,
|
|
238
|
+
disabled: PropTypes.bool,
|
|
239
|
+
isInput: PropTypes.bool,
|
|
240
|
+
step: PropTypes.number,
|
|
241
|
+
onIncreasePress: PropTypes.func,
|
|
242
|
+
onDecreasePress: PropTypes.func,
|
|
243
|
+
tintColor: PropTypes.string,
|
|
221
244
|
};
|
|
222
245
|
|
|
223
246
|
Quantity.defaultProps = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
tintColor: Colors.pink_05_b,
|
|
247
|
+
min: 0,
|
|
248
|
+
max: 5,
|
|
249
|
+
size: 'medium',
|
|
250
|
+
isInput: false,
|
|
251
|
+
disabled: false,
|
|
252
|
+
step: 1,
|
|
253
|
+
tintColor: Colors.pink_03,
|
|
232
254
|
};
|
|
255
|
+
|
|
256
|
+
export default Quantity;
|
package/Stepper.web.js
CHANGED
|
@@ -1,232 +1,258 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {Component, useState} from 'react';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
View,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
Image,
|
|
7
|
+
TextInput as Input,
|
|
4
8
|
} from 'react-native';
|
|
5
9
|
import PropTypes from 'prop-types';
|
|
6
10
|
import Text from '../../core/components/typography';
|
|
7
|
-
import Colors from '../../core/colors';
|
|
8
|
-
import
|
|
11
|
+
import Colors from '../../core-v2/colors';
|
|
12
|
+
import Radius from '../../core-v2/radius';
|
|
13
|
+
import Spacing from '../../core-v2/spacing';
|
|
9
14
|
|
|
10
|
-
const minus =
|
|
11
|
-
|
|
15
|
+
const minus =
|
|
16
|
+
'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
|
|
17
|
+
const plus =
|
|
18
|
+
'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_plus_circle.png';
|
|
12
19
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
alignItems: 'center',
|
|
29
|
-
marginHorizontal: 6,
|
|
30
|
-
backgroundColor: Colors.white,
|
|
31
|
-
},
|
|
32
|
-
button: {
|
|
33
|
-
justifyContent: 'center',
|
|
34
|
-
alignItems: 'center',
|
|
35
|
-
backgroundColor: Colors.white,
|
|
36
|
-
borderColor: 'transparent'
|
|
37
|
-
},
|
|
38
|
-
borderBox: {
|
|
39
|
-
borderColor: Colors.black_04, borderWidth: 1, borderRadius: 6
|
|
40
|
-
},
|
|
41
|
-
disabledIcon: {
|
|
42
|
-
tintColor: Colors.black_09,
|
|
43
|
-
},
|
|
44
|
-
disabledBox: {
|
|
45
|
-
borderColor: Colors.black_03, backgroundColor: Colors.black_03
|
|
46
|
-
}
|
|
47
|
-
});
|
|
20
|
+
const Quantity = props => {
|
|
21
|
+
const {
|
|
22
|
+
disabled,
|
|
23
|
+
min = 0,
|
|
24
|
+
max = 5,
|
|
25
|
+
defaultValue = 0,
|
|
26
|
+
size,
|
|
27
|
+
onChange,
|
|
28
|
+
onIncreasePress,
|
|
29
|
+
onDecreasePress,
|
|
30
|
+
isInput = false,
|
|
31
|
+
step = 1,
|
|
32
|
+
style,
|
|
33
|
+
tintColor,
|
|
34
|
+
} = props;
|
|
48
35
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
36
|
+
const [value, setValue] = useState(defaultValue);
|
|
37
|
+
|
|
38
|
+
const getStyle = size => {
|
|
39
|
+
switch (size) {
|
|
40
|
+
case 'medium':
|
|
41
|
+
return {
|
|
42
|
+
button: {
|
|
43
|
+
width: 28,
|
|
44
|
+
height: 28,
|
|
45
|
+
borderRadius: Radius.M + Radius.XXS,
|
|
46
|
+
},
|
|
47
|
+
icon: {
|
|
48
|
+
width: 24,
|
|
49
|
+
height: 24,
|
|
50
|
+
},
|
|
51
|
+
input: {
|
|
52
|
+
minWidth: 28,
|
|
53
|
+
minHeight: 24,
|
|
54
|
+
borderRadius: Radius.S,
|
|
55
|
+
},
|
|
56
|
+
text: {
|
|
57
|
+
fontSize: 12,
|
|
58
|
+
lineHeight: 16,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
case 'large':
|
|
62
|
+
return {
|
|
63
|
+
button: {
|
|
64
|
+
width: 36,
|
|
65
|
+
height: 36,
|
|
66
|
+
borderRadius: Radius.L + Radius.XXS,
|
|
67
|
+
},
|
|
68
|
+
icon: {
|
|
69
|
+
width: 24,
|
|
70
|
+
height: 24,
|
|
71
|
+
},
|
|
72
|
+
input: {
|
|
73
|
+
minWidth: 32,
|
|
74
|
+
minHeight: 26,
|
|
75
|
+
borderRadius: Radius.S,
|
|
76
|
+
},
|
|
77
|
+
text: {
|
|
78
|
+
fontSize: 12,
|
|
79
|
+
lineHeight: 16,
|
|
80
|
+
},
|
|
88
81
|
};
|
|
89
82
|
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const validateValue = value => {
|
|
86
|
+
if (value < min) value = min;
|
|
87
|
+
if (value > max) value = max;
|
|
88
|
+
return value;
|
|
89
|
+
};
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
ownUpdate: false,
|
|
96
|
-
};
|
|
97
|
-
} if (nextProps.value !== value && nextProps.value !== prevState.value) {
|
|
98
|
-
return { value: nextProps.value };
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
91
|
+
const onDecrease = () => {
|
|
92
|
+
let newValue = value;
|
|
93
|
+
if (value > min) {
|
|
94
|
+
newValue = value - step;
|
|
101
95
|
}
|
|
96
|
+
if (newValue < min) newValue = min;
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return onChange && typeof onChange === 'function' && onChange(value, type);
|
|
98
|
+
if (onDecreasePress && typeof onDecreasePress === 'function') {
|
|
99
|
+
onDecreasePress(newValue);
|
|
106
100
|
}
|
|
107
101
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
setValue = (newValue, type) => {
|
|
118
|
-
this.setState({
|
|
119
|
-
value: newValue,
|
|
120
|
-
ownUpdate: true,
|
|
121
|
-
}, () => {
|
|
122
|
-
this.onChangeValue(newValue, type);
|
|
123
|
-
});
|
|
102
|
+
setValue(newValue);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const onIncrease = () => {
|
|
106
|
+
let newValue = value;
|
|
107
|
+
if (value < max) {
|
|
108
|
+
newValue = value + step;
|
|
124
109
|
}
|
|
110
|
+
if (newValue > max) newValue = max;
|
|
125
111
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.setValue(newValue, type);
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
this.onChangeValue(value, type);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
render() {
|
|
146
|
-
const { value } = this.state;
|
|
147
|
-
const {
|
|
148
|
-
style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle
|
|
149
|
-
} = this.props;
|
|
150
|
-
const { min } = this.props || 1;
|
|
151
|
-
if (isSingle && value === 0) {
|
|
152
|
-
return (
|
|
153
|
-
<View style={[styles.container, style]}>
|
|
154
|
-
<IconButton
|
|
155
|
-
tintColor={tintColor}
|
|
156
|
-
size={size}
|
|
157
|
-
disabled={(value >= max || !isIncreaseValue)}
|
|
158
|
-
onPress={this.onPress(true)}
|
|
159
|
-
icon={plus}
|
|
160
|
-
/>
|
|
161
|
-
</View>
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
const TextComp = Text[getStyle(size).text];
|
|
165
|
-
return (
|
|
166
|
-
<View style={[styles.container, style]}>
|
|
167
|
-
<IconButton
|
|
168
|
-
style={iconStyle}
|
|
169
|
-
tintColor={tintColor}
|
|
170
|
-
size={size}
|
|
171
|
-
disabled={value === min}
|
|
172
|
-
onPress={this.onPress(false)}
|
|
173
|
-
icon={minus}
|
|
174
|
-
/>
|
|
175
|
-
<View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
|
|
176
|
-
<TextComp weight="bold" style={styles.text}>{value}</TextComp>
|
|
177
|
-
</View>
|
|
178
|
-
<IconButton
|
|
179
|
-
tintColor={tintColor}
|
|
180
|
-
style={iconStyle}
|
|
181
|
-
size={size}
|
|
182
|
-
disabled={(value >= max || !isIncreaseValue)}
|
|
183
|
-
onPress={this.onPress(true)}
|
|
184
|
-
icon={plus}
|
|
185
|
-
/>
|
|
186
|
-
</View>
|
|
187
|
-
);
|
|
112
|
+
if (onIncreasePress && typeof onIncreasePress === 'function') {
|
|
113
|
+
onIncreasePress(newValue);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setValue(newValue);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const onPressButton = type => {
|
|
120
|
+
if (type === 'plus') {
|
|
121
|
+
onIncrease();
|
|
122
|
+
} else {
|
|
123
|
+
onDecrease();
|
|
188
124
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
125
|
+
};
|
|
126
|
+
const renderButton = (type, size, icon) => {
|
|
127
|
+
let disabledStatus = props.disabled;
|
|
128
|
+
if (type === 'plus' && value === max) disabledStatus = true;
|
|
129
|
+
if (type === 'minus' && value === min) disabledStatus = true;
|
|
130
|
+
|
|
131
|
+
if (onPressButton) {
|
|
132
|
+
return (
|
|
133
|
+
<TouchableOpacity
|
|
134
|
+
disabled={disabledStatus}
|
|
135
|
+
onPress={() => onPressButton(type)}
|
|
136
|
+
style={[getStyle(size)?.button, styles.button]}>
|
|
137
|
+
<Image
|
|
200
138
|
source={icon}
|
|
201
|
-
style={[
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
139
|
+
style={[
|
|
140
|
+
getStyle(size)?.icon,
|
|
141
|
+
disabledStatus && styles.disabledButton,
|
|
142
|
+
{tintColor},
|
|
143
|
+
]}
|
|
144
|
+
/>
|
|
145
|
+
</TouchableOpacity>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const onChangeText = value => {
|
|
151
|
+
let newValue = validateValue(parseInt(value)) || '0';
|
|
152
|
+
if (value.length > 1 && value[0] === 0) {
|
|
153
|
+
newValue = value.substring(1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (onChange && typeof onChange === 'function') onChange(newValue);
|
|
157
|
+
|
|
158
|
+
setValue(newValue);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<View style={style}>
|
|
163
|
+
<View style={styles.container}>
|
|
164
|
+
{renderButton('minus', size, minus)}
|
|
165
|
+
<View style={styles.inputContainer}>
|
|
166
|
+
{isInput ? (
|
|
167
|
+
<Input
|
|
168
|
+
textAlign="center"
|
|
169
|
+
keyboardType="number-pad"
|
|
170
|
+
inputMode="numeric"
|
|
171
|
+
selectionColor={Colors.pink_03}
|
|
172
|
+
style={[
|
|
173
|
+
getStyle(size)?.input,
|
|
174
|
+
styles.input,
|
|
175
|
+
disabled && styles.disabledInput,
|
|
176
|
+
{
|
|
177
|
+
fontSize: size === 'small' ? 10 : 12,
|
|
178
|
+
color: Colors.black_17,
|
|
179
|
+
},
|
|
180
|
+
]}
|
|
181
|
+
value={value.toString()}
|
|
182
|
+
onChangeText={onChangeText}
|
|
183
|
+
defaultValue={defaultValue.toString()}
|
|
184
|
+
/>
|
|
185
|
+
) : (
|
|
186
|
+
<View
|
|
187
|
+
style={[
|
|
188
|
+
getStyle(size)?.input,
|
|
189
|
+
styles.input,
|
|
190
|
+
disabled && styles.disabledInput,
|
|
191
|
+
]}>
|
|
192
|
+
<Text style={getStyle(size)?.text}>{value.toString()}</Text>
|
|
193
|
+
</View>
|
|
194
|
+
)}
|
|
195
|
+
</View>
|
|
196
|
+
{renderButton('plus', size, plus)}
|
|
197
|
+
</View>
|
|
198
|
+
</View>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const styles = StyleSheet.create({
|
|
203
|
+
button: {
|
|
204
|
+
backgroundColor: Colors.black_03,
|
|
205
|
+
justifyContent: 'center',
|
|
206
|
+
alignItems: 'center',
|
|
207
|
+
},
|
|
208
|
+
icon: {},
|
|
209
|
+
container: {
|
|
210
|
+
flexDirection: 'row',
|
|
211
|
+
},
|
|
212
|
+
input: {
|
|
213
|
+
borderWidth: 1,
|
|
214
|
+
borderColor: Colors.black_04,
|
|
215
|
+
marginHorizontal: Spacing.M,
|
|
216
|
+
justifyContent: 'center',
|
|
217
|
+
alignItems: 'center',
|
|
218
|
+
paddingHorizontal: Spacing.XS,
|
|
219
|
+
paddingVertical: Spacing.ZERO,
|
|
220
|
+
},
|
|
221
|
+
inputContainer: {
|
|
222
|
+
alignItems: 'center',
|
|
223
|
+
justifyContent: 'center',
|
|
224
|
+
},
|
|
225
|
+
disabledButton: {
|
|
226
|
+
tintColor: Colors.black_08,
|
|
227
|
+
},
|
|
228
|
+
disabledInput: {
|
|
229
|
+
opacity: 0.4,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
205
232
|
|
|
206
233
|
Quantity.propTypes = {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
tintColor: PropTypes.string,
|
|
220
|
-
iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
234
|
+
size: PropTypes.oneOf(['large', 'medium']),
|
|
235
|
+
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
236
|
+
min: PropTypes.number,
|
|
237
|
+
max: PropTypes.number,
|
|
238
|
+
defaultValue: PropTypes.number,
|
|
239
|
+
onChange: PropTypes.func,
|
|
240
|
+
disabled: PropTypes.bool,
|
|
241
|
+
isInput: PropTypes.bool,
|
|
242
|
+
step: PropTypes.number,
|
|
243
|
+
onIncreasePress: PropTypes.func,
|
|
244
|
+
onDecreasePress: PropTypes.func,
|
|
245
|
+
tintColor: PropTypes.string,
|
|
221
246
|
};
|
|
222
247
|
|
|
223
248
|
Quantity.defaultProps = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
tintColor: Colors.pink_05_b,
|
|
249
|
+
min: 0,
|
|
250
|
+
max: 5,
|
|
251
|
+
size: 'medium',
|
|
252
|
+
isInput: false,
|
|
253
|
+
disabled: false,
|
|
254
|
+
step: 1,
|
|
255
|
+
tintColor: Colors.pink_03,
|
|
232
256
|
};
|
|
257
|
+
|
|
258
|
+
export default Quantity;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
"name": "@momo-kits/stepper",
|
|
3
|
+
"version": "0.72.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@momo-kits/core-v2": ">=0.0.5-beta",
|
|
9
|
+
"prop-types": "^15.7.2",
|
|
10
|
+
"react": "16.9.0",
|
|
11
|
+
"react-native": ">=0.55"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {},
|
|
14
|
+
"license": "MoMo"
|
|
15
15
|
}
|
package/publish.sh
CHANGED
|
@@ -21,9 +21,9 @@ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type
|
|
|
21
21
|
#npm login
|
|
22
22
|
#publish dist to npm
|
|
23
23
|
cd dist
|
|
24
|
-
npm publish --access=public
|
|
24
|
+
npm publish --tag beta --access=public
|
|
25
25
|
cd ..
|
|
26
26
|
rm -rf dist
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/stepper new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/stepper"}'
|
|
29
|
+
#curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/stepper new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/stepper"}'
|