@momo-kits/stepper 0.0.9 → 0.0.14

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 +63 -17
  2. package/Stepper.web.js +64 -18
  3. package/package.json +1 -1
package/Stepper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { Component } from 'react';
2
2
  import {
3
- View, StyleSheet
3
+ View, StyleSheet, TextInput
4
4
  } from 'react-native';
5
5
  import PropTypes from 'prop-types';
6
6
  import {
@@ -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) => () => {
@@ -145,7 +180,7 @@ export default class Quantity extends Component {
145
180
  render() {
146
181
  const { value } = this.state;
147
182
  const {
148
- style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle
183
+ style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle, isInput
149
184
  } = this.props;
150
185
  const { min } = this.props || 1;
151
186
  if (isSingle && value === 0) {
@@ -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(size).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(size).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(size).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
@@ -1,11 +1,10 @@
1
1
  import React, { Component } from 'react';
2
2
  import {
3
- View, StyleSheet, TouchableOpacity, Image
3
+ View, StyleSheet, TouchableOpacity, Image, TextInput
4
4
  } from 'react-native';
5
5
  import PropTypes from 'prop-types';
6
6
  import Text from '../../core/components/typography';
7
7
  import Colors from '../../core/colors';
8
- import ValueUtil from '../../core/utils/ValueUtil';
9
8
 
10
9
  const minus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
11
10
  const plus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_plus_circle.png';
@@ -79,6 +78,30 @@ const getStyle = (type) => {
79
78
  };
80
79
  return objStyle[type] || objStyle.medium;
81
80
  };
81
+
82
+ const getSize = (type) => {
83
+ const objStyle = {
84
+ large: {
85
+ size: {
86
+ width: 32,height: 24 // height: 26
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
+
100
+ };
101
+ return objStyle[type] || objStyle.medium;
102
+ };
103
+
104
+
82
105
  export default class Quantity extends Component {
83
106
  constructor(props) {
84
107
  super(props);
@@ -114,13 +137,24 @@ export default class Quantity extends Component {
114
137
  return value[key];
115
138
  };
116
139
 
117
- setValue = (newValue, type) => {
118
- this.setState({
119
- value: newValue,
120
- ownUpdate: true,
121
- }, () => {
122
- this.onChangeValue(newValue, type);
123
- });
140
+ setValue = (newValue = 0, type) => {
141
+ const { isInput, isIncreaseValue, max, min } = this.props;
142
+ const onValue = (newValue, type) => {
143
+ this.setState({
144
+ value: newValue,
145
+ ownUpdate: true,
146
+ }, () => {
147
+ this.onChangeValue(newValue, type);
148
+ });
149
+ };
150
+
151
+ if(isInput){
152
+ if((newValue <= max && isIncreaseValue) && (newValue >= min)){
153
+ onValue(newValue, type)
154
+ }
155
+ }else {
156
+ onValue(newValue, type)
157
+ }
124
158
  }
125
159
 
126
160
  onPress = (isIncrease = true) => () => {
@@ -145,7 +179,7 @@ export default class Quantity extends Component {
145
179
  render() {
146
180
  const { value } = this.state;
147
181
  const {
148
- style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle
182
+ style, max, valueStyle, size, tintColor, isIncreaseValue, isSingle, iconStyle, isInput
149
183
  } = this.props;
150
184
  const { min } = this.props || 1;
151
185
  if (isSingle && value === 0) {
@@ -173,7 +207,16 @@ export default class Quantity extends Component {
173
207
  icon={minus}
174
208
  />
175
209
  <View style={[styles.numberBox, getStyle(size).size, valueStyle]}>
176
- <TextComp weight="bold" style={styles.text}>{value}</TextComp>
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
+ }
177
220
  </View>
178
221
  <IconButton
179
222
  tintColor={tintColor}
@@ -192,14 +235,14 @@ const IconButton = ({
192
235
  disabled, onPress, icon, size, tintColor, style
193
236
  }) => (
194
237
  <TouchableOpacity
195
- style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
196
- disabled={disabled}
197
- onPress={onPress}
238
+ style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
239
+ disabled={disabled}
240
+ onPress={onPress}
198
241
  >
199
- <Image
200
- source={icon}
201
- style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
202
- />
242
+ <Image
243
+ source={icon}
244
+ style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
245
+ />
203
246
  </TouchableOpacity>
204
247
  );
205
248
 
@@ -218,6 +261,7 @@ Quantity.propTypes = {
218
261
  isSingle: PropTypes.bool,
219
262
  tintColor: PropTypes.string,
220
263
  iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
264
+ isInput: PropTypes.bool,
221
265
  };
222
266
 
223
267
  Quantity.defaultProps = {
@@ -229,4 +273,6 @@ Quantity.defaultProps = {
229
273
  isSingle: false,
230
274
  size: 'medium',
231
275
  tintColor: Colors.pink_05_b,
276
+ isInput: false
232
277
  };
278
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/stepper",
3
- "version": "0.0.9",
3
+ "version": "0.0.14",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},