@momo-kits/step 0.0.74-beta → 0.72.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,279 @@
1
+ import {Colors, IconSource, Image, Spacing, Text} from '@momo-kits/core-v2';
2
+ import PropTypes from 'prop-types';
3
+ import React from 'react';
4
+ import {StyleSheet, View} from 'react-native';
5
+
6
+ const HorizontalStep = props => {
7
+ const {
8
+ steps = {},
9
+ currentStep,
10
+ type,
11
+ activeCircleColor,
12
+ inactiveCircleColor,
13
+ checkedCircleColor,
14
+ activeBorderColor,
15
+ inactiveBorderColor,
16
+ activeLineColor,
17
+ inactiveLineColor,
18
+ style,
19
+ size = 'default',
20
+ checkIcon,
21
+ errorIcon,
22
+ } = props;
23
+
24
+ let CIRCLE_SIZE = 24;
25
+ let CIRCLE_TEXT_SIZE = 12;
26
+ let ICON_SIZE = 16;
27
+ let TITLE_SIZE = {
28
+ size: 14,
29
+ lineHeight: 20,
30
+ };
31
+ let SUBTITLE_SIZE = {
32
+ size: 10,
33
+ lineHeight: 14,
34
+ };
35
+ let CONTENT_SIZE = {
36
+ size: 12,
37
+ lineHeight: 16,
38
+ };
39
+ const ICON_URL = checkIcon || IconSource.ic_check_24;
40
+ const ERROR_ICON_URL = errorIcon || IconSource.ic_close_x_24;
41
+ if (size === 'small') {
42
+ CIRCLE_SIZE = 16;
43
+ CIRCLE_TEXT_SIZE = 8;
44
+ ICON_SIZE = 12;
45
+ TITLE_SIZE = {
46
+ size: 12,
47
+ lineHeight: 16,
48
+ };
49
+ SUBTITLE_SIZE = {
50
+ size: 10,
51
+ lineHeight: 14,
52
+ };
53
+ CONTENT_SIZE = {
54
+ size: 10,
55
+ lineHeight: 14,
56
+ };
57
+ }
58
+
59
+ const renderCircle = (error, index) => {
60
+ let circleColor = inactiveCircleColor;
61
+ let borderColor = inactiveBorderColor;
62
+
63
+ if (index < currentStep) {
64
+ circleColor = checkedCircleColor;
65
+ } else if (index === currentStep) circleColor = activeCircleColor;
66
+
67
+ if (index <= currentStep) borderColor = activeBorderColor;
68
+
69
+ if (error) {
70
+ circleColor = Colors.red_03;
71
+ borderColor = Colors.red_08;
72
+ }
73
+ return (
74
+ <View
75
+ style={[
76
+ styles.circle,
77
+ {
78
+ width: CIRCLE_SIZE,
79
+ height: CIRCLE_SIZE,
80
+ borderRadius: CIRCLE_SIZE / 2,
81
+ borderColor: borderColor,
82
+ backgroundColor: circleColor,
83
+ },
84
+ ]}>
85
+ {renderCircleContent(error, index)}
86
+ </View>
87
+ );
88
+ };
89
+
90
+ const renderCircleContent = (error, index) => {
91
+ const icon = error ? ERROR_ICON_URL : ICON_URL;
92
+ if (type === 'check') {
93
+ return (
94
+ <Image
95
+ source={icon}
96
+ style={[
97
+ styles.icon,
98
+ {
99
+ width: ICON_SIZE,
100
+ height: ICON_SIZE,
101
+ },
102
+ ]}
103
+ />
104
+ );
105
+ } else if (type === 'combine') {
106
+ return index < currentStep ? (
107
+ <Image
108
+ source={icon}
109
+ style={[
110
+ styles.icon,
111
+ {
112
+ width: ICON_SIZE,
113
+ height: ICON_SIZE,
114
+ },
115
+ ]}
116
+ />
117
+ ) : (
118
+ <Text
119
+ style={[
120
+ styles.circleText,
121
+ {
122
+ fontSize: CIRCLE_TEXT_SIZE,
123
+ lineHeight: CIRCLE_TEXT_SIZE + 2,
124
+ },
125
+ ]}>
126
+ {index + 1}
127
+ </Text>
128
+ );
129
+ }
130
+ return (
131
+ <Text
132
+ style={[
133
+ styles.circleText,
134
+ {
135
+ fontSize: CIRCLE_TEXT_SIZE,
136
+ lineHeight: CIRCLE_TEXT_SIZE + 2,
137
+ },
138
+ ]}>
139
+ {index + 1}
140
+ </Text>
141
+ );
142
+ };
143
+
144
+ const renderLine = index => {
145
+ let lineColor = index < currentStep ? activeLineColor : inactiveLineColor;
146
+
147
+ if (index === -1 || index === steps.length - 1) {
148
+ lineColor = 'transparent';
149
+ }
150
+
151
+ return <View style={[styles.line, {backgroundColor: lineColor}]} />;
152
+ };
153
+
154
+ const renderStepPart = (item, index) => {
155
+ const {title, subTitle, content, error} = item;
156
+ const weight = index === currentStep ? '600' : '400';
157
+ const disabledColor = Colors.black_09;
158
+ const errorColor = Colors.error;
159
+ return (
160
+ <View key={index.toString()} style={styles.stepPart}>
161
+ <Text
162
+ style={[
163
+ styles.subTitle,
164
+ {
165
+ fontSize: SUBTITLE_SIZE.size,
166
+ lineHeight: SUBTITLE_SIZE.lineHeight,
167
+ color:
168
+ index < currentStep && !error ? disabledColor : Colors.black_12,
169
+ },
170
+ ]}>
171
+ {subTitle}
172
+ </Text>
173
+ <View
174
+ style={{
175
+ flexDirection: 'row',
176
+ alignItems: 'center',
177
+ }}>
178
+ {renderLine(index - 1)}
179
+ {renderCircle(error, index)}
180
+ {renderLine(index)}
181
+ </View>
182
+ <Text
183
+ style={[
184
+ styles.title,
185
+ {
186
+ lineHeight: TITLE_SIZE.lineHeight,
187
+ fontSize: TITLE_SIZE.size,
188
+ fontWeight: weight,
189
+ color: error
190
+ ? errorColor
191
+ : index < currentStep
192
+ ? disabledColor
193
+ : Colors.black_17,
194
+ },
195
+ ]}>
196
+ {title}
197
+ </Text>
198
+ <Text
199
+ style={[
200
+ styles.contentText,
201
+ {
202
+ fontSize: CONTENT_SIZE.size,
203
+ lineHeight: CONTENT_SIZE.lineHeight,
204
+ color:
205
+ index < currentStep && !error ? disabledColor : Colors.black_12,
206
+ },
207
+ ]}>
208
+ {content}
209
+ </Text>
210
+ </View>
211
+ );
212
+ };
213
+
214
+ return (
215
+ <View style={style}>
216
+ <View style={styles.container}>
217
+ {steps.map((item, index) => {
218
+ return renderStepPart(item, index);
219
+ })}
220
+ </View>
221
+ </View>
222
+ );
223
+ };
224
+
225
+ export default HorizontalStep;
226
+
227
+ const styles = StyleSheet.create({
228
+ container: {
229
+ flexDirection: 'row',
230
+ width: '100%',
231
+ },
232
+ circleContainer: {
233
+ flexDirection: 'column',
234
+ alignItems: 'center',
235
+ height: '100%',
236
+ },
237
+ circle: {
238
+ borderWidth: 2,
239
+ justifyContent: 'center',
240
+ alignItems: 'center',
241
+ margin: Spacing.XS,
242
+ },
243
+ contentContainer: {
244
+ marginLeft: Spacing.S,
245
+ flex: 1,
246
+ },
247
+ content: {marginVertical: Spacing.XS},
248
+ contentText: {
249
+ color: Colors.black_12,
250
+ },
251
+ header: {
252
+ flexDirection: 'row',
253
+ justifyContent: 'space-between',
254
+ alignItems: 'center',
255
+ },
256
+ title: {
257
+ marginBottom: Spacing.XS,
258
+ },
259
+ subTitle: {
260
+ color: Colors.black_12,
261
+ },
262
+ line: {
263
+ height: 2,
264
+ borderRadius: 1,
265
+ flex: 1,
266
+ },
267
+ icon: {
268
+ tintColor: Colors.white,
269
+ },
270
+ circleText: {
271
+ color: Colors.white,
272
+ fontWeight: '600',
273
+ },
274
+ stepPart: {
275
+ flexDirection: 'column',
276
+ alignItems: 'center',
277
+ flex: 1,
278
+ },
279
+ });
@@ -0,0 +1,299 @@
1
+ import React from 'react';
2
+ import {StyleSheet, View, Image} from 'react-native';
3
+ import PropTypes from 'prop-types';
4
+ import Colors from '../../core/colors';
5
+ import Text from '../../core/components/typography';
6
+ import Spacing from '../../core/spacing';
7
+ import {Icons as IconSource} from '../../core/icons';
8
+
9
+ const CIRCLE_SIZE = 24;
10
+ const CIRCLE_TEXT_SIZE = 12;
11
+ const ICON_SIZE = 16;
12
+ const ICON_URL = IconSource.ic_check_24;
13
+ const TITLE_SIZE = {
14
+ size: 12,
15
+ lineHeight: 16,
16
+ };
17
+ const SUBTITLE_SIZE = {
18
+ size: 10,
19
+ lineHeight: 14,
20
+ };
21
+ const CONTENT_SIZE = {
22
+ size: 12,
23
+ lineHeight: 16,
24
+ };
25
+
26
+ const HorizontalStep = props => {
27
+ const {
28
+ steps = {},
29
+ currentStep,
30
+ type,
31
+ activeCircleColor,
32
+ inactiveCircleColor,
33
+ checkedCircleColor,
34
+ activeBorderColor,
35
+ inactiveBorderColor,
36
+ activeLineColor,
37
+ inactiveLineColor,
38
+ style,
39
+ size = 'default',
40
+ checkIcon,
41
+ errorIcon,
42
+ } = props;
43
+
44
+ let CIRCLE_SIZE = 24;
45
+ let CIRCLE_TEXT_SIZE = 12;
46
+ let ICON_SIZE = 16;
47
+ let TITLE_SIZE = {
48
+ size: 14,
49
+ lineHeight: 20,
50
+ };
51
+ let SUBTITLE_SIZE = {
52
+ size: 10,
53
+ lineHeight: 14,
54
+ };
55
+ let CONTENT_SIZE = {
56
+ size: 12,
57
+ lineHeight: 16,
58
+ };
59
+ const ICON_URL = checkIcon || IconSource.ic_check_24;
60
+ const ERROR_ICON_URL = errorIcon || IconSource.ic_close_x_24;
61
+ if (size === 'small') {
62
+ CIRCLE_SIZE = 16;
63
+ CIRCLE_TEXT_SIZE = 8;
64
+ ICON_SIZE = 12;
65
+ TITLE_SIZE = {
66
+ size: 12,
67
+ lineHeight: 16,
68
+ };
69
+ SUBTITLE_SIZE = {
70
+ size: 10,
71
+ lineHeight: 14,
72
+ };
73
+ CONTENT_SIZE = {
74
+ size: 10,
75
+ lineHeight: 14,
76
+ };
77
+ }
78
+
79
+ const renderCircle = (error, index) => {
80
+ let circleColor = inactiveCircleColor;
81
+ let borderColor = inactiveBorderColor;
82
+
83
+ if (index < currentStep) {
84
+ circleColor = checkedCircleColor;
85
+ } else if (index === currentStep) circleColor = activeCircleColor;
86
+
87
+ if (index <= currentStep) borderColor = activeBorderColor;
88
+
89
+ if (error) {
90
+ circleColor = Colors.red_03;
91
+ borderColor = Colors.red_08;
92
+ }
93
+ return (
94
+ <View
95
+ style={[
96
+ styles.circle,
97
+ {
98
+ width: CIRCLE_SIZE,
99
+ height: CIRCLE_SIZE,
100
+ borderRadius: CIRCLE_SIZE / 2,
101
+ borderColor: borderColor,
102
+ backgroundColor: circleColor,
103
+ },
104
+ ]}>
105
+ {renderCircleContent(error, index)}
106
+ </View>
107
+ );
108
+ };
109
+
110
+ const renderCircleContent = (error, index) => {
111
+ const icon = error ? ERROR_ICON_URL : ICON_URL;
112
+ if (type === 'check') {
113
+ return (
114
+ <Image
115
+ source={icon}
116
+ style={[
117
+ styles.icon,
118
+ {
119
+ width: ICON_SIZE,
120
+ height: ICON_SIZE,
121
+ },
122
+ ]}
123
+ />
124
+ );
125
+ } else if (type === 'combine') {
126
+ return index < currentStep ? (
127
+ <Image
128
+ source={icon}
129
+ style={[
130
+ styles.icon,
131
+ {
132
+ width: ICON_SIZE,
133
+ height: ICON_SIZE,
134
+ },
135
+ ]}
136
+ />
137
+ ) : (
138
+ <Text
139
+ style={[
140
+ styles.circleText,
141
+ {
142
+ fontSize: CIRCLE_TEXT_SIZE,
143
+ lineHeight: CIRCLE_TEXT_SIZE + 2,
144
+ },
145
+ ]}>
146
+ {index + 1}
147
+ </Text>
148
+ );
149
+ }
150
+ return (
151
+ <Text
152
+ style={[
153
+ styles.circleText,
154
+ {
155
+ fontSize: CIRCLE_TEXT_SIZE,
156
+ lineHeight: CIRCLE_TEXT_SIZE + 2,
157
+ },
158
+ ]}>
159
+ {index + 1}
160
+ </Text>
161
+ );
162
+ };
163
+
164
+ const renderLine = index => {
165
+ let lineColor = index < currentStep ? activeLineColor : inactiveLineColor;
166
+
167
+ if (index === -1 || index === steps.length - 1) {
168
+ lineColor = 'transparent';
169
+ }
170
+
171
+ return <View style={[styles.line, {backgroundColor: lineColor}]} />;
172
+ };
173
+
174
+ const renderStepPart = (item, index) => {
175
+ const {title, subTitle, content, error} = item;
176
+ const weight = index === currentStep ? '600' : '400';
177
+ const disabledColor = Colors.black_09;
178
+ const errorColor = Colors.error;
179
+ return (
180
+ <View key={index.toString()} style={styles.stepPart}>
181
+ <Text
182
+ style={[
183
+ styles.subTitle,
184
+ {
185
+ fontSize: SUBTITLE_SIZE.size,
186
+ lineHeight: SUBTITLE_SIZE.lineHeight,
187
+ color:
188
+ index < currentStep && !error ? disabledColor : Colors.black_12,
189
+ },
190
+ ]}>
191
+ {subTitle}
192
+ </Text>
193
+ <View
194
+ style={{
195
+ flexDirection: 'row',
196
+ alignItems: 'center',
197
+ }}>
198
+ {renderLine(index - 1)}
199
+ {renderCircle(error, index)}
200
+ {renderLine(index)}
201
+ </View>
202
+ <Text
203
+ style={[
204
+ styles.title,
205
+ {
206
+ lineHeight: TITLE_SIZE.lineHeight,
207
+ fontSize: TITLE_SIZE.size,
208
+ fontWeight: weight,
209
+ color: error
210
+ ? errorColor
211
+ : index < currentStep
212
+ ? disabledColor
213
+ : Colors.black_17,
214
+ },
215
+ ]}>
216
+ {title}
217
+ </Text>
218
+ <Text
219
+ style={[
220
+ styles.contentText,
221
+ {
222
+ fontSize: CONTENT_SIZE.size,
223
+ lineHeight: CONTENT_SIZE.lineHeight,
224
+ color:
225
+ index < currentStep && !error ? disabledColor : Colors.black_12,
226
+ },
227
+ ]}>
228
+ {content}
229
+ </Text>
230
+ </View>
231
+ );
232
+ };
233
+
234
+ return (
235
+ <View style={style}>
236
+ <View style={styles.container}>
237
+ {steps.map((item, index) => {
238
+ return renderStepPart(item, index);
239
+ })}
240
+ </View>
241
+ </View>
242
+ );
243
+ };
244
+
245
+ export default HorizontalStep;
246
+
247
+ const styles = StyleSheet.create({
248
+ container: {
249
+ flexDirection: 'row',
250
+ width: '100%',
251
+ },
252
+ circleContainer: {
253
+ flexDirection: 'column',
254
+ alignItems: 'center',
255
+ height: '100%',
256
+ },
257
+ circle: {
258
+ borderWidth: 2,
259
+ justifyContent: 'center',
260
+ alignItems: 'center',
261
+ margin: Spacing.XS,
262
+ },
263
+ contentContainer: {
264
+ marginLeft: Spacing.S,
265
+ flex: 1,
266
+ },
267
+ content: {marginVertical: Spacing.XS},
268
+ contentText: {
269
+ color: Colors.black_12,
270
+ },
271
+ header: {
272
+ flexDirection: 'row',
273
+ justifyContent: 'space-between',
274
+ alignItems: 'center',
275
+ },
276
+ title: {
277
+ marginBottom: Spacing.XS,
278
+ },
279
+ subTitle: {
280
+ color: Colors.black_12,
281
+ },
282
+ line: {
283
+ height: 2,
284
+ borderRadius: 1,
285
+ flex: 1,
286
+ },
287
+ icon: {
288
+ tintColor: Colors.white,
289
+ },
290
+ circleText: {
291
+ color: Colors.white,
292
+ fontWeight: '600',
293
+ },
294
+ stepPart: {
295
+ flexDirection: 'column',
296
+ alignItems: 'center',
297
+ flex: 1,
298
+ },
299
+ });