@momo-kits/step 0.0.61-rc.1 → 0.0.62-alpha.13

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.
@@ -1,401 +1,216 @@
1
- import React, { Component } from 'react';
2
- import { View, StyleSheet, Image, ScrollView } from 'react-native';
3
-
4
1
  import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import { StyleSheet, View, Image } from 'react-native';
5
4
  import Colors from '../../core/colors';
6
5
  import Text from '../../core/components/typography';
6
+ import Spacing from '../../core/spacing';
7
+
7
8
  import { Icons as IconSource } from '../../core/icons';
8
9
 
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;
10
41
 
11
- const styles = StyleSheet.create({
12
- circle: {
13
- width: CIRCLE_SIZE,
14
- height: CIRCLE_SIZE,
15
- borderRadius: CIRCLE_SIZE / 2,
16
- borderWidth: 2,
17
- padding: 4,
18
- },
19
- iconImage: {
20
- width: 16,
21
- height: 16,
22
- position: 'absolute',
23
- top: 2,
24
- left: 2,
25
- },
26
- titleDefault: {
27
- color: Colors.black_12,
28
- fontSize: 14,
29
- fontWeight: 'normal',
30
- },
31
- titleActive: {
32
- color: Colors.black_17,
33
- fontSize: 14,
34
- fontWeight: 'bold',
35
- },
36
- container: {
37
- width: '100%',
38
- paddingRight: 48,
39
- marginTop: 4,
40
- },
41
- titleAndDate: {
42
- flexDirection: 'row',
43
- justifyContent: 'space-between',
44
- alignItems: 'center',
45
- },
46
- description: {
47
- fontSize: 12,
48
- color: Colors.black_12,
49
- marginBottom: 16,
50
- paddingTop: 4,
51
- paddingLeft: 11,
52
- },
53
- date: {
54
- fontSize: 10,
55
- color: Colors.black_12,
56
- },
57
- number: {
58
- fontSize: 12,
59
- color: 'white',
60
- textAlign: 'center',
61
- lineHeight: 13,
62
- },
63
- lineVertical: {
64
- marginLeft: 11,
65
- width: 2,
66
- minHeight: 10,
67
- marginTop: 4,
68
- marginBottom: 4,
69
- flex: 1,
70
- },
71
- minHeight: {
72
- minHeight: 12,
73
- marginBottom: 4,
74
- },
75
- });
76
-
77
- export default class VerticalStep extends Component {
78
- constructor(props) {
79
- super(props);
80
- this.state = {
81
- width: 0,
82
- height: 0,
83
- };
84
- }
85
-
86
- onLayout = (e) => {
87
- this.setState({
88
- width: e.nativeEvent.layout.width,
89
- height: e.nativeEvent.layout.height,
90
- });
91
- };
92
-
93
- /* #region render cust */
94
- _renderCircleImage = ({ icon = '', circleColor, circleBorderColor }) => {
95
42
  return (
96
- <View>
97
- <View
98
- style={[
99
- styles.circle,
100
- {
101
- backgroundColor: circleColor,
102
- borderColor: circleBorderColor,
103
- },
104
- ]}>
105
- <Image
106
- source={icon}
107
- style={[styles.iconImage, { tintColor: '#ffffff' }]}
108
- />
109
- </View>
43
+ <View
44
+ style={[
45
+ styles.circle,
46
+ {
47
+ borderColor: borderColor,
48
+ backgroundColor: circleColor,
49
+ },
50
+ ]}>
51
+ {renderCircleContent(index)}
110
52
  </View>
111
53
  );
112
54
  };
113
55
 
114
- _renderCircleText = ({
115
- circleColor = '',
116
- circleBorderColor = '',
117
- index = 0,
118
- }) => {
119
- return (
120
- <View>
121
- <View
122
- style={[
123
- styles.circle,
124
- {
125
- backgroundColor: circleColor,
126
- borderColor: circleBorderColor,
127
- },
128
- ]}>
129
- <Text style={styles.number}>{index + 1}</Text>
130
- </View>
131
- </View>
132
- );
133
- };
134
-
135
- _renderCircle = ({
136
- circleColor = '',
137
- circleBorderColor = '',
138
- isActiveState = false,
139
- circleUnchecked = false,
140
- iconActive,
141
- iconUnchecked,
142
- icon = {},
143
- index = 0,
144
- }) => {
145
- let resultComponent = <></>;
146
- if (!isActiveState) {
147
- if (circleUnchecked) {
148
- if (Object.keys(iconUnchecked).length === 0) {
149
- resultComponent = this._renderCircleImage({
150
- icon,
151
- circleColor,
152
- circleBorderColor,
153
- });
154
- } else {
155
- resultComponent = this._renderCircleText({
156
- circleColor,
157
- circleBorderColor,
158
- index,
159
- });
160
- }
161
- } else {
162
- resultComponent = this._renderCircleImage({
163
- icon,
164
- circleColor,
165
- circleBorderColor,
166
- });
167
- }
168
- } else {
169
- // This is active case
170
- // If icon diff "" & regex http or https url so will render image component
171
- if (Object.keys(iconActive).length === 0) {
172
- resultComponent = this._renderCircleImage({
173
- icon,
174
- circleColor,
175
- circleBorderColor,
176
- });
177
- } else {
178
- // Otherwise render index number in text component
179
- resultComponent = resultComponent = this._renderCircleText({
180
- circleColor,
181
- circleBorderColor,
182
- index,
183
- });
184
- }
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
+ );
185
65
  }
186
- return resultComponent;
66
+ return <Text style={styles.circleText}>{index + 1}</Text>;
187
67
  };
188
68
 
189
- _renderLine = ({ titles = {}, index = 0, lineActive = '' }) => {
190
- let resultComponent = <></>;
69
+ const renderLine = (index) => {
70
+ if (index === steps.length - 1) return null;
71
+ const lineColor =
72
+ index < currentStep ? activeLineColor : inactiveLineColor;
191
73
 
192
- if (titles?.length - 1 !== index) {
193
- resultComponent = (
194
- <View
195
- style={[
196
- styles.lineVertical,
197
- {
198
- backgroundColor: lineActive,
199
- },
200
- ]}
201
- />
202
- );
203
- }
204
- return resultComponent;
74
+ return (
75
+ <View style={[styles.line, { backgroundColor: lineColor }]}></View>
76
+ );
205
77
  };
206
78
 
207
- _renderTitle = ({ textFontStyle = {}, titleStyle = {}, value = {} }) => {
208
- let resultComponent = (
209
- <View>
210
- <Text.Caption
211
- style={[{ marginLeft: 10 }, textFontStyle, titleStyle]}>
212
- {value}
213
- </Text.Caption>
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>
214
88
  </View>
215
89
  );
216
- return resultComponent;
217
- };
218
-
219
- _renderDateOrValue = ({
220
- date = '',
221
- isActiveState = false,
222
- circleChecked = false,
223
- dateStyle = {},
224
- index = 0,
225
- }) => {
226
- // Init states in render function
227
- let resultComponent = <></>;
228
- if (!date) {
229
- return resultComponent;
230
- }
231
- if (isActiveState || circleChecked) {
232
- resultComponent = (
233
- <Text style={[styles.date, dateStyle]}>{date[index]}</Text>
234
- );
235
- }
236
- return resultComponent;
237
90
  };
238
91
 
239
- _renderDescription = ({ items = {}, descriptionStyle = {}, index = 0 }) => {
240
- let resultComponent = <></>;
241
-
242
- if (items) {
243
- resultComponent = (
244
- <View>
245
- {typeof items[index] == 'string' ? (
246
- <Text style={[styles.description, descriptionStyle]}>
247
- {items[index]}
248
- </Text>
249
- ) : (
250
- <View style={[styles.description]}>{items[index]}</View>
251
- )}
252
- </View>
253
- );
254
- }
255
- return resultComponent;
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
+ );
256
102
  };
257
- /* #endregion */
258
-
259
- circleColumn = (value, index) => {
260
- const {
261
- currentStep,
262
- titles,
263
- iconActive,
264
- iconChecked,
265
- iconUnchecked,
266
- circleColorActive,
267
- circleColorChecked,
268
- circleColorUnchecked,
269
- circleBorderColorActive,
270
- circleBorderColorChecked,
271
- circleBorderColorUnchecked,
272
- lineColorActive,
273
- lineColorInActive,
274
- items,
275
- date,
276
- titleStyle,
277
- descriptionStyle,
278
- dateStyle,
279
- } = this.props;
280
-
281
- // Three circle states
282
- const isActiveState = currentStep == index + 1;
283
- const circleChecked = currentStep > index + 1;
284
- const circleUnchecked = currentStep < index + 1;
285
-
286
- // Default properties is inactive state
287
- let icon = {};
288
- let circleColor = circleColorUnchecked || Colors.black_06;
289
- let circleBorderColor = circleBorderColorUnchecked || Colors.black_04;
290
- let textFontStyle = styles.titleDefault;
291
- let lineActive = lineColorInActive || Colors.black_04;
292
-
293
- let tintColor = '#ffd6e7';
294
-
295
- // This is all properties in active state
296
- if (isActiveState) {
297
- icon = iconActive || index + 1;
298
- circleColor = circleColorActive || '#d82d8b';
299
- circleBorderColor = circleBorderColorActive || Colors.pink_09;
300
- textFontStyle = styles.titleActive;
301
- }
302
-
303
- if (circleChecked) {
304
- icon = iconChecked || IconSource.ic_check_24;
305
- lineActive = lineColorActive || tintColor;
306
- circleColor = circleColorChecked || '#ffadd2';
307
- circleBorderColor = circleBorderColorChecked || Colors.pink_09;
308
- }
309
-
310
- if (circleUnchecked) {
311
- icon = iconUnchecked || index + 1;
312
- }
313
103
 
104
+ const renderStepPart = (item, index) => {
105
+ const { title, subTitle, content } = item;
314
106
  return (
315
- <View key={index} style={{ flexDirection: 'row' }}>
316
- <View>
317
- {this._renderCircle({
318
- circleColor,
319
- circleBorderColor,
320
- isActiveState,
321
- circleUnchecked,
322
- iconActive,
323
- iconUnchecked,
324
- icon,
325
- index,
326
- })}
327
- {this._renderLine({
328
- titles,
329
- index,
330
- lineActive,
331
- })}
107
+ <View
108
+ key={index.toString()}
109
+ style={{
110
+ flexDirection: 'row',
111
+ }}>
112
+ <View style={styles.circleContainer}>
113
+ {renderCircle(index)}
114
+ {renderLine(index)}
332
115
  </View>
333
- <View style={styles.container}>
334
- <View style={styles.titleAndDate}>
335
- {this._renderTitle({
336
- textFontStyle,
337
- titleStyle,
338
- value,
339
- })}
340
- {this._renderDateOrValue({
341
- date,
342
- isActiveState,
343
- circleChecked,
344
- dateStyle,
345
- index,
346
- })}
347
- </View>
348
- {this._renderDescription({
349
- items,
350
- descriptionStyle,
351
- index,
352
- })}
116
+ <View style={styles.contentContainer}>
117
+ {renderHeader(title, subTitle, index)}
118
+ {renderContent(content, index)}
353
119
  </View>
354
120
  </View>
355
121
  );
356
122
  };
357
123
 
358
- renderCircle = () => {
359
- const { titles = [[]] } = this.props;
360
- return titles.map(this.circleColumn);
361
- };
362
-
363
- render() {
364
- return (
365
- <ScrollView>
366
- <View onLayout={this.onLayout}>
367
- <View style={[styles.circleColumn]}>
368
- {this.renderCircle()}
369
- </View>
370
- </View>
371
- </ScrollView>
372
- );
373
- }
124
+ return (
125
+ <View style={style}>
126
+ {steps.map((item, index) => {
127
+ return renderStepPart(item, index);
128
+ })}
129
+ </View>
130
+ );
374
131
  }
375
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
+
376
188
  VerticalStep.propTypes = {
377
- titles: PropTypes.array,
189
+ steps: PropTypes.arrayOf({
190
+ title: PropTypes.string.isRequired,
191
+ subTitle: PropTypes.string,
192
+ content: PropTypes.oneOfType([PropTypes.string || PropTypes.element]),
193
+ }),
378
194
  currentStep: PropTypes.number,
379
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
380
- items: PropTypes.array,
381
- isVertical: PropTypes.bool,
382
- iconActive: PropTypes.any,
383
- iconChecked: PropTypes.any,
384
- iconUnchecked: PropTypes.any,
385
- circleColorActive: PropTypes.string,
386
- circleColorChecked: PropTypes.string,
387
- circleColorUnchecked: PropTypes.string,
388
- circleBorderColorActive: PropTypes.string,
389
- circleBorderColorChecked: PropTypes.string,
390
- circleBorderColorUnchecked: PropTypes.string,
391
- lineColorActive: PropTypes.string,
392
- lineColorInActive: PropTypes.string,
393
- titleStyle: PropTypes.object,
394
- descriptionStyle: PropTypes.object,
395
- dateStyle: PropTypes.object,
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]),
396
204
  };
397
205
 
398
206
  VerticalStep.defaultProps = {
399
- titles: [],
400
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,
401
216
  };
package/Step.web.js CHANGED
@@ -6,56 +6,46 @@ import VerticalStep from './Step.vertical.web.js';
6
6
  import Colors from '../../core/colors';
7
7
  import { Icons as IconSource } from '../../core/icons';
8
8
 
9
- export default class Step extends Component {
10
- constructor(props) {
11
- super(props);
12
- }
13
-
14
- render() {
15
- const { isVertical } = this.props;
16
- let DefaultComponent = HorizontalStep;
17
- if (isVertical) {
18
- DefaultComponent = VerticalStep;
19
- }
20
- return <DefaultComponent {...this.props} />;
9
+ function Step(props) {
10
+ const { isVertical } = props;
11
+ if (isVertical) {
12
+ return <VerticalStep {...props} />;
21
13
  }
14
+ return <HorizontalStep {...props} />;
22
15
  }
16
+ export default Step;
23
17
 
24
18
  Step.propTypes = {
25
- titles: 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
+ }),
26
25
  currentStep: PropTypes.number,
27
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
28
- items: PropTypes.array,
29
- isVertical: PropTypes.bool,
30
- iconActive: PropTypes.any,
31
- iconChecked: PropTypes.any,
32
- iconUnchecked: PropTypes.any,
33
- circleColorActive: PropTypes.string,
34
- circleColorChecked: PropTypes.string,
35
- circleColorUnchecked: PropTypes.string,
36
- circleBorderColorActive: PropTypes.string,
37
- circleBorderColorChecked: PropTypes.string,
38
- circleBorderColorUnchecked: PropTypes.string,
39
- lineColorActive: PropTypes.string,
40
- lineColorInActive: PropTypes.string,
41
- titleStyle: PropTypes.object,
42
- descriptionStyle: PropTypes.object,
43
- dateStyle: PropTypes.object,
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,
44
38
  };
45
39
 
46
40
  Step.defaultProps = {
47
- titles: [],
48
41
  currentStep: 0,
49
- isVertical: false,
50
- iconActive: 'index + 1',
51
- iconChecked: IconSource.ic_check_24,
52
- iconUnchecked: 'index + 1',
53
- circleColorActive: '#d82d8b',
54
- circleColorChecked: '#ffadd2',
55
- circleColorUnchecked: Colors.black_06,
56
- circleBorderColorActive: Colors.pink_09,
57
- circleBorderColorChecked: Colors.pink_09,
58
- circleBorderColorUnchecked: Colors.black_04,
59
- lineColorActive: '#ffd6e7',
60
- lineColorInActive: Colors.black_04,
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,
61
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/step",
3
- "version": "0.0.61-rc.1",
3
+ "version": "0.0.62-alpha.13",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},
@@ -8,7 +8,7 @@
8
8
  "react-native": ">=0.55",
9
9
  "prop-types": "^15.7.2",
10
10
  "react": "16.9.0",
11
- "@momo-kits/core": ">=0.0.5-beta"
11
+ "@momo-kits/core-v2": ">=0.0.5-beta"
12
12
  },
13
13
  "devDependencies": {},
14
14
  "license": "MoMo"
package/Step.constants.js DELETED
@@ -1 +0,0 @@
1
- export const IS_VALID_URL = /((\w+:\/\/\S+)|(\w+[\.:]\w+\S+))[^\s,\.]/