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