@momo-kits/step 0.0.65-beta → 0.0.65-beta.2

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,325 @@
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 = {
15
+ size: 14,
16
+ lineHeight: 20,
17
+ };
18
+ const SUBTITLE_SIZE = {
19
+ size: 10,
20
+ lineHeight: 14,
21
+ };
22
+ const CONTENT_SIZE = {
23
+ size: 12,
24
+ lineHeight: 16,
25
+ };
26
+
27
+ const VerticalStep = props => {
28
+ const {
29
+ steps = {},
30
+ currentStep,
31
+ type,
32
+ activeCircleColor,
33
+ inactiveCircleColor,
34
+ checkedCircleColor,
35
+ activeBorderColor,
36
+ inactiveBorderColor,
37
+ activeLineColor,
38
+ inactiveLineColor,
39
+ style,
40
+ size = 'default',
41
+ checkIcon,
42
+ errorIcon,
43
+ } = props;
44
+ let CIRCLE_SIZE = 24;
45
+ let CIRCLE_TEXT_SIZE = 12;
46
+ let ICON_SIZE = 16;
47
+ let TITLE_SIZE = {
48
+ size: 14,
49
+ lineHeight: 20,
50
+ };
51
+ let SUBTITLE_SIZE = {
52
+ size: 10,
53
+ lineHeight: 14,
54
+ };
55
+ let CONTENT_SIZE = {
56
+ size: 12,
57
+ lineHeight: 16,
58
+ };
59
+ const ICON_URL = checkIcon || IconSource.ic_check_24;
60
+ const ERROR_ICON_URL = errorIcon || IconSource.ic_close_x_24;
61
+ if (size === 'small') {
62
+ CIRCLE_SIZE = 16;
63
+ CIRCLE_TEXT_SIZE = 8;
64
+ ICON_SIZE = 12;
65
+ TITLE_SIZE = {
66
+ size: 12,
67
+ lineHeight: 16,
68
+ };
69
+ SUBTITLE_SIZE = {
70
+ size: 10,
71
+ lineHeight: 14,
72
+ };
73
+ CONTENT_SIZE = {
74
+ size: 10,
75
+ lineHeight: 14,
76
+ };
77
+ }
78
+
79
+ const renderCircle = (error, index) => {
80
+ let circleColor = inactiveCircleColor;
81
+ let borderColor = inactiveBorderColor;
82
+
83
+ if (index < currentStep) {
84
+ circleColor = checkedCircleColor;
85
+ } else if (index === currentStep) circleColor = activeCircleColor;
86
+
87
+ if (index <= currentStep) borderColor = activeBorderColor;
88
+ if (error) {
89
+ circleColor = Colors.red_03;
90
+ borderColor = Colors.red_08;
91
+ }
92
+
93
+ return (
94
+ <View
95
+ style={[
96
+ styles.circle,
97
+ {
98
+ width: CIRCLE_SIZE,
99
+ height: CIRCLE_SIZE,
100
+ borderRadius: CIRCLE_SIZE / 2,
101
+ borderColor: borderColor,
102
+ backgroundColor: circleColor,
103
+ },
104
+ ]}>
105
+ {renderCircleContent(error, index)}
106
+ </View>
107
+ );
108
+ };
109
+
110
+ const renderCircleContent = (error, index) => {
111
+ const icon = error ? ERROR_ICON_URL : ICON_URL;
112
+
113
+ if (type === 'check') {
114
+ return (
115
+ <Image
116
+ source={icon}
117
+ style={[
118
+ styles.icon,
119
+ {
120
+ width: ICON_SIZE,
121
+ height: ICON_SIZE,
122
+ },
123
+ ]}
124
+ />
125
+ );
126
+ } else if (type === 'combine') {
127
+ return index < currentStep ? (
128
+ <Image
129
+ source={icon}
130
+ style={[
131
+ styles.icon,
132
+ {
133
+ width: ICON_SIZE,
134
+ height: ICON_SIZE,
135
+ },
136
+ ]}
137
+ />
138
+ ) : (
139
+ <Text
140
+ style={[
141
+ styles.circleText,
142
+ {
143
+ fontSize: CIRCLE_TEXT_SIZE,
144
+ lineHeight: CIRCLE_TEXT_SIZE + 2,
145
+ },
146
+ ]}>
147
+ {index + 1}
148
+ </Text>
149
+ );
150
+ }
151
+ return (
152
+ <Text
153
+ style={[
154
+ styles.circleText,
155
+ {
156
+ fontSize: CIRCLE_TEXT_SIZE,
157
+ lineHeight: CIRCLE_TEXT_SIZE + 2,
158
+ },
159
+ ]}>
160
+ {index + 1}
161
+ </Text>
162
+ );
163
+ };
164
+
165
+ const renderLine = index => {
166
+ if (index === steps.length - 1) return null;
167
+ const lineColor = index < currentStep ? activeLineColor : inactiveLineColor;
168
+
169
+ return <View style={[styles.line, {backgroundColor: lineColor}]} />;
170
+ };
171
+
172
+ const renderHeader = (title, subTitle, error, index) => {
173
+ const weight = index === currentStep ? '600' : '400';
174
+ const disabledColor = Colors.black_09;
175
+ const errorColor = Colors.red_03;
176
+ return (
177
+ <View style={styles.header}>
178
+ <Text
179
+ style={[
180
+ styles.title,
181
+ {
182
+ lineHeight: TITLE_SIZE.lineHeight,
183
+ fontSize: TITLE_SIZE.size,
184
+ fontWeight: weight,
185
+ color: error
186
+ ? errorColor
187
+ : index < currentStep
188
+ ? disabledColor
189
+ : Colors.black_17,
190
+ },
191
+ ]}>
192
+ {title}
193
+ </Text>
194
+ <Text
195
+ style={[
196
+ styles.subTitle,
197
+ {
198
+ fontSize: SUBTITLE_SIZE.size,
199
+ lineHeight: SUBTITLE_SIZE.lineHeight,
200
+ color:
201
+ index < currentStep && !error ? disabledColor : Colors.black_12,
202
+ },
203
+ ]}>
204
+ {subTitle}
205
+ </Text>
206
+ </View>
207
+ );
208
+ };
209
+
210
+ const renderContent = (content, error, index, size) => {
211
+ const disabledColor = Colors.black_09;
212
+ let marginBottom = size === 'small' ? Spacing.S : Spacing.M;
213
+ let minHeight = 30;
214
+
215
+ if (index === steps.length - 1) {
216
+ marginBottom = 0;
217
+ minHeight = 0;
218
+ }
219
+
220
+ return (
221
+ <View
222
+ style={[
223
+ styles.content,
224
+ {
225
+ marginBottom,
226
+ minHeight,
227
+ },
228
+ ]}>
229
+ {content && typeof content === 'string' ? (
230
+ <Text
231
+ style={[
232
+ styles.contentText,
233
+ {
234
+ fontSize: CONTENT_SIZE.size,
235
+ lineHeight: CONTENT_SIZE.lineHeight,
236
+ color:
237
+ index < currentStep && !error
238
+ ? disabledColor
239
+ : Colors.black_12,
240
+ },
241
+ ]}>
242
+ {content}
243
+ </Text>
244
+ ) : (
245
+ content
246
+ )}
247
+ </View>
248
+ );
249
+ };
250
+
251
+ const renderStepPart = (item, index) => {
252
+ const {title, subTitle, content, error} = item;
253
+ return (
254
+ <View
255
+ key={index.toString()}
256
+ style={{
257
+ flexDirection: 'row',
258
+ }}>
259
+ <View style={styles.circleContainer}>
260
+ {renderCircle(error, index)}
261
+ {renderLine(index)}
262
+ </View>
263
+ <View style={styles.contentContainer}>
264
+ {renderHeader(title, subTitle, error, index)}
265
+ {renderContent(content, error, index, size)}
266
+ </View>
267
+ </View>
268
+ );
269
+ };
270
+
271
+ return (
272
+ <View style={style}>
273
+ {steps.map((item, index) => {
274
+ return renderStepPart(item, index);
275
+ })}
276
+ </View>
277
+ );
278
+ };
279
+
280
+ export default VerticalStep;
281
+
282
+ const styles = StyleSheet.create({
283
+ circleContainer: {
284
+ flexDirection: 'column',
285
+ alignItems: 'center',
286
+ height: '100%',
287
+ },
288
+ circle: {
289
+ borderWidth: 2,
290
+ justifyContent: 'center',
291
+ alignItems: 'center',
292
+ },
293
+ contentContainer: {
294
+ marginLeft: Spacing.S,
295
+ flex: 1,
296
+ },
297
+ content: {
298
+ marginTop: Spacing.XS,
299
+ },
300
+ contentText: {
301
+ color: Colors.black_12,
302
+ },
303
+ header: {
304
+ flexDirection: 'row',
305
+ justifyContent: 'space-between',
306
+ alignItems: 'center',
307
+ },
308
+ title: {},
309
+ subTitle: {
310
+ color: Colors.black_12,
311
+ },
312
+ line: {
313
+ width: 2,
314
+ flex: 1,
315
+ marginVertical: Spacing.XS,
316
+ borderRadius: 1,
317
+ },
318
+ icon: {
319
+ tintColor: Colors.white,
320
+ },
321
+ circleText: {
322
+ color: Colors.white,
323
+ fontWeight: '600',
324
+ },
325
+ });
package/Step.web.js CHANGED
@@ -1,302 +1,51 @@
1
- import React, { Component } from 'react';
2
- import { View, StyleSheet, Image } from 'react-native';
3
- import PropTypes from 'prop-types';
4
- import { ColorCore as Colors } from '../../core/colors/colorCore';
5
- import Text from '../../core/components/typography';
6
- import { Icons as IconSource } from '../../core/icons';
7
-
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
- }
1
+ import React, {Component} from 'react';
180
2
 
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
- }
3
+ import PropTypes from 'prop-types';
4
+ import HorizontalStep from './Step.horizontal.web.js';
5
+ import VerticalStep from './Step.vertical.web.js';
6
+ import Colors from '../../core-v2/colors';
7
+
8
+ const Step = props => {
9
+ const {isVertical} = props;
10
+ if (isVertical) {
11
+ return <VerticalStep {...props} />;
12
+ }
13
+ return <HorizontalStep {...props} />;
14
+ };
278
15
 
279
- </View>
280
- );
281
- }
282
- }
16
+ export default Step;
283
17
 
284
18
  Step.propTypes = {
285
- data: PropTypes.arrayOf(PropTypes.string),
286
- 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]),
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
+ }),
25
+ currentStep: PropTypes.number,
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
- currentStep: 0,
301
- tintColor: Colors.sepia_05
302
- };
41
+ currentStep: 0,
42
+ type: 'check',
43
+ size: 'normal',
44
+ activeCircleColor: Colors.pink_03,
45
+ inactiveCircleColor: Colors.black_06,
46
+ checkedCircleColor: Colors.pink_08,
47
+ activeBorderColor: Colors.pink_10,
48
+ inactiveBorderColor: Colors.black_04,
49
+ activeLineColor: Colors.pink_08,
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.65-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-beta.2",
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