@momo-kits/step 0.0.44-beta → 0.0.44-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
+ };
package/Step.web.js CHANGED
@@ -1,170 +1,61 @@
1
1
  import React, { Component } from 'react';
2
- import { View, StyleSheet, Image } from 'react-native';
3
- import PropTypes from 'prop-types';
4
- import { ColorCore } from '../../core/colors/colorCore';
5
- import Text from '../../core/components/typography';
6
- import { Icons } from '../../core/icons';
7
-
8
- const CIRCLE_SIZE = 18;
9
2
 
10
- const styles = StyleSheet.create({
11
- circle: {
12
- width: CIRCLE_SIZE,
13
- height: CIRCLE_SIZE,
14
- borderWidth: 1,
15
- borderColor: ColorCore.sepia_05,
16
- borderRadius: 9,
17
- backgroundColor: 'white'
18
- },
19
- line: {
20
- height: 1,
21
- backgroundColor: 'white',
22
- borderWidth: 1,
23
- borderRadius: 1,
24
- borderStyle: 'dashed',
25
- zIndex: 0,
26
- marginTop: 9
27
- },
28
- topRight: {
29
- position: 'absolute',
30
- right: -1,
31
- top: -1,
32
- width: 1,
33
- height: '100%',
34
- backgroundColor: 'white',
35
- zIndex: 1
36
- },
37
- topLeft: {
38
- position: 'absolute',
39
- left: -1,
40
- top: -1,
41
- width: '100%',
42
- height: 1,
43
- backgroundColor: 'white',
44
- zIndex: 1
45
- },
46
- topLeftWidth: {
47
- position: 'absolute',
48
- left: -1,
49
- top: -1,
50
- width: 1,
51
- height: '100%',
52
- backgroundColor: 'white',
53
- zIndex: 1
54
- },
55
- circleRow: {
56
- position: 'absolute',
57
- justifyContent: 'space-between',
58
- flexDirection: 'row',
59
- },
60
- titleDefault: {
61
- color: ColorCore.black_12
62
- },
63
- titleActive: {
64
- color: ColorCore.black_17,
65
- fontWeight: 'bold'
66
- },
67
- containerStyle: {
68
- minHeight: CIRCLE_SIZE + 20 + CIRCLE_SIZE
69
- }
70
- });
3
+ import PropTypes from 'prop-types';
4
+ import HorizontalStep from './Step.horizontal.web.js';
5
+ import VerticalStep from './Step.vertical.web.js';
6
+ import Colors from '../../core/colors';
7
+ import { Icons as IconSource } from '../../core/icons';
71
8
 
72
9
  export default class Step extends Component {
73
10
  constructor(props) {
74
11
  super(props);
75
- this.state = {
76
- width: 0
77
- };
78
- }
79
-
80
- onLayout = (e) => {
81
- this.setState({ width: e.nativeEvent.layout.width });
82
- }
83
-
84
- renderLine = () => {
85
- const { lineColor } = this.props;
86
- return (
87
- <View style={[styles.line, { borderColor: lineColor }]}>
88
- <View style={styles.topLeft} />
89
- <View style={styles.topLeftWidth} />
90
- <View style={styles.topRight} />
91
- </View>
92
- );
93
- }
94
-
95
- circle = (value, index) => {
96
- const { currentStep, tintColor, data } = this.props;
97
- const { width } = this.state;
98
- const icon = currentStep >= (index + 1) ? Icons.ic_step_active : Icons.ic_step_coming;
99
- const textFontStyle = currentStep >= (index + 1) ? styles.titleActive : styles.titleDefault;
100
- const itemWidth = (width - CIRCLE_SIZE) / data?.length;
101
- let left = 0;
102
- let textAlignStyle = { textAlign: 'center' };
103
- /**
104
- * item lefr
105
- */
106
- if (index === 0) {
107
- left = 0;
108
- textAlignStyle = { textAlign: 'left' };
109
-
110
- /**
111
- * item right
112
- */
113
- } else if (index === data?.length - 1) {
114
- left = -itemWidth + CIRCLE_SIZE;
115
- textAlignStyle = { textAlign: 'right' };
116
- /**
117
- * center item
118
- */
119
- } else { left = -itemWidth / 2 + CIRCLE_SIZE / 2; }
120
- const textStyle = [textAlignStyle, textFontStyle];
121
- return (
122
- <View>
123
- <Image source={icon} style={[styles.circle, { tintColor }]} />
124
- <View style={{
125
- position: 'absolute',
126
- width: itemWidth,
127
- left,
128
- top: CIRCLE_SIZE + CIRCLE_SIZE / 2
129
- }}
130
- >
131
- <Text.Title style={textStyle}>{value}</Text.Title>
132
- </View>
133
- </View>
134
- );
135
- }
136
-
137
- renderCircle = () => {
138
- const { data = [] } = this.props;
139
- const views = data.map(this.circle);
140
- return views;
141
12
  }
142
13
 
143
14
  render() {
144
- const { width } = this.state;
145
- const { style } = this.props;
146
- return (
147
- <View style={[styles.containerStyle, style]} onLayout={this.onLayout}>
148
- {this.renderLine()}
149
- <View style={[styles.circleRow, { width }]}>
150
- {this.renderCircle()}
151
- </View>
152
- </View>
153
- );
15
+ const { isVertical } = this.props;
16
+ let DefaultComponent = HorizontalStep;
17
+ if (isVertical) {
18
+ DefaultComponent = VerticalStep;
19
+ }
20
+ return <DefaultComponent {...this.props} />;
154
21
  }
155
22
  }
156
23
 
157
24
  Step.propTypes = {
158
- lineColor: PropTypes.string,
159
- data: PropTypes.arrayOf(PropTypes.string),
25
+ titles: PropTypes.array,
160
26
  currentStep: PropTypes.number,
161
- tintColor: PropTypes.string,
162
27
  style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
28
+ items: PropTypes.array,
29
+ isVertical: PropTypes.bool,
30
+ iconActive: PropTypes.any,
31
+ iconChecked: PropTypes.any,
32
+ iconUnchecked: PropTypes.any,
33
+ circleColorActive: PropTypes.string,
34
+ circleColorChecked: PropTypes.string,
35
+ circleColorUnchecked: PropTypes.string,
36
+ circleBorderColorActive: PropTypes.string,
37
+ circleBorderColorChecked: PropTypes.string,
38
+ circleBorderColorUnchecked: PropTypes.string,
39
+ lineColorActive: PropTypes.string,
40
+ lineColorInActive: PropTypes.string,
41
+ titleStyle: PropTypes.object,
42
+ descriptionStyle: PropTypes.object,
43
+ dateStyle: PropTypes.object,
163
44
  };
164
45
 
165
46
  Step.defaultProps = {
166
- data: [],
167
- lineColor: '#fa541c',
47
+ titles: [],
168
48
  currentStep: 0,
169
- tintColor: '#fa541c'
49
+ isVertical: false,
50
+ iconActive: 'index + 1',
51
+ iconChecked: IconSource.ic_check_24,
52
+ iconUnchecked: 'index + 1',
53
+ circleColorActive: '#d82d8b',
54
+ circleColorChecked: '#ffadd2',
55
+ circleColorUnchecked: Colors.black_06,
56
+ circleBorderColorActive: Colors.pink_09,
57
+ circleBorderColorChecked: Colors.pink_09,
58
+ circleBorderColorUnchecked: Colors.black_04,
59
+ lineColorActive: '#ffd6e7',
60
+ lineColorInActive: Colors.black_04,
170
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/step",
3
- "version": "0.0.44-beta",
3
+ "version": "0.0.44-beta.3",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},
package/publish.sh CHANGED
@@ -21,7 +21,7 @@ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type
21
21
  #npm login
22
22
  #publish dist to npm
23
23
  cd dist
24
- npm publish --access=public
24
+ npm publish --tag beta --access=public
25
25
  cd ..
26
26
  rm -rf dist
27
27