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