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