@momo-kits/step 0.0.61-beta → 0.0.61-beta.3

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,401 @@
1
+ import React, { Component } from 'react';
2
+ import { View, StyleSheet, Image, ScrollView } from 'react-native';
3
+
4
+ import PropTypes from 'prop-types';
5
+ import Colors from '../../core/colors';
6
+ import Text from '../../core/components/typography';
7
+ import { Icons as IconSource } from '../../core/icons';
8
+
9
+ const CIRCLE_SIZE = 24;
10
+
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
+ 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>
110
+ </View>
111
+ );
112
+ };
113
+
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
+ }
185
+ }
186
+ return resultComponent;
187
+ };
188
+
189
+ _renderLine = ({ titles = {}, index = 0, lineActive = '' }) => {
190
+ let resultComponent = <></>;
191
+
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;
205
+ };
206
+
207
+ _renderTitle = ({ textFontStyle = {}, titleStyle = {}, value = {} }) => {
208
+ let resultComponent = (
209
+ <View>
210
+ <Text.Caption
211
+ style={[{ marginLeft: 10 }, textFontStyle, titleStyle]}>
212
+ {value}
213
+ </Text.Caption>
214
+ </View>
215
+ );
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
+ };
238
+
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;
256
+ };
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
+
314
+ 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
+ })}
332
+ </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
+ })}
353
+ </View>
354
+ </View>
355
+ );
356
+ };
357
+
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
+ }
374
+ }
375
+
376
+ VerticalStep.propTypes = {
377
+ titles: PropTypes.array,
378
+ 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,
396
+ };
397
+
398
+ VerticalStep.defaultProps = {
399
+ titles: [],
400
+ currentStep: 0,
401
+ };