@momo-kits/stepper 0.0.7 → 0.0.12

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 +61 -15
  2. package/Stepper.web.js +66 -20
  3. package/package.json +1 -1
package/Stepper.js CHANGED
@@ -79,6 +79,30 @@ const getStyle = (type) => {
79
79
  };
80
80
  return objStyle[type] || objStyle.medium;
81
81
  };
82
+
83
+ const getSize = (type) => {
84
+ const objStyle = {
85
+ large: {
86
+ size: {
87
+ width: 32,height: 24 // height: 26
88
+ },
89
+ },
90
+ medium: {
91
+ size: {
92
+ width: 28, height: 24// height: 24
93
+ },
94
+ },
95
+ small: {
96
+ size: {
97
+ width: 20, height: 16// height: 16
98
+ },
99
+ }
100
+
101
+ };
102
+ return objStyle[type] || objStyle.medium;
103
+ };
104
+
105
+
82
106
  export default class Quantity extends Component {
83
107
  constructor(props) {
84
108
  super(props);
@@ -114,13 +138,24 @@ export default class Quantity extends Component {
114
138
  return value[key];
115
139
  };
116
140
 
117
- setValue = (newValue, type) => {
118
- this.setState({
119
- value: newValue,
120
- ownUpdate: true,
121
- }, () => {
122
- this.onChangeValue(newValue, type);
123
- });
141
+ setValue = (newValue = 0, type) => {
142
+ const { isInput, isIncreaseValue, max, min } = this.props;
143
+ const onValue = (newValue, type) => {
144
+ this.setState({
145
+ value: newValue,
146
+ ownUpdate: true,
147
+ }, () => {
148
+ this.onChangeValue(newValue, type);
149
+ });
150
+ };
151
+
152
+ if(isInput){
153
+ if((newValue <= max && isIncreaseValue) && (newValue >= min)){
154
+ onValue(newValue, type)
155
+ }
156
+ }else {
157
+ onValue(newValue, type)
158
+ }
124
159
  }
125
160
 
126
161
  onPress = (isIncrease = true) => () => {
@@ -173,7 +208,16 @@ export default class Quantity extends Component {
173
208
  icon={minus}
174
209
  />
175
210
  <View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
176
- <TextComp weight="bold" style={styles.text}>{value}</TextComp>
211
+ {
212
+ isInput ? <TextInput
213
+ style={[{textAlignVertical: 'center'}, getSize(type).size]}
214
+ underlineColorAndroid="transparent"
215
+ value={value.toString()}
216
+ textAlign='center'
217
+ maxLength={3}
218
+ keyboardType='number-pad'
219
+ onChangeText={(text) => this.setValue(text)}/> : <TextComp weight="bold" style={styles.text}>{value}</TextComp>
220
+ }
177
221
  </View>
178
222
  <IconButton
179
223
  tintColor={tintColor}
@@ -192,14 +236,14 @@ const IconButton = ({
192
236
  disabled, onPress, icon, size, tintColor, style
193
237
  }) => (
194
238
  <TouchableOpacity
195
- style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
196
- disabled={disabled}
197
- onPress={onPress}
239
+ style={[getStyle(type).size, styles.button, style]}// disabled && styles.disabledBox
240
+ disabled={disabled}
241
+ onPress={onPress}
198
242
  >
199
- <Image
200
- source={icon}
201
- style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
202
- />
243
+ <Image
244
+ source={icon}
245
+ style={[getStyle(type).icon, { tintColor }, disabled && styles.disabledIcon]}
246
+ />
203
247
  </TouchableOpacity>
204
248
  );
205
249
 
@@ -218,6 +262,7 @@ Quantity.propTypes = {
218
262
  isSingle: PropTypes.bool,
219
263
  tintColor: PropTypes.string,
220
264
  iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
265
+ isInput: PropTypes.bool,
221
266
  };
222
267
 
223
268
  Quantity.defaultProps = {
@@ -229,4 +274,5 @@ Quantity.defaultProps = {
229
274
  isSingle: false,
230
275
  size: 'medium',
231
276
  tintColor: Colors.pink_05_b,
277
+ isInput: false
232
278
  };
package/Stepper.web.js CHANGED
@@ -79,6 +79,30 @@ const getStyle = (type) => {
79
79
  };
80
80
  return objStyle[type] || objStyle.medium;
81
81
  };
82
+
83
+ const getSize = (type) => {
84
+ const objStyle = {
85
+ large: {
86
+ size: {
87
+ width: 32,height: 24 // height: 26
88
+ },
89
+ },
90
+ medium: {
91
+ size: {
92
+ width: 28, height: 24// height: 24
93
+ },
94
+ },
95
+ small: {
96
+ size: {
97
+ width: 20, height: 16// height: 16
98
+ },
99
+ }
100
+
101
+ };
102
+ return objStyle[type] || objStyle.medium;
103
+ };
104
+
105
+
82
106
  export default class Quantity extends Component {
83
107
  constructor(props) {
84
108
  super(props);
@@ -114,13 +138,24 @@ export default class Quantity extends Component {
114
138
  return value[key];
115
139
  };
116
140
 
117
- setValue = (newValue, type) => {
118
- this.setState({
119
- value: newValue,
120
- ownUpdate: true,
121
- }, () => {
122
- this.onChangeValue(newValue, type);
123
- });
141
+ setValue = (newValue = 0, type) => {
142
+ const { isInput, isIncreaseValue, max, min } = this.props;
143
+ const onValue = (newValue, type) => {
144
+ this.setState({
145
+ value: newValue,
146
+ ownUpdate: true,
147
+ }, () => {
148
+ this.onChangeValue(newValue, type);
149
+ });
150
+ };
151
+
152
+ if(isInput){
153
+ if((newValue <= max && isIncreaseValue) && (newValue >= min)){
154
+ onValue(newValue, type)
155
+ }
156
+ }else {
157
+ onValue(newValue, type)
158
+ }
124
159
  }
125
160
 
126
161
  onPress = (isIncrease = true) => () => {
@@ -167,18 +202,27 @@ export default class Quantity extends Component {
167
202
  <IconButton
168
203
  style={iconStyle}
169
204
  tintColor={tintColor}
170
- size={size}
205
+ type={type}
171
206
  disabled={value === min}
172
207
  onPress={this.onPress(false)}
173
208
  icon={minus}
174
209
  />
175
- <View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
176
- <TextComp weight="bold" style={styles.text}>{value}</TextComp>
210
+ <View style={[styles.numberBox, getStyle(type).size, valueStyle]}>
211
+ {
212
+ isInput ? <TextInput
213
+ style={[{textAlignVertical: 'center'}, getSize(type).size]}
214
+ underlineColorAndroid="transparent"
215
+ value={value.toString()}
216
+ textAlign='center'
217
+ maxLength={3}
218
+ keyboardType='number-pad'
219
+ onChangeText={(text) => this.setValue(text)}/> : <TextComp weight="bold" style={styles.text}>{value}</TextComp>
220
+ }
177
221
  </View>
178
222
  <IconButton
179
223
  tintColor={tintColor}
180
224
  style={iconStyle}
181
- size={size}
225
+ type={type}
182
226
  disabled={(value >= max || !isIncreaseValue)}
183
227
  onPress={this.onPress(true)}
184
228
  icon={plus}
@@ -192,19 +236,19 @@ const IconButton = ({
192
236
  disabled, onPress, icon, size, tintColor, style
193
237
  }) => (
194
238
  <TouchableOpacity
195
- style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
196
- disabled={disabled}
197
- onPress={onPress}
239
+ style={[getStyle(type).size, styles.button, style]}// disabled && styles.disabledBox
240
+ disabled={disabled}
241
+ onPress={onPress}
198
242
  >
199
- <Image
200
- source={icon}
201
- style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
202
- />
243
+ <Image
244
+ source={icon}
245
+ style={[getStyle(type).icon, { tintColor }, disabled && styles.disabledIcon]}
246
+ />
203
247
  </TouchableOpacity>
204
248
  );
205
249
 
206
250
  Quantity.propTypes = {
207
- size: PropTypes.oneOf(['large', 'medium', 'small']),
251
+ type: PropTypes.oneOf(['large', 'medium', 'small']),
208
252
  style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
209
253
  valueStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
210
254
  min: PropTypes.number,
@@ -218,6 +262,7 @@ Quantity.propTypes = {
218
262
  isSingle: PropTypes.bool,
219
263
  tintColor: PropTypes.string,
220
264
  iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
265
+ isInput: PropTypes.bool,
221
266
  };
222
267
 
223
268
  Quantity.defaultProps = {
@@ -227,6 +272,7 @@ Quantity.defaultProps = {
227
272
  isIncreaseValue: true,
228
273
  isDecreaseValue: true,
229
274
  isSingle: false,
230
- size: 'medium',
275
+ type: 'medium',
231
276
  tintColor: Colors.pink_05_b,
277
+ isInput: false
232
278
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/stepper",
3
- "version": "0.0.7",
3
+ "version": "0.0.12",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},