@momo-kits/step 0.0.43-beta.22 → 0.0.43-beta.25

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.js CHANGED
@@ -1,227 +1,20 @@
1
1
  import React, { Component } from 'react';
2
- import { View, StyleSheet } from 'react-native';
3
-
4
- import PropTypes, { string } from 'prop-types';
5
- import { Colors, Text, IconSource, Image, Icon } from '@momo-kits/core';
6
- import { getUrlByTime } from '../../core/components/image/utils';
7
- import { ScrollView } from 'react-native-gesture-handler';
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
- checkedCircle: {
20
- width: CIRCLE_SIZE,
21
- height: CIRCLE_SIZE,
22
- borderRadius: CIRCLE_SIZE / 2,
23
- backgroundColor: '#ffadd2',
24
- borderWidth: 2,
25
- borderColor: Colors.pink_09,
26
- },
27
- titleDefault: {
28
- color: Colors.black_12,
29
- fontSize: 14,
30
- fontWeight: 'normal',
31
- },
32
- titleActive: {
33
- color: Colors.black_17,
34
- fontSize: 14,
35
- fontWeight: 'bold',
36
- },
37
- containerStyle: {
38
- minHeight: CIRCLE_SIZE + 20 + CIRCLE_SIZE,
39
- },
40
- description: {
41
- fontSize: 12,
42
- color: Colors.black_12,
43
- paddingBottom: 16,
44
- paddingTop: 4,
45
- paddingLeft: 11,
46
- },
47
- date: {
48
- fontSize: 10,
49
- color: Colors.black_12,
50
- },
51
- number: {
52
- fontSize: 12,
53
- color: 'white',
54
- textAlign: 'center',
55
- lineHeight: 13,
56
- },
57
- });
2
+ import PropTypes from 'prop-types';
3
+ import HorizontalStep from './Step.horizontal';
4
+ import VerticalStep from './Step.vertical';
58
5
 
59
6
  export default class Step extends Component {
60
7
  constructor(props) {
61
8
  super(props);
62
- this.state = {
63
- width: 0,
64
- height: 0,
65
- };
66
9
  }
67
10
 
68
- onLayout = (e) => {
69
- this.setState({
70
- width: e.nativeEvent.layout.width,
71
- height: e.nativeEvent.layout.height,
72
- });
73
- };
74
-
75
- circleStep = (index) => {
76
- return (
77
- <View style={[styles.circle]}>
78
- <Text style={styles.number}>{index}</Text>
79
- </View>
80
- );
81
- };
82
-
83
- circleColumn = (value, index) => {
84
- const {
85
- currentStep,
86
- titles,
87
- lineStyle,
88
- iconActive,
89
- iconInActive,
90
- lineColorActive,
91
- lineColorInActive,
92
- items,
93
- currentStepColor,
94
- date,
95
- } = this.props;
96
- const { height } = this.state;
97
- let itemHeight = 0;
98
- const icon =
99
- currentStep >= index + 2
100
- ? iconActive || IconSource.ic_check_24
101
- : iconInActive || index + 1;
102
- var circleColor =
103
- currentStep >= index + 1 ? currentStepColor : Colors.black_06;
104
- var circleBorderColor =
105
- currentStep >= index + 1 ? Colors.pink_09 : Colors.black_04;
106
- const textFontStyle =
107
- currentStep === index + 1
108
- ? styles.titleActive
109
- : styles.titleDefault;
110
- const itemWidth = (height - CIRCLE_SIZE) / titles?.length;
111
- const lineActive =
112
- currentStep >= index + 2
113
- ? lineColorActive
114
- ? Colors.pink_09
115
- : '#ffd6e7'
116
- : lineColorInActive || Colors.black_04;
117
- console.log(typeof items[index]);
118
- return (
119
- <View
120
- onLayout={(event) => {
121
- const viewHeight = event.nativeEvent.layout.height;
122
- itemHeight = viewHeight;
123
- console.log({ itemHeight });
124
- }}
125
- key={index}
126
- style={{ flexDirection: 'row' }}>
127
- <View>
128
- {currentStep <= index + 1 ? (
129
- <View
130
- style={[
131
- styles.circle,
132
- {
133
- backgroundColor: circleColor,
134
- borderColor: circleBorderColor,
135
- },
136
- ]}>
137
- <Text style={styles.number}>{icon}</Text>
138
- </View>
139
- ) : (
140
- <View>
141
- <Image
142
- source={icon}
143
- style={[
144
- styles.checkedCircle,
145
- { tintColor: '#ffd6e7' },
146
- ]}
147
- />
148
- </View>
149
- )}
150
- {titles?.length - 1 !== index && (
151
- <View
152
- style={[
153
- styles.line,
154
- {
155
- left: 11,
156
- backgroundColor: lineActive,
157
- width: 2,
158
- minHeight: 10,
159
- marginTop: 4,
160
- marginBottom: 4,
161
- flex: 1,
162
- },
163
- lineStyle,
164
- ]}
165
- />
166
- )}
167
- </View>
168
- <View
169
- style={[{ width: '100%', paddingRight: 48, marginTop: 4 }]}>
170
- <View
171
- style={{
172
- flexDirection: 'row',
173
- justifyContent: 'space-between',
174
- alignItems: 'center',
175
- }}>
176
- <Text.Caption
177
- style={[{ marginLeft: 10 }, textFontStyle]}>
178
- {value}
179
- </Text.Caption>
180
- {currentStep >= index + 1 && (
181
- <Text style={styles.date}>{date}</Text>
182
- )}
183
- </View>
184
- <View>
185
- {typeof items[index] == 'string' ? (
186
- <Text style={[styles.description]}>
187
- {items[index]}
188
- </Text>
189
- ) : (
190
- <View style={[styles.description]}>
191
- {items[index]}
192
- </View>
193
- )}
194
- </View>
195
- </View>
196
- </View>
197
- );
198
- };
199
-
200
- renderCircle = () => {
201
- const { titles = [[]] } = this.props;
202
- return titles.map(this.circleColumn);
203
- };
204
-
205
11
  render() {
206
- const { width, height } = this.state;
207
- const { style, isVertical } = this.props;
208
- return (
209
- <ScrollView>
210
- <View
211
- style={[styles.containerStyle, style]}
212
- onLayout={this.onLayout}>
213
- {isVertical ? (
214
- <View style={[styles.circleColumn, { height }]}>
215
- {this.renderCircle()}
216
- </View>
217
- ) : (
218
- <View style={[styles.circleRow, { width }]}>
219
- {this.renderCircle()}
220
- </View>
221
- )}
222
- </View>
223
- </ScrollView>
224
- );
12
+ const { isVertical } = this.props;
13
+ let DefaultComponent = HorizontalStep;
14
+ if (isVertical) {
15
+ DefaultComponent = VerticalStep;
16
+ }
17
+ return <DefaultComponent {...this.props} />;
225
18
  }
226
19
  }
227
20
 
@@ -237,6 +30,7 @@ Step.propTypes = {
237
30
  lineColorInActive: PropTypes.string,
238
31
  borderColorActive: PropTypes.string,
239
32
  borderColorInActive: PropTypes.string,
33
+ titleFontSize: PropTypes.number,
240
34
  };
241
35
 
242
36
  Step.defaultProps = {
@@ -0,0 +1,242 @@
1
+ import { Colors, IconSource, Image, Text } from '@momo-kits/core';
2
+ import PropTypes from 'prop-types';
3
+ import React, { Component } from 'react';
4
+ import { StyleSheet, View } from 'react-native';
5
+ import { ScrollView } from 'react-native-gesture-handler';
6
+
7
+
8
+ const CIRCLE_SIZE = 24;
9
+
10
+ // this is layout of each item (flexdirection row)
11
+ // this is left container (flex 0.2, )
12
+ // this is value label
13
+ // this is image
14
+ // this is caption label
15
+ // this is desc label
16
+ // this is right container (flex 0.8)
17
+ // this is line (width flex = 1 or width 100 percent)
18
+
19
+ const styles = StyleSheet.create({
20
+ circle: {
21
+ width: CIRCLE_SIZE,
22
+ height: CIRCLE_SIZE,
23
+ borderRadius: CIRCLE_SIZE / 2,
24
+ borderWidth: 2,
25
+ padding: 4,
26
+ },
27
+ checkedCircle: {
28
+ width: CIRCLE_SIZE,
29
+ height: CIRCLE_SIZE,
30
+ borderRadius: CIRCLE_SIZE / 2,
31
+ backgroundColor: '#ffadd2',
32
+ borderWidth: 2,
33
+ borderColor: Colors.pink_09,
34
+ },
35
+ titleDefault: {
36
+ color: Colors.black_12,
37
+ fontSize: 14,
38
+ fontWeight: 'normal',
39
+ },
40
+ titleActive: {
41
+ color: Colors.black_17,
42
+ fontSize: 14,
43
+ fontWeight: 'bold',
44
+ },
45
+ containerStyle: {
46
+ minHeight: CIRCLE_SIZE + 20 + CIRCLE_SIZE,
47
+ },
48
+ description: {
49
+ fontSize: 12,
50
+ color: Colors.black_12,
51
+ marginBottom: 16,
52
+ paddingTop: 4,
53
+ paddingLeft: 11,
54
+ },
55
+ date: {
56
+ fontSize: 10,
57
+ color: Colors.black_12,
58
+ },
59
+ number: {
60
+ fontSize: 12,
61
+ color: 'white',
62
+ textAlign: 'center',
63
+ lineHeight: 13,
64
+ },
65
+ lineVertical: {
66
+ marginLeft: 11,
67
+ width: 2,
68
+ minHeight: 10,
69
+ marginTop: 4,
70
+ marginBottom: 4,
71
+ flex: 1,
72
+ },
73
+ minHeight: {
74
+ minHeight: 12,
75
+ marginBottom: 4,
76
+ },
77
+ });
78
+
79
+ export default class VerticalStep extends Component {
80
+ constructor(props) {
81
+ super(props);
82
+ this.state = {
83
+ width: 0,
84
+ height: 0,
85
+ };
86
+ }
87
+
88
+ onLayout = (e) => {
89
+ this.setState({
90
+ width: e.nativeEvent.layout.width,
91
+ height: e.nativeEvent.layout.height,
92
+ });
93
+ };
94
+
95
+ circleStep = (index) => {
96
+ return (
97
+ <View style={[styles.circle]}>
98
+ <Text style={styles.number}>{index}</Text>
99
+ </View>
100
+ );
101
+ };
102
+
103
+ circleColumn = (value, index) => {
104
+ const {
105
+ currentStep,
106
+ titles,
107
+ lineStyle,
108
+ iconActive,
109
+ iconInActive,
110
+ lineColorActive,
111
+ lineColorInActive,
112
+ items,
113
+ currentStepColor,
114
+ date,
115
+ isVertical,
116
+ } = this.props;
117
+ const icon =
118
+ currentStep >= index + 2
119
+ ? iconActive || IconSource.ic_check_24
120
+ : iconInActive || index + 1;
121
+ var circleColor =
122
+ currentStep >= index + 1 ? currentStepColor : Colors.black_06;
123
+ var circleBorderColor =
124
+ currentStep >= index + 1 ? Colors.pink_09 : Colors.black_04;
125
+ const textFontStyle =
126
+ currentStep === index + 1
127
+ ? styles.titleActive
128
+ : styles.titleDefault;
129
+ const lineActive =
130
+ currentStep >= index + 2
131
+ ? lineColorActive
132
+ ? Colors.pink_09
133
+ : '#ffd6e7'
134
+ : lineColorInActive || Colors.black_04;
135
+ return (
136
+ <View key={index} style={{ flexDirection: 'row' }}>
137
+ <View>
138
+ {currentStep <= index + 1 ? (
139
+ <View>
140
+ {/* image */}
141
+ <View
142
+ style={[
143
+ styles.circle,
144
+ {
145
+ backgroundColor: circleColor,
146
+ borderColor: circleBorderColor,
147
+ },
148
+ ]}>
149
+ <Text style={styles.number}>{icon}</Text>
150
+ </View>
151
+ </View>
152
+ ) : (
153
+ <View>
154
+ <Image
155
+ source={icon}
156
+ style={[
157
+ styles.checkedCircle,
158
+ { tintColor: '#ffd6e7' },
159
+ ]}
160
+ />
161
+ </View>
162
+ )}
163
+ {titles?.length - 1 !== index && (
164
+ <View
165
+ style={[
166
+ styles.lineVertical,
167
+ {
168
+ backgroundColor: lineActive,
169
+ },
170
+ lineStyle,
171
+ ]}
172
+ />
173
+ )}
174
+ </View>
175
+ <View
176
+ style={[{ width: '100%', paddingRight: 48, marginTop: 4 }]}>
177
+ <View
178
+ style={{
179
+ flexDirection: 'row',
180
+ justifyContent: 'space-between',
181
+ alignItems: 'center',
182
+ }}>
183
+ <Text.Caption
184
+ style={[{ marginLeft: 10 }, textFontStyle]}>
185
+ {value}
186
+ </Text.Caption>
187
+ {currentStep >= index + 1 && (
188
+ <Text style={styles.date}>{date}</Text>
189
+ )}
190
+ </View>
191
+ <View>
192
+ {typeof items[index] == 'string' ? (
193
+ <Text style={[styles.description]}>
194
+ {items[index]}
195
+ </Text>
196
+ ) : (
197
+ <View style={[styles.description]}>
198
+ {items[index]}
199
+ </View>
200
+ )}
201
+ </View>
202
+ </View>
203
+ </View>
204
+ );
205
+ };
206
+
207
+ renderCircle = () => {
208
+ const { titles = [[]] } = this.props;
209
+ return titles.map(this.circleColumn);
210
+ };
211
+
212
+ render() {
213
+ return (
214
+ <ScrollView>
215
+ <View style={[styles.containerStyle]} onLayout={this.onLayout}>
216
+ <View style={[styles.circleColumn]}>
217
+ {this.renderCircle()}
218
+ </View>
219
+ </View>
220
+ </ScrollView>
221
+ );
222
+ }
223
+ }
224
+
225
+ VerticalStep.propTypes = {
226
+ titles: PropTypes.array,
227
+ currentStep: PropTypes.number,
228
+ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
229
+ items: PropTypes.array,
230
+ isVertical: PropTypes.bool,
231
+ iconActive: PropTypes.any,
232
+ iconInActive: PropTypes.any,
233
+ lineColorActive: PropTypes.string,
234
+ lineColorInActive: PropTypes.string,
235
+ borderColorActive: PropTypes.string,
236
+ borderColorInActive: PropTypes.string,
237
+ };
238
+
239
+ VerticalStep.defaultProps = {
240
+ titles: [],
241
+ currentStep: 0,
242
+ };