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