@momo-kits/step 0.0.60-beta → 0.0.60-beta.2

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,303 +1,57 @@
1
1
  import React, { Component } from 'react';
2
- import { View, StyleSheet } from 'react-native';
3
-
4
2
  import PropTypes from 'prop-types';
5
- import {
6
- Colors, Text, IconSource, Image
7
- } from '@momo-kits/core';
8
-
9
- const CIRCLE_SIZE = 24;
3
+ import HorizontalStep from './Step.horizontal';
4
+ import VerticalStep from './Step.vertical';
10
5
 
11
- const styles = StyleSheet.create({
12
- circle: {
13
- width: CIRCLE_SIZE,
14
- height: CIRCLE_SIZE,
15
- // borderWidth: 1,
16
- // borderColor: Colors.sepia_05,
17
- borderRadius: CIRCLE_SIZE / 2,
18
- backgroundColor: 'white'
19
- },
20
- line: {
21
- height: 4,
22
- backgroundColor: 'white',
23
- // borderWidth: 1,
24
- // borderRadius: 1,
25
- // borderStyle: 'dashed',
26
- zIndex: 0,
27
- // marginTop: 8
28
- },
29
- topRight: {
30
- position: 'absolute',
31
- right: -1,
32
- top: -1,
33
- width: 1,
34
- height: '100%',
35
- backgroundColor: 'white',
36
- zIndex: 1
37
- },
38
- topLeft: {
39
- position: 'absolute',
40
- left: -1,
41
- top: -1,
42
- width: '100%',
43
- height: 1,
44
- backgroundColor: 'white',
45
- zIndex: 1
46
- },
47
- topLeftWidth: {
48
- position: 'absolute',
49
- left: -1,
50
- top: -1,
51
- width: 1,
52
- height: '100%',
53
- backgroundColor: 'white',
54
- zIndex: 1
55
- },
56
- circleRow: {
57
- position: 'absolute',
58
- justifyContent: 'space-between',
59
- flexDirection: 'row',
60
- },
61
- circleColumn: {
62
- // position: 'absolute',
63
- justifyContent: 'space-between',
64
- },
65
- titleDefault: {
66
- color: Colors.black_12
67
- },
68
- titleActive: {
69
- color: Colors.black_17,
70
- fontWeight: 'bold'
71
- },
72
- containerStyle: {
73
- minHeight: CIRCLE_SIZE + 20 + CIRCLE_SIZE
74
- }
75
- });
6
+ import { Colors } from '@momo-kits/core';
76
7
 
77
8
  export default class Step extends Component {
78
9
  constructor(props) {
79
10
  super(props);
80
- this.state = {
81
- width: 0,
82
- height: 0
83
- };
84
- }
85
-
86
- onLayout = (e) => {
87
- this.setState({ width: e.nativeEvent.layout.width, height: e.nativeEvent.layout.height });
88
- }
89
-
90
- renderLine = () => {
91
- const {
92
- lineColor, lineStyle, currentStep, data
93
- } = this.props;
94
- return (
95
- <View style={[styles.line, { borderColor: lineColor }, lineStyle]}>
96
- {/* <View style={styles.topLeft} />
97
- <View style={styles.topLeftWidth} />
98
- <View style={styles.topRight} /> */}
99
- </View>
100
- );
101
- }
102
-
103
- circle = (value, index) => {
104
- const {
105
- currentStep, tintColor, data, lineStyle, isNumber, iconActive,
106
- iconInActive, lineColorActive, lineColorInActive, bodyStyle, iconStyle
107
- } = this.props;
108
- const { width } = this.state;
109
- const icon = currentStep >= (index + 1) ? iconActive || IconSource.ic_step_active : iconInActive || IconSource.ic_step_coming;
110
- const textFontStyle = currentStep >= (index + 1) ? styles.titleActive : styles.titleDefault;
111
- const itemWidth = (width - CIRCLE_SIZE) / data?.length;
112
- const lineActive = currentStep >= (index + 1) ? lineColorActive || isNumber ? Colors.pink_09 : Colors.sepia_05 : lineColorInActive || Colors.black_02;
113
- const lineWidth = (width - CIRCLE_SIZE) / (data.length - 1);
114
- const backgroundActive = currentStep >= (index + 1) ? Colors.pink_05_b : Colors.black_09;
115
- let left = 0;
116
- let textAlignStyle = { textAlign: 'center' };
117
- /**
118
- * item lefr
119
- */
120
- if (index === 0) {
121
- left = 0;
122
- textAlignStyle = { textAlign: 'left' };
123
-
124
- /**
125
- * item right
126
- */
127
- } else if (index === data?.length - 1) {
128
- left = -itemWidth + CIRCLE_SIZE;
129
- textAlignStyle = { textAlign: 'right' };
130
- /**
131
- * center item
132
- */
133
- } else { left = -itemWidth / 2 + CIRCLE_SIZE / 2; }
134
- const textStyle = [textAlignStyle, textFontStyle];
135
-
136
- return (
137
- <View key={index}>
138
- {
139
- data?.length - 1 !== index && (
140
- <View style={[styles.line, {
141
- position: 'absolute',
142
- top: 10,
143
- backgroundColor: lineActive,
144
- width: lineWidth,
145
- height: 4,
146
- marginTop: 0
147
- }, lineStyle]}
148
- />
149
- )
150
- }
151
- {
152
- isNumber ? (
153
- <View style={{
154
- width: CIRCLE_SIZE,
155
- height: CIRCLE_SIZE,
156
- borderRadius: CIRCLE_SIZE / 2,
157
- backgroundColor: backgroundActive,
158
- borderColor: Colors.pink_09,
159
- borderWidth: 1,
160
- alignItems: 'center',
161
- justifyContent: 'center'
162
- }}
163
- >
164
- <Text.SubTitle style={{ color: 'white' }} weight="bold">{index + 1}</Text.SubTitle>
165
- </View>
166
- ) : <Image source={icon} style={[styles.circle, { tintColor }, iconStyle]} />
167
- }
168
-
169
- <View style={{
170
- position: 'absolute',
171
- width: itemWidth,
172
- left,
173
- top: CIRCLE_SIZE + CIRCLE_SIZE / 4
174
- }}
175
- >
176
- <Text.Caption style={[textStyle, bodyStyle]}>{value}</Text.Caption>
177
- </View>
178
- </View>
179
- );
180
- }
181
-
182
- circleColumn = (value, index) => {
183
- const {
184
- currentStep, tintColor, data, lineStyle, isNumber, iconActive,
185
- iconInActive, lineColorActive, lineColorInActive, bodyStyle, iconStyle
186
- } = this.props;
187
- const { height } = this.state;
188
- const icon = currentStep >= (index + 1) ? iconActive || IconSource.ic_step_active : iconInActive || IconSource.ic_step_coming;
189
- const textFontStyle = currentStep >= (index + 1) ? styles.titleActive : styles.titleDefault;
190
- const itemWidth = (height - CIRCLE_SIZE) / data?.length;
191
- const lineActive = currentStep >= (index + 1) ? lineColorActive || isNumber ? Colors.pink_09 : Colors.sepia_05 : lineColorInActive || Colors.black_02;
192
- const lineWidth = (height - CIRCLE_SIZE) / (data.length - 1);
193
- const backgroundActive = currentStep >= (index + 1) ? Colors.pink_05_b : Colors.black_09;
194
- let left = 0;
195
- let textAlignStyle = { textAlign: 'center' };
196
- /**
197
- * item lefr
198
- */
199
- if (index === 0) {
200
- left = 0;
201
- textAlignStyle = { textAlign: 'left' };
202
-
203
- /**
204
- * item right
205
- */
206
- } else if (index === data?.length - 1) {
207
- left = -itemWidth + CIRCLE_SIZE;
208
- textAlignStyle = { textAlign: 'right' };
209
- /**
210
- * center item
211
- */
212
- } else { left = -itemWidth / 2 + CIRCLE_SIZE / 2; }
213
- const textStyle = [textAlignStyle, textFontStyle];
214
-
215
- return (
216
- <View key={index}>
217
- <View style={{ flexDirection: 'row', alignItems: 'center' }}>
218
- {
219
- isNumber ? (
220
- <View style={{
221
- width: CIRCLE_SIZE,
222
- height: CIRCLE_SIZE,
223
- borderRadius: CIRCLE_SIZE / 2,
224
- backgroundColor: backgroundActive,
225
- borderColor: Colors.pink_09,
226
- borderWidth: 1,
227
- alignItems: 'center',
228
- justifyContent: 'center'
229
- }}
230
- >
231
- {
232
- iconActive ? <Image source={iconActive} style={[styles.circle, { tintColor }, iconStyle]} /> : <Text.SubTitle style={{ color: 'white' }} weight="bold">{index + 1}</Text.SubTitle>
233
- }
234
- </View>
235
- ) : <Image source={icon} style={[styles.circle, { tintColor }, iconStyle]} />
236
- }
237
- <Text.Caption style={[{ marginLeft: 10 }, textStyle, bodyStyle]}>{value}</Text.Caption>
238
- </View>
239
-
240
- {
241
- data?.length - 1 !== index && (
242
- <View style={[styles.line, {
243
- left: 10,
244
- backgroundColor: lineActive,
245
- width: 4,
246
- height: lineWidth,
247
- marginTop: 0,
248
- }, lineStyle]}
249
- />
250
- )
251
- }
252
-
253
- </View>
254
- );
255
- }
256
-
257
- renderCircle = () => {
258
- const { data = [], isVertical } = this.props;
259
- return data.map(isVertical ? this.circleColumn : this.circle);
260
11
  }
261
12
 
262
13
  render() {
263
- const { width, height } = this.state;
264
- const { style, isVertical } = this.props;
265
- return (
266
- <View style={[styles.containerStyle, style]} onLayout={this.onLayout}>
267
- {/* {this.renderLine()} */}
268
- {
269
- isVertical ? (
270
- <View style={[styles.circleColumn, { height }]}>
271
- {this.renderCircle()}
272
- </View>
273
- ) : (
274
- <View style={[styles.circleRow, { width }]}>
275
- {this.renderCircle()}
276
- </View>
277
- )
278
- }
279
-
280
- </View>
281
- );
14
+ const { isVertical } = this.props;
15
+ let DefaultComponent = HorizontalStep;
16
+ if (isVertical) {
17
+ DefaultComponent = VerticalStep;
18
+ }
19
+ return <DefaultComponent {...this.props} />;
282
20
  }
283
21
  }
284
22
 
285
23
  Step.propTypes = {
286
- data: PropTypes.arrayOf(PropTypes.string),
24
+ titles: PropTypes.array,
287
25
  currentStep: PropTypes.number,
288
- tintColor: PropTypes.string,
289
26
  style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
290
- isNumber: PropTypes.bool,
27
+ items: PropTypes.array,
291
28
  isVertical: PropTypes.bool,
292
29
  iconActive: PropTypes.any,
293
- iconInActive: PropTypes.any,
30
+ iconChecked: PropTypes.any,
31
+ iconUnchecked: PropTypes.any,
32
+ circleColorActive: PropTypes.string,
33
+ circleColorChecked: PropTypes.string,
34
+ circleColorUnchecked: PropTypes.string,
35
+ circleBorderColorActive: PropTypes.string,
36
+ circleBorderColorChecked: PropTypes.string,
37
+ circleBorderColorUnchecked: PropTypes.string,
294
38
  lineColorActive: PropTypes.string,
295
39
  lineColorInActive: PropTypes.string,
296
- bodyStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
40
+ titleStyle: PropTypes.object,
41
+ descriptionStyle: PropTypes.object,
42
+ dateStyle: PropTypes.object,
297
43
  };
298
44
 
299
45
  Step.defaultProps = {
300
- data: [],
46
+ titles: [],
301
47
  currentStep: 0,
302
- tintColor: Colors.sepia_05
303
- };
48
+ isVertical: false,
49
+ circleColorActive: '#d82d8b',
50
+ circleColorChecked: '#ffadd2',
51
+ circleColorUnchecked: Colors.black_06,
52
+ circleBorderColorActive: Colors.pink_09,
53
+ circleBorderColorChecked: Colors.pink_09,
54
+ circleBorderColorUnchecked: Colors.black_04,
55
+ lineColorActive: '#ffd6e7',
56
+ lineColorInActive: Colors.black_04,
57
+ };