@momo-kits/step 0.0.64-beta → 0.0.65-alpha.8

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.
@@ -0,0 +1,216 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import { StyleSheet, View, Image } from 'react-native';
4
+ import Colors from '../../core/colors';
5
+ import Text from '../../core/components/typography';
6
+ import Spacing from '../../core/spacing';
7
+
8
+ import { Icons as IconSource } from '../../core/icons';
9
+
10
+ const CIRCLE_SIZE = 24;
11
+ const CIRCLE_TEXT_SIZE = 12;
12
+ const ICON_SIZE = 16;
13
+ const ICON_URL = IconSource.ic_check_24;
14
+ const TITLE_SIZE = { size: 14, lineHeight: 20 };
15
+ const SUBTITLE_SIZE = { size: 10, lineHeight: 14 };
16
+ const CONTENT_SIZE = { size: 12, lineHeight: 16 };
17
+ function VerticalStep(props) {
18
+ VerticalStep.displayName = 'VerticalStep';
19
+ const {
20
+ steps = {},
21
+ currentStep,
22
+ type,
23
+ activeCircleColor,
24
+ inactiveCircleColor,
25
+ checkedCircleColor,
26
+ activeBorderColor,
27
+ inactiveBorderColor,
28
+ activeLineColor,
29
+ inactiveLineColor,
30
+ style,
31
+ } = props;
32
+
33
+ const renderCircle = (index) => {
34
+ let circleColor = inactiveCircleColor;
35
+ let borderColor = inactiveBorderColor;
36
+
37
+ if (index < currentStep) circleColor = checkedCircleColor;
38
+ else if (index === currentStep) circleColor = activeCircleColor;
39
+
40
+ if (index <= currentStep) borderColor = activeBorderColor;
41
+
42
+ return (
43
+ <View
44
+ style={[
45
+ styles.circle,
46
+ {
47
+ borderColor: borderColor,
48
+ backgroundColor: circleColor,
49
+ },
50
+ ]}>
51
+ {renderCircleContent(index)}
52
+ </View>
53
+ );
54
+ };
55
+
56
+ const renderCircleContent = (index) => {
57
+ if (type === 'check') {
58
+ return <Image source={ICON_URL} style={styles.icon} />;
59
+ } else if (type === 'combine') {
60
+ return index < currentStep ? (
61
+ <Image source={ICON_URL} style={styles.icon} />
62
+ ) : (
63
+ <Text style={styles.circleText}>{index + 1}</Text>
64
+ );
65
+ }
66
+ return <Text style={styles.circleText}>{index + 1}</Text>;
67
+ };
68
+
69
+ const renderLine = (index) => {
70
+ if (index === steps.length - 1) return null;
71
+ const lineColor =
72
+ index < currentStep ? activeLineColor : inactiveLineColor;
73
+
74
+ return (
75
+ <View style={[styles.line, { backgroundColor: lineColor }]}></View>
76
+ );
77
+ };
78
+
79
+ const renderHeader = (title, subTitle, index) => {
80
+ const weight = index === currentStep ? '600' : '400';
81
+
82
+ return (
83
+ <View style={styles.header}>
84
+ <Text style={[styles.title, { fontWeight: weight }]}>
85
+ {title}
86
+ </Text>
87
+ <Text style={styles.subTitle}>{subTitle}</Text>
88
+ </View>
89
+ );
90
+ };
91
+
92
+ const renderContent = (content, index) => {
93
+ return (
94
+ <View style={styles.content}>
95
+ {content && typeof content === 'string' ? (
96
+ <Text style={styles.contentText}>{content}</Text>
97
+ ) : (
98
+ content
99
+ )}
100
+ </View>
101
+ );
102
+ };
103
+
104
+ const renderStepPart = (item, index) => {
105
+ const { title, subTitle, content } = item;
106
+ return (
107
+ <View
108
+ key={index.toString()}
109
+ style={{
110
+ flexDirection: 'row',
111
+ }}>
112
+ <View style={styles.circleContainer}>
113
+ {renderCircle(index)}
114
+ {renderLine(index)}
115
+ </View>
116
+ <View style={styles.contentContainer}>
117
+ {renderHeader(title, subTitle, index)}
118
+ {renderContent(content, index)}
119
+ </View>
120
+ </View>
121
+ );
122
+ };
123
+
124
+ return (
125
+ <View style={style}>
126
+ {steps.map((item, index) => {
127
+ return renderStepPart(item, index);
128
+ })}
129
+ </View>
130
+ );
131
+ }
132
+
133
+ export default VerticalStep;
134
+
135
+ const styles = StyleSheet.create({
136
+ circleContainer: {
137
+ flexDirection: 'column',
138
+ alignItems: 'center',
139
+ height: '100%',
140
+ },
141
+ circle: {
142
+ width: CIRCLE_SIZE,
143
+ height: CIRCLE_SIZE,
144
+ borderRadius: CIRCLE_SIZE / 2,
145
+ borderWidth: 2,
146
+ justifyContent: 'center',
147
+ alignItems: 'center',
148
+ },
149
+ contentContainer: { marginLeft: Spacing.S, flex: 1 },
150
+ content: { marginVertical: Spacing.XS, minHeight: 60 },
151
+ contentText: {
152
+ fontSize: CONTENT_SIZE.size,
153
+ lineHeight: CONTENT_SIZE.lineHeight,
154
+ color: Colors.black_12,
155
+ },
156
+ header: {
157
+ flexDirection: 'row',
158
+ justifyContent: 'space-between',
159
+ alignItems: 'center',
160
+ },
161
+ title: {
162
+ lineHeight: TITLE_SIZE.lineHeight,
163
+ fontSize: TITLE_SIZE.size,
164
+ },
165
+ subTitle: {
166
+ fontSize: SUBTITLE_SIZE.size,
167
+ lineHeight: SUBTITLE_SIZE.lineHeight,
168
+ color: Colors.black_12,
169
+ },
170
+ line: {
171
+ width: 2,
172
+ flex: 1,
173
+ marginVertical: Spacing.XS,
174
+ borderRadius: 1,
175
+ },
176
+ icon: {
177
+ width: ICON_SIZE,
178
+ height: ICON_SIZE,
179
+ tintColor: Colors.white,
180
+ },
181
+ circleText: {
182
+ fontSize: CIRCLE_TEXT_SIZE,
183
+ color: Colors.white,
184
+ fontWeight: '600',
185
+ },
186
+ });
187
+
188
+ VerticalStep.propTypes = {
189
+ steps: PropTypes.arrayOf({
190
+ title: PropTypes.string.isRequired,
191
+ subTitle: PropTypes.string,
192
+ content: PropTypes.oneOfType([PropTypes.string || PropTypes.element]),
193
+ }),
194
+ currentStep: PropTypes.number,
195
+ type: PropTypes.oneOf(['check', 'combine', 'text']),
196
+ activeCircleColor: PropTypes.string,
197
+ inactiveCircleColor: PropTypes.string,
198
+ checkedCircleColor: PropTypes.string,
199
+ activeBorderColor: PropTypes.string,
200
+ inactiveBorderColor: PropTypes.string,
201
+ activeLineColor: PropTypes.string,
202
+ inactiveLineColor: PropTypes.string,
203
+ style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
204
+ };
205
+
206
+ VerticalStep.defaultProps = {
207
+ currentStep: 0,
208
+ type: 'check',
209
+ activeCircleColor: Colors.pink_05_b,
210
+ inactiveCircleColor: Colors.black_06,
211
+ checkedCircleColor: '#f382c0',
212
+ activeBorderColor: Colors.pink_09,
213
+ inactiveBorderColor: Colors.black_04,
214
+ activeLineColor: '#fbd5ea',
215
+ inactiveLineColor: Colors.black_04,
216
+ };
package/Step.web.js CHANGED
@@ -1,302 +1,51 @@
1
1
  import React, { Component } from 'react';
2
- import { View, StyleSheet, Image } from 'react-native';
2
+
3
3
  import PropTypes from 'prop-types';
4
- import { ColorCore as Colors } from '../../core/colors/colorCore';
5
- import Text from '../../core/components/typography';
4
+ import HorizontalStep from './Step.horizontal.web.js';
5
+ import VerticalStep from './Step.vertical.web.js';
6
+ import Colors from '../../core/colors';
6
7
  import { Icons as IconSource } from '../../core/icons';
7
8
 
8
- const CIRCLE_SIZE = 24;
9
-
10
- const styles = StyleSheet.create({
11
- circle: {
12
- width: CIRCLE_SIZE,
13
- height: CIRCLE_SIZE,
14
- // borderWidth: 1,
15
- // borderColor: Colors.sepia_05,
16
- borderRadius: CIRCLE_SIZE / 2,
17
- backgroundColor: 'white'
18
- },
19
- line: {
20
- height: 4,
21
- backgroundColor: 'white',
22
- // borderWidth: 1,
23
- // borderRadius: 1,
24
- // borderStyle: 'dashed',
25
- zIndex: 0,
26
- // marginTop: 8
27
- },
28
- topRight: {
29
- position: 'absolute',
30
- right: -1,
31
- top: -1,
32
- width: 1,
33
- height: '100%',
34
- backgroundColor: 'white',
35
- zIndex: 1
36
- },
37
- topLeft: {
38
- position: 'absolute',
39
- left: -1,
40
- top: -1,
41
- width: '100%',
42
- height: 1,
43
- backgroundColor: 'white',
44
- zIndex: 1
45
- },
46
- topLeftWidth: {
47
- position: 'absolute',
48
- left: -1,
49
- top: -1,
50
- width: 1,
51
- height: '100%',
52
- backgroundColor: 'white',
53
- zIndex: 1
54
- },
55
- circleRow: {
56
- position: 'absolute',
57
- justifyContent: 'space-between',
58
- flexDirection: 'row',
59
- },
60
- circleColumn: {
61
- // position: 'absolute',
62
- justifyContent: 'space-between',
63
- },
64
- titleDefault: {
65
- color: Colors.black_12
66
- },
67
- titleActive: {
68
- color: Colors.black_17,
69
- fontWeight: 'bold'
70
- },
71
- containerStyle: {
72
- minHeight: CIRCLE_SIZE + 20 + CIRCLE_SIZE
73
- }
74
- });
75
-
76
- export default class Step extends Component {
77
- constructor(props) {
78
- super(props);
79
- this.state = {
80
- width: 0,
81
- height: 0
82
- };
83
- }
84
-
85
- onLayout = (e) => {
86
- this.setState({ width: e.nativeEvent.layout.width, height: e.nativeEvent.layout.height });
87
- }
88
-
89
- renderLine = () => {
90
- const {
91
- lineColor, lineStyle, currentStep, data
92
- } = this.props;
93
- return (
94
- <View style={[styles.line, { borderColor: lineColor }, lineStyle]}>
95
- {/* <View style={styles.topLeft} />
96
- <View style={styles.topLeftWidth} />
97
- <View style={styles.topRight} /> */}
98
- </View>
99
- );
100
- }
101
-
102
- circle = (value, index) => {
103
- const {
104
- currentStep, tintColor, data, lineStyle, isNumber, iconActive,
105
- iconInActive, lineColorActive, lineColorInActive, bodyStyle, iconStyle
106
- } = this.props;
107
- const { width } = this.state;
108
- const icon = currentStep >= (index + 1) ? iconActive || IconSource.ic_step_active : iconInActive || IconSource.ic_step_coming;
109
- const textFontStyle = currentStep >= (index + 1) ? styles.titleActive : styles.titleDefault;
110
- const itemWidth = (width - CIRCLE_SIZE) / data?.length;
111
- const lineActive = currentStep >= (index + 1) ? lineColorActive || isNumber ? Colors.pink_09 : Colors.sepia_05 : lineColorInActive || Colors.black_02;
112
- const lineWidth = (width - CIRCLE_SIZE) / (data.length - 1);
113
- const backgroundActive = currentStep >= (index + 1) ? Colors.pink_05_b : Colors.black_09;
114
- let left = 0;
115
- let textAlignStyle = { textAlign: 'center' };
116
- /**
117
- * item lefr
118
- */
119
- if (index === 0) {
120
- left = 0;
121
- textAlignStyle = { textAlign: 'left' };
122
-
123
- /**
124
- * item right
125
- */
126
- } else if (index === data?.length - 1) {
127
- left = -itemWidth + CIRCLE_SIZE;
128
- textAlignStyle = { textAlign: 'right' };
129
- /**
130
- * center item
131
- */
132
- } else { left = -itemWidth / 2 + CIRCLE_SIZE / 2; }
133
- const textStyle = [textAlignStyle, textFontStyle];
134
-
135
- return (
136
- <View key={index}>
137
- {
138
- data?.length - 1 !== index && (
139
- <View style={[styles.line, {
140
- position: 'absolute',
141
- top: 10,
142
- backgroundColor: lineActive,
143
- width: lineWidth,
144
- height: 4,
145
- marginTop: 0
146
- }, lineStyle]}
147
- />
148
- )
149
- }
150
- {
151
- isNumber ? (
152
- <View style={{
153
- width: CIRCLE_SIZE,
154
- height: CIRCLE_SIZE,
155
- borderRadius: CIRCLE_SIZE / 2,
156
- backgroundColor: backgroundActive,
157
- borderColor: Colors.pink_09,
158
- borderWidth: 1,
159
- alignItems: 'center',
160
- justifyContent: 'center'
161
- }}
162
- >
163
- <Text.SubTitle style={{ color: 'white' }} weight="bold">{index + 1}</Text.SubTitle>
164
- </View>
165
- ) : <Image source={icon} style={[styles.circle, { tintColor }, iconStyle]} />
166
- }
167
-
168
- <View style={{
169
- position: 'absolute',
170
- width: itemWidth,
171
- left,
172
- top: CIRCLE_SIZE + CIRCLE_SIZE / 4
173
- }}
174
- >
175
- <Text.Caption style={[textStyle, bodyStyle]}>{value}</Text.Caption>
176
- </View>
177
- </View>
178
- );
179
- }
180
-
181
- circleColumn = (value, index) => {
182
- const {
183
- currentStep, tintColor, data, lineStyle, isNumber, iconActive,
184
- iconInActive, lineColorActive, lineColorInActive, bodyStyle, iconStyle
185
- } = this.props;
186
- const { height } = this.state;
187
- const icon = currentStep >= (index + 1) ? iconActive || IconSource.ic_step_active : iconInActive || IconSource.ic_step_coming;
188
- const textFontStyle = currentStep >= (index + 1) ? styles.titleActive : styles.titleDefault;
189
- const itemWidth = (height - CIRCLE_SIZE) / data?.length;
190
- const lineActive = currentStep >= (index + 1) ? lineColorActive || isNumber ? Colors.pink_09 : Colors.sepia_05 : lineColorInActive || Colors.black_02;
191
- const lineWidth = (height - CIRCLE_SIZE) / (data.length - 1);
192
- const backgroundActive = currentStep >= (index + 1) ? Colors.pink_05_b : Colors.black_09;
193
- let left = 0;
194
- let textAlignStyle = { textAlign: 'center' };
195
- /**
196
- * item lefr
197
- */
198
- if (index === 0) {
199
- left = 0;
200
- textAlignStyle = { textAlign: 'left' };
201
-
202
- /**
203
- * item right
204
- */
205
- } else if (index === data?.length - 1) {
206
- left = -itemWidth + CIRCLE_SIZE;
207
- textAlignStyle = { textAlign: 'right' };
208
- /**
209
- * center item
210
- */
211
- } else { left = -itemWidth / 2 + CIRCLE_SIZE / 2; }
212
- const textStyle = [textAlignStyle, textFontStyle];
213
-
214
- return (
215
- <View key={index}>
216
- <View style={{ flexDirection: 'row', alignItems: 'center' }}>
217
- {
218
- isNumber ? (
219
- <View style={{
220
- width: CIRCLE_SIZE,
221
- height: CIRCLE_SIZE,
222
- borderRadius: CIRCLE_SIZE / 2,
223
- backgroundColor: backgroundActive,
224
- borderColor: Colors.pink_09,
225
- borderWidth: 1,
226
- alignItems: 'center',
227
- justifyContent: 'center'
228
- }}
229
- >
230
- {
231
- iconActive ? <Image source={iconActive} style={[styles.circle, { tintColor }, iconStyle]} /> : <Text.SubTitle style={{ color: 'white' }} weight="bold">{index + 1}</Text.SubTitle>
232
- }
233
- </View>
234
- ) : <Image source={icon} style={[styles.circle, { tintColor }, iconStyle]} />
235
- }
236
- <Text.Caption style={[{ marginLeft: 10 }, textStyle, bodyStyle]}>{value}</Text.Caption>
237
- </View>
238
-
239
- {
240
- data?.length - 1 !== index && (
241
- <View style={[styles.line, {
242
- left: 10,
243
- backgroundColor: lineActive,
244
- width: 4,
245
- height: lineWidth,
246
- marginTop: 0,
247
- }, lineStyle]}
248
- />
249
- )
250
- }
251
-
252
- </View>
253
- );
254
- }
255
-
256
- renderCircle = () => {
257
- const { data = [], isVertical } = this.props;
258
- return data.map(isVertical ? this.circleColumn : this.circle);
259
- }
260
-
261
- render() {
262
- const { width, height } = this.state;
263
- const { style, isVertical } = this.props;
264
- return (
265
- <View style={[styles.containerStyle, style]} onLayout={this.onLayout}>
266
- {/* {this.renderLine()} */}
267
- {
268
- isVertical ? (
269
- <View style={[styles.circleColumn, { height }]}>
270
- {this.renderCircle()}
271
- </View>
272
- ) : (
273
- <View style={[styles.circleRow, { width }]}>
274
- {this.renderCircle()}
275
- </View>
276
- )
277
- }
278
-
279
- </View>
280
- );
9
+ function Step(props) {
10
+ const { isVertical } = props;
11
+ if (isVertical) {
12
+ return <VerticalStep {...props} />;
281
13
  }
14
+ return <HorizontalStep {...props} />;
282
15
  }
16
+ export default Step;
283
17
 
284
18
  Step.propTypes = {
285
- data: PropTypes.arrayOf(PropTypes.string),
19
+ steps: PropTypes.arrayOf({
20
+ title: PropTypes.string.isRequired,
21
+ subTitle: PropTypes.string,
22
+ content: PropTypes.oneOfType([PropTypes.string || PropTypes.element]),
23
+ error: PropTypes.bool,
24
+ }),
286
25
  currentStep: PropTypes.number,
287
- tintColor: PropTypes.string,
288
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
289
- isNumber: PropTypes.bool,
290
- isVertical: PropTypes.bool,
291
- iconActive: PropTypes.any,
292
- iconInActive: PropTypes.any,
293
- lineColorActive: PropTypes.string,
294
- lineColorInActive: PropTypes.string,
295
- bodyStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
26
+ type: PropTypes.oneOf(['check', 'combine', 'text']),
27
+ size: PropTypes.oneOf(['default', 'small']),
28
+ activeCircleColor: PropTypes.string,
29
+ inactiveCircleColor: PropTypes.string,
30
+ checkedCircleColor: PropTypes.string,
31
+ activeBorderColor: PropTypes.string,
32
+ inactiveBorderColor: PropTypes.string,
33
+ activeLineColor: PropTypes.string,
34
+ inactiveLineColor: PropTypes.string,
35
+ style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
36
+ checkIcon: PropTypes.string,
37
+ errorIcon: PropTypes.string,
296
38
  };
297
39
 
298
40
  Step.defaultProps = {
299
- data: [],
300
41
  currentStep: 0,
301
- tintColor: Colors.sepia_05
302
- };
42
+ type: 'check',
43
+ size: 'normal',
44
+ activeCircleColor: Colors.pink_05_b,
45
+ inactiveCircleColor: Colors.black_06,
46
+ checkedCircleColor: '#f382c0',
47
+ activeBorderColor: Colors.pink_09,
48
+ inactiveBorderColor: Colors.black_04,
49
+ activeLineColor: '#fbd5ea',
50
+ inactiveLineColor: Colors.black_04,
51
+ };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
- "name": "@momo-kits/step",
3
- "version": "0.0.64-beta",
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"
2
+ "name": "@momo-kits/step",
3
+ "version": "0.0.65-alpha.8",
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-v2": ">=0.0.5-beta"
12
+ },
13
+ "devDependencies": {},
14
+ "license": "MoMo"
15
15
  }
package/publish.sh CHANGED
@@ -21,7 +21,7 @@ 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