@momo-kits/stepper 0.0.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 ADDED
@@ -0,0 +1,232 @@
1
+ import React, { Component } from 'react';
2
+ import {
3
+ View, StyleSheet
4
+ } from 'react-native';
5
+ import PropTypes from 'prop-types';
6
+ import {
7
+ Text, Colors, Image, TouchableOpacity
8
+ } from '@momo-kits/core';
9
+
10
+ const minus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
11
+ const plus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_plus_circle.png';
12
+
13
+ const styles = StyleSheet.create({
14
+ container: {
15
+ flexDirection: 'row',
16
+ },
17
+ icon: {
18
+ height: 24,
19
+ width: 24,
20
+ resizeMode: 'contain',
21
+ tintColor: Colors.pink_03,
22
+ },
23
+ text: {
24
+ color: Colors.black_17
25
+ },
26
+ numberBox: {
27
+ justifyContent: 'center',
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
+ });
48
+
49
+ const getStyle = (type) => {
50
+ const objStyle = {
51
+ large: {
52
+ size: {
53
+ ...styles.borderBox, width: 32, // height: 26
54
+ },
55
+ icon: {
56
+ width: 24, height: 24, resizeMode: 'contain'
57
+ },
58
+ text: 'Title'
59
+ },
60
+ medium: {
61
+ size: {
62
+ ...styles.borderBox, width: 28, // height: 24
63
+ },
64
+ icon: {
65
+ width: 24, height: 24, resizeMode: 'contain'
66
+ },
67
+ text: 'SubTitle'
68
+ },
69
+ small: {
70
+ size: {
71
+ ...styles.borderBox, width: 20, // height: 16
72
+ },
73
+ icon: {
74
+ width: 16, height: 16, resizeMode: 'contain'
75
+ },
76
+ text: 'Caption'
77
+ }
78
+
79
+ };
80
+ return objStyle[type] || objStyle.medium;
81
+ };
82
+ export default class Quantity extends Component {
83
+ constructor(props) {
84
+ super(props);
85
+ this.state = {
86
+ value: props.defaultValue || props.min,
87
+ ownUpdate: false
88
+ };
89
+ }
90
+
91
+ static getDerivedStateFromProps(nextProps, prevState) {
92
+ const { value = undefined } = this?.props || {};
93
+ if (prevState.ownUpdate) {
94
+ return {
95
+ ownUpdate: false,
96
+ };
97
+ } if (nextProps.value !== value && nextProps.value !== prevState.value) {
98
+ return { value: nextProps.value };
99
+ }
100
+ return null;
101
+ }
102
+
103
+ onChangeValue = (value, type) => {
104
+ const { onChange } = this.props;
105
+ return onChange && typeof onChange === 'function' && onChange(value, type);
106
+ }
107
+
108
+ getValue = (key) => {
109
+ const { isIncreaseValue, isDecreaseValue } = this.props;
110
+ const value = {
111
+ increase: isIncreaseValue ? 1 : 0,
112
+ decrease: isDecreaseValue ? 1 : 0,
113
+ };
114
+ return value[key];
115
+ };
116
+
117
+ setValue = (newValue, type) => {
118
+ this.setState({
119
+ value: newValue,
120
+ ownUpdate: true,
121
+ }, () => {
122
+ this.onChangeValue(newValue, type);
123
+ });
124
+ }
125
+
126
+ onPress = (isIncrease = true) => () => {
127
+ const { isChangeValue, onConditionCheck } = this.props;
128
+ const { value } = this.state;
129
+ const type = isIncrease ? 'increase' : 'decrease';
130
+ if (isChangeValue) {
131
+ const newValue = isIncrease ? value + this.getValue('increase') : value - this.getValue('decrease');
132
+ if (typeof onConditionCheck === 'function') {
133
+ const passCondition = onConditionCheck(newValue, type);
134
+ if (passCondition) {
135
+ this.setValue(newValue, type);
136
+ }
137
+ } else {
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
+ );
188
+ }
189
+ }
190
+
191
+ const IconButton = ({
192
+ disabled, onPress, icon, size, tintColor, style
193
+ }) => (
194
+ <TouchableOpacity
195
+ style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
196
+ disabled={disabled}
197
+ onPress={onPress}
198
+ >
199
+ <Image
200
+ source={icon}
201
+ style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
202
+ />
203
+ </TouchableOpacity>
204
+ );
205
+
206
+ Quantity.propTypes = {
207
+ size: PropTypes.oneOf(['large', 'medium', 'small']),
208
+ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
209
+ valueStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
210
+ min: PropTypes.number,
211
+ max: PropTypes.number,
212
+ value: PropTypes.number,
213
+ defaultValue: PropTypes.number,
214
+ onChange: PropTypes.func,
215
+ isChangeValue: PropTypes.bool,
216
+ isIncreaseValue: PropTypes.bool,
217
+ isDecreaseValue: PropTypes.bool,
218
+ isSingle: PropTypes.bool,
219
+ tintColor: PropTypes.string,
220
+ iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
221
+ };
222
+
223
+ Quantity.defaultProps = {
224
+ min: 1,
225
+ max: 100,
226
+ isChangeValue: true,
227
+ isIncreaseValue: true,
228
+ isDecreaseValue: true,
229
+ isSingle: false,
230
+ size: 'medium',
231
+ tintColor: Colors.pink_05_b,
232
+ };
package/Stepper.web.js ADDED
@@ -0,0 +1,232 @@
1
+ import React, { Component } from 'react';
2
+ import {
3
+ View, StyleSheet, TouchableOpacity, Image
4
+ } from 'react-native';
5
+ import PropTypes from 'prop-types';
6
+ import Text from '../../core/components/typography';
7
+ import Colors from '../../core/colors';
8
+ import ValueUtil from '../../core/utils/ValueUtil';
9
+
10
+ const minus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
11
+ const plus = 'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_plus_circle.png';
12
+
13
+ const styles = StyleSheet.create({
14
+ container: {
15
+ flexDirection: 'row',
16
+ },
17
+ icon: {
18
+ height: 24,
19
+ width: 24,
20
+ resizeMode: 'contain',
21
+ tintColor: Colors.pink_03,
22
+ },
23
+ text: {
24
+ color: Colors.black_17
25
+ },
26
+ numberBox: {
27
+ justifyContent: 'center',
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
+ });
48
+
49
+ const getStyle = (type) => {
50
+ const objStyle = {
51
+ large: {
52
+ size: {
53
+ ...styles.borderBox, width: 32, // height: 26
54
+ },
55
+ icon: {
56
+ width: 24, height: 24, resizeMode: 'contain'
57
+ },
58
+ text: 'Title'
59
+ },
60
+ medium: {
61
+ size: {
62
+ ...styles.borderBox, width: 28, // height: 24
63
+ },
64
+ icon: {
65
+ width: 24, height: 24, resizeMode: 'contain'
66
+ },
67
+ text: 'SubTitle'
68
+ },
69
+ small: {
70
+ size: {
71
+ ...styles.borderBox, width: 20, // height: 16
72
+ },
73
+ icon: {
74
+ width: 16, height: 16, resizeMode: 'contain'
75
+ },
76
+ text: 'Caption'
77
+ }
78
+
79
+ };
80
+ return objStyle[type] || objStyle.medium;
81
+ };
82
+ export default class Quantity extends Component {
83
+ constructor(props) {
84
+ super(props);
85
+ this.state = {
86
+ value: props.defaultValue || props.min,
87
+ ownUpdate: false
88
+ };
89
+ }
90
+
91
+ static getDerivedStateFromProps(nextProps, prevState) {
92
+ const { value = undefined } = this?.props || {};
93
+ if (prevState.ownUpdate) {
94
+ return {
95
+ ownUpdate: false,
96
+ };
97
+ } if (nextProps.value !== value && nextProps.value !== prevState.value) {
98
+ return { value: nextProps.value };
99
+ }
100
+ return null;
101
+ }
102
+
103
+ onChangeValue = (value, type) => {
104
+ const { onChange } = this.props;
105
+ return onChange && typeof onChange === 'function' && onChange(value, type);
106
+ }
107
+
108
+ getValue = (key) => {
109
+ const { isIncreaseValue, isDecreaseValue } = this.props;
110
+ const value = {
111
+ increase: isIncreaseValue ? 1 : 0,
112
+ decrease: isDecreaseValue ? 1 : 0,
113
+ };
114
+ return value[key];
115
+ };
116
+
117
+ setValue = (newValue, type) => {
118
+ this.setState({
119
+ value: newValue,
120
+ ownUpdate: true,
121
+ }, () => {
122
+ this.onChangeValue(newValue, type);
123
+ });
124
+ }
125
+
126
+ onPress = (isIncrease = true) => () => {
127
+ const { isChangeValue, onConditionCheck } = this.props;
128
+ const { value } = this.state;
129
+ const type = isIncrease ? 'increase' : 'decrease';
130
+ if (isChangeValue) {
131
+ const newValue = isIncrease ? value + this.getValue('increase') : value - this.getValue('decrease');
132
+ if (typeof onConditionCheck === 'function') {
133
+ const passCondition = onConditionCheck(newValue, type);
134
+ if (passCondition) {
135
+ this.setValue(newValue, type);
136
+ }
137
+ } else {
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
+ );
188
+ }
189
+ }
190
+
191
+ const IconButton = ({
192
+ disabled, onPress, icon, size, tintColor, style
193
+ }) => (
194
+ <TouchableOpacity
195
+ style={[getStyle(size).size, styles.button, style]}// disabled && styles.disabledBox
196
+ disabled={disabled}
197
+ onPress={onPress}
198
+ >
199
+ <Image
200
+ source={icon}
201
+ style={[getStyle(size).icon, { tintColor }, disabled && styles.disabledIcon]}
202
+ />
203
+ </TouchableOpacity>
204
+ );
205
+
206
+ Quantity.propTypes = {
207
+ size: PropTypes.oneOf(['large', 'medium', 'small']),
208
+ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
209
+ valueStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
210
+ min: PropTypes.number,
211
+ max: PropTypes.number,
212
+ value: PropTypes.number,
213
+ defaultValue: PropTypes.number,
214
+ onChange: PropTypes.func,
215
+ isChangeValue: PropTypes.bool,
216
+ isIncreaseValue: PropTypes.bool,
217
+ isDecreaseValue: PropTypes.bool,
218
+ isSingle: PropTypes.bool,
219
+ tintColor: PropTypes.string,
220
+ iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
221
+ };
222
+
223
+ Quantity.defaultProps = {
224
+ min: 1,
225
+ max: 100,
226
+ isChangeValue: true,
227
+ isIncreaseValue: true,
228
+ isDecreaseValue: true,
229
+ isSingle: false,
230
+ size: 'medium',
231
+ tintColor: Colors.pink_05_b,
232
+ };
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import Stepper from './Stepper';
2
+
3
+ export default Stepper;
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@momo-kits/stepper",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "main": "index.js",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "react-native": ">=0.55",
9
+ "prop-types": "^15.7.2",
10
+ "react": "16.9.0",
11
+ "@momo-kits/core": ">=0.0.5-beta"
12
+ },
13
+ "devDependencies": {},
14
+ "license": "MoMo"
15
+ }
package/publish.sh ADDED
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+ rm -rf dist
3
+ mkdir dist
4
+
5
+ cp . ./dist
6
+
7
+ # GET VERSION from mck_package.json
8
+ VERSIONSTRING=( v$(jq .version package.json) )
9
+ VERSION=(${VERSIONSTRING//[\"]/})
10
+ echo VERSION: $VERSION
11
+
12
+ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
13
+
14
+ # #babel component to dist
15
+ #babel ./dist -d dist --copy-files
16
+
17
+ #copy option
18
+ #cp -r ./src/ dist
19
+
20
+
21
+ #npm login
22
+ #publish dist to npm
23
+ cd dist
24
+ npm publish --access=public
25
+ cd ..
26
+ rm -rf dist
27
+
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"}'