@momo-kits/step 0.0.44-beta → 0.0.44-beta.1

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