@momo-kits/step 0.0.43-beta.23 → 0.0.43-beta.26

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