@momo-kits/step 0.103.2-rc.8 → 0.109.1-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/StepsHorizontal.tsx +22 -21
- package/StepsVertical.tsx +50 -32
- package/dist/StepIcon.tsx +75 -0
- package/dist/StepsHorizontal.tsx +157 -0
- package/dist/StepsVertical.tsx +116 -0
- package/dist/index.tsx +20 -0
- package/dist/package.json +17 -0
- package/dist/publish.sh +27 -0
- package/dist/styles.ts +60 -0
- package/dist/types.ts +157 -0
- package/dist/utils.ts +175 -0
- package/index.tsx +2 -2
- package/package.json +15 -15
- package/types.ts +33 -3
- package/utils.ts +84 -34
package/StepsHorizontal.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import {FlexAlignType, TouchableOpacity, View} from 'react-native';
|
|
|
4
4
|
import StepIcon from './StepIcon';
|
|
5
5
|
import styles from './styles';
|
|
6
6
|
import {Step, StepsProps} from './types';
|
|
7
|
-
import {getStepColor, getStepTypo} from './utils';
|
|
7
|
+
import { getStepColor, getStepTypo} from './utils';
|
|
8
8
|
|
|
9
9
|
type TextAlign = 'left' | 'right' | 'center';
|
|
10
10
|
|
|
@@ -18,9 +18,9 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
18
18
|
onPress,
|
|
19
19
|
disabled,
|
|
20
20
|
}) => {
|
|
21
|
-
const renderStepItem = (
|
|
22
|
-
const {title, description, error, time} =
|
|
23
|
-
let typoStyle = getStepTypo(activeIndex,
|
|
21
|
+
const renderStepItem = (item: Step, index: number) => {
|
|
22
|
+
const {title, description, error, time} = item;
|
|
23
|
+
let typoStyle = getStepTypo(activeIndex, index, error, size, 'horizontal');
|
|
24
24
|
const {theme} = useContext(ApplicationContext);
|
|
25
25
|
let alignItems: FlexAlignType = 'center';
|
|
26
26
|
let textAlign: TextAlign = 'center';
|
|
@@ -32,28 +32,28 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
32
32
|
alignItems = 'flex-end';
|
|
33
33
|
textAlign = 'right';
|
|
34
34
|
} else if (align === 'stretch') {
|
|
35
|
-
if (
|
|
35
|
+
if (index === 0) {
|
|
36
36
|
alignItems = 'flex-start';
|
|
37
37
|
textAlign = 'left';
|
|
38
|
-
} else if (
|
|
38
|
+
} else if (index === steps.length - 1) {
|
|
39
39
|
textAlign = 'right';
|
|
40
40
|
alignItems = 'flex-end';
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const haveMarginRight =
|
|
45
|
-
|
|
45
|
+
index !== steps.length - 1 && align !== 'center' && align !== 'stretch';
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<TouchableOpacity
|
|
49
|
-
key={`Step ${
|
|
49
|
+
key={`Step ${index}`}
|
|
50
50
|
style={{
|
|
51
51
|
flex: 1,
|
|
52
52
|
alignItems,
|
|
53
53
|
marginRight: haveMarginRight ? Spacing.XS : 0,
|
|
54
54
|
}}
|
|
55
55
|
disabled={disabled || !onPress}
|
|
56
|
-
onPress={onPress}>
|
|
56
|
+
onPress={() => onPress && onPress(item, index)}>
|
|
57
57
|
{!!time && (
|
|
58
58
|
<Text
|
|
59
59
|
style={{textAlign}}
|
|
@@ -62,7 +62,7 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
62
62
|
{time}
|
|
63
63
|
</Text>
|
|
64
64
|
)}
|
|
65
|
-
{renderStepIcon(
|
|
65
|
+
{renderStepIcon(item, index, align, disabled)}
|
|
66
66
|
{!!title && (
|
|
67
67
|
<Text
|
|
68
68
|
style={[styles.title, {textAlign}]}
|
|
@@ -86,20 +86,21 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
const renderStepIcon = (
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
item: Step,
|
|
90
|
+
index: number,
|
|
91
91
|
align: string = 'center',
|
|
92
|
-
disabled
|
|
92
|
+
disabled?: boolean
|
|
93
93
|
) => {
|
|
94
|
-
const {error} =
|
|
94
|
+
const {error} = item;
|
|
95
95
|
|
|
96
|
-
const stepStyle = getStepColor(activeIndex,
|
|
96
|
+
const stepStyle = getStepColor(activeIndex, index, error, steps.length, disabled);
|
|
97
97
|
const {backgroundColor, borderColor, lineColorRight, lineColorLeft} =
|
|
98
98
|
stepStyle;
|
|
99
99
|
|
|
100
|
-
const lineLeftHide =
|
|
100
|
+
const lineLeftHide =
|
|
101
|
+
(align === 'stretch' && index === 0) || align === 'left';
|
|
101
102
|
const lineRightHide =
|
|
102
|
-
(align === 'stretch' &&
|
|
103
|
+
(align === 'stretch' && index === steps.length - 1) || align === 'right';
|
|
103
104
|
|
|
104
105
|
return (
|
|
105
106
|
<View style={styles.rowStep}>
|
|
@@ -124,9 +125,9 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
124
125
|
marginLeft: !lineLeftHide ? Spacing.XS : 0,
|
|
125
126
|
marginVertical: Spacing.XS,
|
|
126
127
|
}}
|
|
127
|
-
index={
|
|
128
|
+
index={index}
|
|
128
129
|
useNumber={useNumber}
|
|
129
|
-
isActive={activeIndex ===
|
|
130
|
+
isActive={activeIndex === index}
|
|
130
131
|
customIcon={customIcon}
|
|
131
132
|
/>
|
|
132
133
|
{!lineRightHide && (
|
|
@@ -146,8 +147,8 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
146
147
|
|
|
147
148
|
return (
|
|
148
149
|
<View style={{flexDirection: 'row'}}>
|
|
149
|
-
{steps.map((
|
|
150
|
-
return renderStepItem(
|
|
150
|
+
{steps.map((item, index) => {
|
|
151
|
+
return renderStepItem(item, index);
|
|
151
152
|
})}
|
|
152
153
|
</View>
|
|
153
154
|
);
|
package/StepsVertical.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {ApplicationContext, Spacing, Text} from '@momo-kits/foundation';
|
|
1
|
+
import {ApplicationContext, Colors, Spacing, Text} from '@momo-kits/foundation';
|
|
2
2
|
import React, {FC, useContext} from 'react';
|
|
3
|
-
import {View} from 'react-native';
|
|
3
|
+
import {View, TouchableOpacity} from 'react-native';
|
|
4
4
|
import StepIcon from './StepIcon';
|
|
5
5
|
import styles from './styles';
|
|
6
6
|
import {Step, StepsProps} from './types';
|
|
@@ -11,43 +11,63 @@ const StepsVertical: FC<StepsProps> = ({
|
|
|
11
11
|
activeIndex,
|
|
12
12
|
size,
|
|
13
13
|
useNumber = false,
|
|
14
|
+
onPress,
|
|
15
|
+
disabled,
|
|
14
16
|
}) => {
|
|
15
17
|
const {theme} = useContext(ApplicationContext);
|
|
16
18
|
|
|
17
|
-
const renderStepItem = (
|
|
18
|
-
const {error, description, title, time} =
|
|
19
|
+
const renderStepItem = (item: Step, index: number) => {
|
|
20
|
+
const {error, description, title, time} = item;
|
|
19
21
|
|
|
20
|
-
const stepStyle = getStepColor(activeIndex,
|
|
21
|
-
|
|
22
|
+
const stepStyle = getStepColor(activeIndex, index, error, steps.length);
|
|
23
|
+
const typoStyle = getStepTypo(activeIndex, index, error, size, 'vertical');
|
|
22
24
|
|
|
23
25
|
const {backgroundColor, borderColor} = stepStyle;
|
|
24
26
|
const lineColor =
|
|
25
|
-
activeIndex >
|
|
27
|
+
activeIndex > index
|
|
26
28
|
? theme.colors.primary + '33'
|
|
27
29
|
: theme.colors.background.default;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* build description
|
|
33
|
+
*/
|
|
34
|
+
const buildDescription = () => {
|
|
35
|
+
if (typeof description === 'string') {
|
|
36
|
+
return (
|
|
37
|
+
<Text
|
|
38
|
+
color={disabled ? theme.colors.text.disable : typoStyle.title.color}
|
|
39
|
+
typography={typoStyle.description.typography}>
|
|
40
|
+
{description}
|
|
41
|
+
</Text>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return description;
|
|
45
|
+
};
|
|
46
|
+
|
|
28
47
|
return (
|
|
29
|
-
<
|
|
30
|
-
key={`Step ${
|
|
48
|
+
<TouchableOpacity
|
|
49
|
+
key={`Step ${index}`}
|
|
31
50
|
style={{
|
|
32
51
|
flexDirection: 'row',
|
|
33
52
|
marginBottom: Spacing.XS,
|
|
34
|
-
}}
|
|
53
|
+
}}
|
|
54
|
+
disabled={disabled || !onPress}
|
|
55
|
+
onPress={() => onPress && onPress(item, index)}>
|
|
35
56
|
<View
|
|
36
57
|
style={{
|
|
37
58
|
alignItems: 'center',
|
|
38
59
|
marginRight: Spacing.M,
|
|
39
|
-
minHeight: 48,
|
|
40
60
|
}}>
|
|
41
61
|
<StepIcon
|
|
42
62
|
size={size}
|
|
43
63
|
error={error}
|
|
44
|
-
backgroundColor={backgroundColor}
|
|
45
|
-
borderColor={borderColor}
|
|
64
|
+
backgroundColor={disabled ? Colors.pink_08 : backgroundColor}
|
|
65
|
+
borderColor={disabled ? Colors.pink_10 : borderColor}
|
|
46
66
|
useNumber={useNumber}
|
|
47
|
-
index={
|
|
48
|
-
isActive={activeIndex ===
|
|
67
|
+
index={index}
|
|
68
|
+
isActive={activeIndex === index}
|
|
49
69
|
/>
|
|
50
|
-
{
|
|
70
|
+
{index !== steps.length - 1 && (
|
|
51
71
|
<View
|
|
52
72
|
style={[
|
|
53
73
|
styles.lineVertical,
|
|
@@ -58,38 +78,36 @@ const StepsVertical: FC<StepsProps> = ({
|
|
|
58
78
|
</View>
|
|
59
79
|
<View style={{flex: 1}}>
|
|
60
80
|
<View
|
|
61
|
-
style={
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
]}>
|
|
81
|
+
style={{
|
|
82
|
+
flexDirection: 'row',
|
|
83
|
+
justifyContent: 'space-between',
|
|
84
|
+
}}>
|
|
67
85
|
<Text
|
|
68
86
|
numberOfLines={2}
|
|
69
87
|
style={{marginRight: Spacing.S, flex: 1}}
|
|
70
|
-
color={
|
|
88
|
+
color={
|
|
89
|
+
disabled ? theme.colors.text.disable : typoStyle.title.color
|
|
90
|
+
}
|
|
71
91
|
typography={typoStyle.title.typography}>
|
|
72
92
|
{title}
|
|
73
93
|
</Text>
|
|
74
94
|
<Text
|
|
75
|
-
color={
|
|
95
|
+
color={
|
|
96
|
+
disabled ? theme.colors.text.disable : typoStyle.time.color
|
|
97
|
+
}
|
|
76
98
|
typography={typoStyle.time.typography}>
|
|
77
99
|
{time}
|
|
78
100
|
</Text>
|
|
79
101
|
</View>
|
|
80
|
-
|
|
81
|
-
color={typoStyle.description.color}
|
|
82
|
-
typography={typoStyle.description.typography}>
|
|
83
|
-
{description}
|
|
84
|
-
</Text>
|
|
102
|
+
{buildDescription()}
|
|
85
103
|
</View>
|
|
86
|
-
</
|
|
104
|
+
</TouchableOpacity>
|
|
87
105
|
);
|
|
88
106
|
};
|
|
89
107
|
return (
|
|
90
108
|
<View style={{width: '100%'}}>
|
|
91
|
-
{steps.map((
|
|
92
|
-
return renderStepItem(
|
|
109
|
+
{steps.map((item, index: number) => {
|
|
110
|
+
return renderStepItem(item, index);
|
|
93
111
|
})}
|
|
94
112
|
</View>
|
|
95
113
|
);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {Colors, Icon, Text} from '@momo-kits/foundation';
|
|
2
|
+
import React, {FC} from 'react';
|
|
3
|
+
import {View} from 'react-native';
|
|
4
|
+
import styles from './styles';
|
|
5
|
+
import {StepIconProps} from './types';
|
|
6
|
+
|
|
7
|
+
const StepIcon: FC<StepIconProps> = ({
|
|
8
|
+
size = 'large',
|
|
9
|
+
backgroundColor,
|
|
10
|
+
borderColor,
|
|
11
|
+
error,
|
|
12
|
+
style,
|
|
13
|
+
useNumber,
|
|
14
|
+
index,
|
|
15
|
+
isActive,
|
|
16
|
+
customIcon,
|
|
17
|
+
}) => {
|
|
18
|
+
let iconStyle = styles.stepIcon;
|
|
19
|
+
let checkIconSize = 16;
|
|
20
|
+
let contentIconSize = 8;
|
|
21
|
+
|
|
22
|
+
if (size === 'small') {
|
|
23
|
+
iconStyle = styles.stepIconSmall;
|
|
24
|
+
checkIconSize = 12;
|
|
25
|
+
contentIconSize = 6;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let iconSource = error ? 'navigation_close' : 'notifications_check';
|
|
29
|
+
|
|
30
|
+
const renderIcon = () => {
|
|
31
|
+
// useNumber is true, render number
|
|
32
|
+
if (useNumber) {
|
|
33
|
+
return (
|
|
34
|
+
<Text
|
|
35
|
+
style={{position: 'absolute'}}
|
|
36
|
+
typography={'header_xs_semibold'}
|
|
37
|
+
color={Colors.black_01}>
|
|
38
|
+
{index + 1}
|
|
39
|
+
</Text>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (isActive) {
|
|
44
|
+
// customIcon is true, render customIcon
|
|
45
|
+
if (customIcon) {
|
|
46
|
+
return (
|
|
47
|
+
<Icon
|
|
48
|
+
size={checkIconSize}
|
|
49
|
+
color={Colors.black_01}
|
|
50
|
+
source={customIcon}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
// render default Icon
|
|
55
|
+
return (
|
|
56
|
+
<View
|
|
57
|
+
style={[styles.currIcon, {width: contentIconSize, aspectRatio: 1}]}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Icon size={checkIconSize} color={Colors.black_01} source={iconSource} />
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<View
|
|
69
|
+
style={[iconStyle, styles.center, {backgroundColor, borderColor}, style]}>
|
|
70
|
+
{renderIcon()}
|
|
71
|
+
</View>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default StepIcon;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {ApplicationContext, Colors, Spacing, Text} from '@momo-kits/foundation';
|
|
2
|
+
import React, {FC, useContext} from 'react';
|
|
3
|
+
import {FlexAlignType, TouchableOpacity, View} from 'react-native';
|
|
4
|
+
import StepIcon from './StepIcon';
|
|
5
|
+
import styles from './styles';
|
|
6
|
+
import {Step, StepsProps} from './types';
|
|
7
|
+
import { getStepColor, getStepTypo} from './utils';
|
|
8
|
+
|
|
9
|
+
type TextAlign = 'left' | 'right' | 'center';
|
|
10
|
+
|
|
11
|
+
const StepsHorizontal: FC<StepsProps> = ({
|
|
12
|
+
steps,
|
|
13
|
+
size,
|
|
14
|
+
activeIndex,
|
|
15
|
+
useNumber = false,
|
|
16
|
+
align = 'center',
|
|
17
|
+
customIcon,
|
|
18
|
+
onPress,
|
|
19
|
+
disabled,
|
|
20
|
+
}) => {
|
|
21
|
+
const renderStepItem = (item: Step, index: number) => {
|
|
22
|
+
const {title, description, error, time} = item;
|
|
23
|
+
let typoStyle = getStepTypo(activeIndex, index, error, size, 'horizontal');
|
|
24
|
+
const {theme} = useContext(ApplicationContext);
|
|
25
|
+
let alignItems: FlexAlignType = 'center';
|
|
26
|
+
let textAlign: TextAlign = 'center';
|
|
27
|
+
|
|
28
|
+
if (align === 'left') {
|
|
29
|
+
alignItems = 'flex-start';
|
|
30
|
+
textAlign = 'left';
|
|
31
|
+
} else if (align === 'right') {
|
|
32
|
+
alignItems = 'flex-end';
|
|
33
|
+
textAlign = 'right';
|
|
34
|
+
} else if (align === 'stretch') {
|
|
35
|
+
if (index === 0) {
|
|
36
|
+
alignItems = 'flex-start';
|
|
37
|
+
textAlign = 'left';
|
|
38
|
+
} else if (index === steps.length - 1) {
|
|
39
|
+
textAlign = 'right';
|
|
40
|
+
alignItems = 'flex-end';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const haveMarginRight =
|
|
45
|
+
index !== steps.length - 1 && align !== 'center' && align !== 'stretch';
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<TouchableOpacity
|
|
49
|
+
key={`Step ${index}`}
|
|
50
|
+
style={{
|
|
51
|
+
flex: 1,
|
|
52
|
+
alignItems,
|
|
53
|
+
marginRight: haveMarginRight ? Spacing.XS : 0,
|
|
54
|
+
}}
|
|
55
|
+
disabled={disabled || !onPress}
|
|
56
|
+
onPress={() => onPress && onPress(item, index)}>
|
|
57
|
+
{!!time && (
|
|
58
|
+
<Text
|
|
59
|
+
style={{textAlign}}
|
|
60
|
+
color={disabled ? theme.colors.text.disable : typoStyle.time.color}
|
|
61
|
+
typography={typoStyle.time.typography}>
|
|
62
|
+
{time}
|
|
63
|
+
</Text>
|
|
64
|
+
)}
|
|
65
|
+
{renderStepIcon(item, index, align, disabled)}
|
|
66
|
+
{!!title && (
|
|
67
|
+
<Text
|
|
68
|
+
style={[styles.title, {textAlign}]}
|
|
69
|
+
color={disabled ? theme.colors.text.disable : typoStyle.title.color}
|
|
70
|
+
typography={typoStyle.title.typography}>
|
|
71
|
+
{title}
|
|
72
|
+
</Text>
|
|
73
|
+
)}
|
|
74
|
+
{!!description && (
|
|
75
|
+
<Text
|
|
76
|
+
style={{textAlign}}
|
|
77
|
+
color={
|
|
78
|
+
disabled ? theme.colors.text.disable : typoStyle.description.color
|
|
79
|
+
}
|
|
80
|
+
typography={typoStyle.description.typography}>
|
|
81
|
+
{description}
|
|
82
|
+
</Text>
|
|
83
|
+
)}
|
|
84
|
+
</TouchableOpacity>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const renderStepIcon = (
|
|
89
|
+
item: Step,
|
|
90
|
+
index: number,
|
|
91
|
+
align: string = 'center',
|
|
92
|
+
disabled?: boolean
|
|
93
|
+
) => {
|
|
94
|
+
const {error} = item;
|
|
95
|
+
|
|
96
|
+
const stepStyle = getStepColor(activeIndex, index, error, steps.length, disabled);
|
|
97
|
+
const {backgroundColor, borderColor, lineColorRight, lineColorLeft} =
|
|
98
|
+
stepStyle;
|
|
99
|
+
|
|
100
|
+
const lineLeftHide =
|
|
101
|
+
(align === 'stretch' && index === 0) || align === 'left';
|
|
102
|
+
const lineRightHide =
|
|
103
|
+
(align === 'stretch' && index === steps.length - 1) || align === 'right';
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<View style={styles.rowStep}>
|
|
107
|
+
{!lineLeftHide && (
|
|
108
|
+
<View
|
|
109
|
+
style={[
|
|
110
|
+
styles.lineHorizontal,
|
|
111
|
+
styles.radiusRight,
|
|
112
|
+
{
|
|
113
|
+
backgroundColor: lineColorLeft,
|
|
114
|
+
},
|
|
115
|
+
]}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
<StepIcon
|
|
119
|
+
size={size}
|
|
120
|
+
error={error}
|
|
121
|
+
backgroundColor={disabled ? Colors.pink_08 : backgroundColor}
|
|
122
|
+
borderColor={disabled ? Colors.pink_10 : borderColor}
|
|
123
|
+
style={{
|
|
124
|
+
marginRight: !lineRightHide ? Spacing.XS : 0,
|
|
125
|
+
marginLeft: !lineLeftHide ? Spacing.XS : 0,
|
|
126
|
+
marginVertical: Spacing.XS,
|
|
127
|
+
}}
|
|
128
|
+
index={index}
|
|
129
|
+
useNumber={useNumber}
|
|
130
|
+
isActive={activeIndex === index}
|
|
131
|
+
customIcon={customIcon}
|
|
132
|
+
/>
|
|
133
|
+
{!lineRightHide && (
|
|
134
|
+
<View
|
|
135
|
+
style={[
|
|
136
|
+
styles.lineHorizontal,
|
|
137
|
+
styles.radiusLeft,
|
|
138
|
+
{
|
|
139
|
+
backgroundColor: lineColorRight,
|
|
140
|
+
},
|
|
141
|
+
]}
|
|
142
|
+
/>
|
|
143
|
+
)}
|
|
144
|
+
</View>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<View style={{flexDirection: 'row'}}>
|
|
150
|
+
{steps.map((item, index) => {
|
|
151
|
+
return renderStepItem(item, index);
|
|
152
|
+
})}
|
|
153
|
+
</View>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export default StepsHorizontal;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {ApplicationContext, Colors, Spacing, Text} from '@momo-kits/foundation';
|
|
2
|
+
import React, {FC, useContext} from 'react';
|
|
3
|
+
import {View, TouchableOpacity} from 'react-native';
|
|
4
|
+
import StepIcon from './StepIcon';
|
|
5
|
+
import styles from './styles';
|
|
6
|
+
import {Step, StepsProps} from './types';
|
|
7
|
+
import {getStepColor, getStepTypo} from './utils';
|
|
8
|
+
|
|
9
|
+
const StepsVertical: FC<StepsProps> = ({
|
|
10
|
+
steps,
|
|
11
|
+
activeIndex,
|
|
12
|
+
size,
|
|
13
|
+
useNumber = false,
|
|
14
|
+
onPress,
|
|
15
|
+
disabled,
|
|
16
|
+
}) => {
|
|
17
|
+
const {theme} = useContext(ApplicationContext);
|
|
18
|
+
|
|
19
|
+
const renderStepItem = (item: Step, index: number) => {
|
|
20
|
+
const {error, description, title, time} = item;
|
|
21
|
+
|
|
22
|
+
const stepStyle = getStepColor(activeIndex, index, error, steps.length);
|
|
23
|
+
const typoStyle = getStepTypo(activeIndex, index, error, size, 'vertical');
|
|
24
|
+
|
|
25
|
+
const {backgroundColor, borderColor} = stepStyle;
|
|
26
|
+
const lineColor =
|
|
27
|
+
activeIndex > index
|
|
28
|
+
? theme.colors.primary + '33'
|
|
29
|
+
: theme.colors.background.default;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* build description
|
|
33
|
+
*/
|
|
34
|
+
const buildDescription = () => {
|
|
35
|
+
if (typeof description === 'string') {
|
|
36
|
+
return (
|
|
37
|
+
<Text
|
|
38
|
+
color={disabled ? theme.colors.text.disable : typoStyle.title.color}
|
|
39
|
+
typography={typoStyle.description.typography}>
|
|
40
|
+
{description}
|
|
41
|
+
</Text>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return description;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<TouchableOpacity
|
|
49
|
+
key={`Step ${index}`}
|
|
50
|
+
style={{
|
|
51
|
+
flexDirection: 'row',
|
|
52
|
+
marginBottom: Spacing.XS,
|
|
53
|
+
}}
|
|
54
|
+
disabled={disabled || !onPress}
|
|
55
|
+
onPress={() => onPress && onPress(item, index)}>
|
|
56
|
+
<View
|
|
57
|
+
style={{
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
marginRight: Spacing.M,
|
|
60
|
+
}}>
|
|
61
|
+
<StepIcon
|
|
62
|
+
size={size}
|
|
63
|
+
error={error}
|
|
64
|
+
backgroundColor={disabled ? Colors.pink_08 : backgroundColor}
|
|
65
|
+
borderColor={disabled ? Colors.pink_10 : borderColor}
|
|
66
|
+
useNumber={useNumber}
|
|
67
|
+
index={index}
|
|
68
|
+
isActive={activeIndex === index}
|
|
69
|
+
/>
|
|
70
|
+
{index !== steps.length - 1 && (
|
|
71
|
+
<View
|
|
72
|
+
style={[
|
|
73
|
+
styles.lineVertical,
|
|
74
|
+
{backgroundColor: lineColor, marginVertical: Spacing.XS},
|
|
75
|
+
]}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
</View>
|
|
79
|
+
<View style={{flex: 1}}>
|
|
80
|
+
<View
|
|
81
|
+
style={{
|
|
82
|
+
flexDirection: 'row',
|
|
83
|
+
justifyContent: 'space-between',
|
|
84
|
+
}}>
|
|
85
|
+
<Text
|
|
86
|
+
numberOfLines={2}
|
|
87
|
+
style={{marginRight: Spacing.S, flex: 1}}
|
|
88
|
+
color={
|
|
89
|
+
disabled ? theme.colors.text.disable : typoStyle.title.color
|
|
90
|
+
}
|
|
91
|
+
typography={typoStyle.title.typography}>
|
|
92
|
+
{title}
|
|
93
|
+
</Text>
|
|
94
|
+
<Text
|
|
95
|
+
color={
|
|
96
|
+
disabled ? theme.colors.text.disable : typoStyle.time.color
|
|
97
|
+
}
|
|
98
|
+
typography={typoStyle.time.typography}>
|
|
99
|
+
{time}
|
|
100
|
+
</Text>
|
|
101
|
+
</View>
|
|
102
|
+
{buildDescription()}
|
|
103
|
+
</View>
|
|
104
|
+
</TouchableOpacity>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
return (
|
|
108
|
+
<View style={{width: '100%'}}>
|
|
109
|
+
{steps.map((item, index: number) => {
|
|
110
|
+
return renderStepItem(item, index);
|
|
111
|
+
})}
|
|
112
|
+
</View>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default StepsVertical;
|
package/dist/index.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, {FC} from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {Step, StepsProps, Align} from './types';
|
|
4
|
+
import StepsHorizontal from './StepsHorizontal';
|
|
5
|
+
import StepsVertical from './StepsVertical';
|
|
6
|
+
|
|
7
|
+
const Steps: FC<StepsProps> = ({horizontal = false, ...props}) => {
|
|
8
|
+
return (
|
|
9
|
+
<View>
|
|
10
|
+
{horizontal ? (
|
|
11
|
+
<StepsHorizontal {...props} />
|
|
12
|
+
) : (
|
|
13
|
+
<StepsVertical {...props} />
|
|
14
|
+
)}
|
|
15
|
+
</View>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export {Steps};
|
|
20
|
+
export type {StepsProps, Step, Align};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momo-kits/step",
|
|
3
|
+
"version": "0.109.1-beta.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@momo-kits/foundation": "latest",
|
|
9
|
+
"prop-types": "^15.7.2",
|
|
10
|
+
"react": "16.9.0",
|
|
11
|
+
"react-native": ">=0.55"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@momo-platform/versions": "4.1.11"
|
|
15
|
+
},
|
|
16
|
+
"license": "MoMo"
|
|
17
|
+
}
|
package/dist/publish.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Prepare dist files
|
|
4
|
+
rm -rf dist
|
|
5
|
+
mkdir dist
|
|
6
|
+
rsync -r --exclude=/dist ./* dist
|
|
7
|
+
cd dist
|
|
8
|
+
|
|
9
|
+
if [ "$1" == "stable" ]; then
|
|
10
|
+
npm version $(npm view @momo-kits/foundation@stable version)
|
|
11
|
+
npm version patch
|
|
12
|
+
npm publish --tag stable --access=public
|
|
13
|
+
elif [ "$1" == "latest" ]; then
|
|
14
|
+
npm version $(npm view @momo-kits/foundation@latest version)
|
|
15
|
+
npm publish --tag latest --access=public
|
|
16
|
+
else
|
|
17
|
+
npm version $(npm view @momo-kits/step@beta version)
|
|
18
|
+
npm version prerelease --preid=beta
|
|
19
|
+
npm publish --tag beta --access=public
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
PACKAGE_NAME=$(npm pkg get name)
|
|
23
|
+
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
24
|
+
|
|
25
|
+
# Clean up
|
|
26
|
+
cd ..
|
|
27
|
+
rm -rf dist
|
package/dist/styles.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {Radius, scaleSize, Spacing} from '@momo-kits/foundation';
|
|
2
|
+
import {StyleSheet} from 'react-native';
|
|
3
|
+
export default StyleSheet.create({
|
|
4
|
+
stepIcon: {
|
|
5
|
+
width: 24,
|
|
6
|
+
height: 24,
|
|
7
|
+
borderWidth: 2,
|
|
8
|
+
borderRadius: Radius.L,
|
|
9
|
+
},
|
|
10
|
+
stepIconSmall: {
|
|
11
|
+
width: scaleSize(16),
|
|
12
|
+
height: scaleSize(16),
|
|
13
|
+
borderWidth: 2,
|
|
14
|
+
borderRadius: scaleSize(Radius.M),
|
|
15
|
+
},
|
|
16
|
+
lineHorizontal: {
|
|
17
|
+
height: 2,
|
|
18
|
+
flex: 1,
|
|
19
|
+
},
|
|
20
|
+
lineVertical: {
|
|
21
|
+
width: 2,
|
|
22
|
+
minHeight: 20,
|
|
23
|
+
flex: 1,
|
|
24
|
+
},
|
|
25
|
+
radiusLeft: {
|
|
26
|
+
borderTopLeftRadius: Radius.S,
|
|
27
|
+
borderBottomLeftRadius: Radius.S,
|
|
28
|
+
},
|
|
29
|
+
radiusRight: {
|
|
30
|
+
borderTopRightRadius: Radius.S,
|
|
31
|
+
borderBottomRightRadius: Radius.S,
|
|
32
|
+
},
|
|
33
|
+
center: {
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
},
|
|
37
|
+
rowStep: {
|
|
38
|
+
flexDirection: 'row',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
},
|
|
41
|
+
title: {
|
|
42
|
+
marginBottom: Spacing.XS,
|
|
43
|
+
},
|
|
44
|
+
textCenter: {
|
|
45
|
+
textAlign: 'center',
|
|
46
|
+
},
|
|
47
|
+
largeText: {
|
|
48
|
+
fontSize: scaleSize(12),
|
|
49
|
+
lineHeight: scaleSize(16),
|
|
50
|
+
},
|
|
51
|
+
smallText: {
|
|
52
|
+
fontSize: scaleSize(8),
|
|
53
|
+
lineHeight: scaleSize(12),
|
|
54
|
+
},
|
|
55
|
+
currIcon: {
|
|
56
|
+
backgroundColor: 'white',
|
|
57
|
+
borderRadius: Radius.L,
|
|
58
|
+
aspectRatio: 1,
|
|
59
|
+
},
|
|
60
|
+
});
|
package/dist/types.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {ViewStyle} from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Properties for the Steps component, a guided progress through a sequence of procedural steps.
|
|
6
|
+
*/
|
|
7
|
+
export type StepsProps = {
|
|
8
|
+
/**
|
|
9
|
+
* Optional. If `true`, the steps are laid out in a horizontal manner.
|
|
10
|
+
* If `false`, the steps are laid out vertically.
|
|
11
|
+
* Defaults to `false` (vertical) if not provided.
|
|
12
|
+
*/
|
|
13
|
+
horizontal?: boolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An array of `Step` items representing each individual step in the sequence.
|
|
17
|
+
* Each `Step` has its own set of properties such as title, description, etc.
|
|
18
|
+
*/
|
|
19
|
+
steps: Step[];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Optional. Specifies the size of the steps. Affects all step items within the component.
|
|
23
|
+
* If not provided, a default size is used.
|
|
24
|
+
*/
|
|
25
|
+
size?: 'small' | 'large';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The index of the currently active step within the steps sequence,
|
|
29
|
+
* starting from 0 for the first step.
|
|
30
|
+
*/
|
|
31
|
+
activeIndex: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Optional. If `true`, the step numbers are displayed within the step icons.
|
|
35
|
+
*/
|
|
36
|
+
useNumber?: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Optional. Specifies the alignment of the steps within the component.
|
|
40
|
+
*/
|
|
41
|
+
align?: Align;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Optional. If `true`, the step descriptions are displayed below the step titles.
|
|
45
|
+
*/
|
|
46
|
+
customIcon?: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Optional. If `true`, the step descriptions are displayed below the step titles.
|
|
50
|
+
*/
|
|
51
|
+
onPress?: (item: Step, index: number) => void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Optional. If `true`, the user won't be able to interact with the Steps component.
|
|
55
|
+
*/
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type Align = 'left' | 'right' | 'center' | 'stretch';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Represents a single step within the Steps component. Each step has a
|
|
63
|
+
* title and can have optional properties such as a description or error state.
|
|
64
|
+
*/
|
|
65
|
+
export type Step = {
|
|
66
|
+
/**
|
|
67
|
+
* The title of the step, briefly describing the purpose or task of this stage.
|
|
68
|
+
*/
|
|
69
|
+
title: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Optional. More detailed text about this particular step.
|
|
73
|
+
* It can provide users with guidance on what to expect or what's required.
|
|
74
|
+
*/
|
|
75
|
+
description?: string | React.ReactNode;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Optional. If `true`, the step is marked as having an error, typically displayed
|
|
79
|
+
* with an error icon and error styles. Defaults to `false` if not provided.
|
|
80
|
+
*/
|
|
81
|
+
error?: boolean;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Optional. A string representing the time associated with this step.
|
|
85
|
+
* It could be the duration, a specific time, or date, depending on the context.
|
|
86
|
+
*/
|
|
87
|
+
time?: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Properties for the StepIcon component, which displays an icon
|
|
92
|
+
* representing a step within the Steps component.
|
|
93
|
+
*/
|
|
94
|
+
export type StepIconProps = {
|
|
95
|
+
/**
|
|
96
|
+
* Optional. Specifies the size of the step icon. If not provided, a default size is used.
|
|
97
|
+
*/
|
|
98
|
+
size?: 'small' | 'large';
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Optional. The background color of the step icon.
|
|
102
|
+
* If not provided, a default background color is used.
|
|
103
|
+
*/
|
|
104
|
+
backgroundColor?: string;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Optional. The border color of the step icon.
|
|
108
|
+
* If not provided, a default border color is used.
|
|
109
|
+
*/
|
|
110
|
+
borderColor?: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Optional. If `true`, the step icon is marked as being in an error state,
|
|
114
|
+
* typically displayed with an error icon and error styles.
|
|
115
|
+
* Defaults to `false` if not provided.
|
|
116
|
+
*/
|
|
117
|
+
error?: boolean;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Optional. Custom styles to apply to the StepIcon component.
|
|
121
|
+
* Can be used to adjust the visual presentation or layout.
|
|
122
|
+
*/
|
|
123
|
+
style?: ViewStyle;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Optional. If `true`, the step number is displayed within the step icon.
|
|
127
|
+
*/
|
|
128
|
+
useNumber?: boolean;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Optional. The number to display within the step icon.
|
|
132
|
+
*/
|
|
133
|
+
index: number;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Optional. If `true`, the step icon is marked as active.
|
|
137
|
+
*/
|
|
138
|
+
isActive?: boolean;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Optional. Custom active icon
|
|
142
|
+
*/
|
|
143
|
+
customIcon?: string;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Properties for the ProgressInfo component, which displays a progress bar
|
|
148
|
+
*/
|
|
149
|
+
export type ProgressInfoProps = {
|
|
150
|
+
steps: Step[];
|
|
151
|
+
horizontal?: boolean;
|
|
152
|
+
size?: 'small' | 'large';
|
|
153
|
+
useNumber?: boolean;
|
|
154
|
+
align?: 'left' | 'right' | 'center' | 'stretch' | undefined;
|
|
155
|
+
showDescription?: boolean;
|
|
156
|
+
customIcon?: string;
|
|
157
|
+
};
|
package/dist/utils.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {ApplicationContext, Colors, Typography} from '@momo-kits/foundation';
|
|
2
|
+
import {Step} from '@momo-kits/step';
|
|
3
|
+
import {useContext} from 'react';
|
|
4
|
+
|
|
5
|
+
type StepStatus = 'incomplete' | 'current' | 'completed' | 'error' | 'disable';
|
|
6
|
+
type StepTypo = {
|
|
7
|
+
typography: Typography;
|
|
8
|
+
color: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const getStatus = (
|
|
12
|
+
activeIndex: number,
|
|
13
|
+
currentIndex: number,
|
|
14
|
+
error?: boolean,
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
): StepStatus => {
|
|
17
|
+
if (disabled) return 'disable';
|
|
18
|
+
if (error) return 'error';
|
|
19
|
+
if (activeIndex === currentIndex) return 'current';
|
|
20
|
+
if (activeIndex > currentIndex) return 'completed';
|
|
21
|
+
return 'incomplete';
|
|
22
|
+
};
|
|
23
|
+
const checkSizeAndStepType = (
|
|
24
|
+
stepType?: 'vertical' | 'horizontal',
|
|
25
|
+
size?: 'small' | 'large'
|
|
26
|
+
) => {
|
|
27
|
+
return (
|
|
28
|
+
stepType === 'horizontal' || (stepType === 'vertical' && size === 'small')
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getTypoTitle = (
|
|
33
|
+
status: StepStatus,
|
|
34
|
+
size?: 'small' | 'large',
|
|
35
|
+
stepType?: 'vertical' | 'horizontal'
|
|
36
|
+
): Typography => {
|
|
37
|
+
const defaultTypo =
|
|
38
|
+
!!size && stepType === 'vertical'
|
|
39
|
+
? 'body_default_regular'
|
|
40
|
+
: 'description_default_regular';
|
|
41
|
+
|
|
42
|
+
switch (status) {
|
|
43
|
+
case 'current':
|
|
44
|
+
case 'error': {
|
|
45
|
+
return checkSizeAndStepType(stepType, size)
|
|
46
|
+
? 'header_xs_semibold'
|
|
47
|
+
: 'header_s_semibold';
|
|
48
|
+
}
|
|
49
|
+
case 'incomplete':
|
|
50
|
+
case 'completed': {
|
|
51
|
+
return checkSizeAndStepType(stepType, size)
|
|
52
|
+
? 'description_default_regular'
|
|
53
|
+
: 'body_default_regular';
|
|
54
|
+
}
|
|
55
|
+
default: {
|
|
56
|
+
return defaultTypo;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const getStepTypo = (
|
|
62
|
+
activeIndex: number,
|
|
63
|
+
currentIndex: number,
|
|
64
|
+
error?: boolean,
|
|
65
|
+
size?: 'small' | 'large',
|
|
66
|
+
stepType?: 'vertical' | 'horizontal'
|
|
67
|
+
) => {
|
|
68
|
+
const {theme} = useContext(ApplicationContext);
|
|
69
|
+
const status = getStatus(activeIndex, currentIndex, error);
|
|
70
|
+
|
|
71
|
+
let title: StepTypo = {
|
|
72
|
+
color: theme.colors.text.default,
|
|
73
|
+
typography: getTypoTitle(status, size, stepType),
|
|
74
|
+
};
|
|
75
|
+
let description: StepTypo = {
|
|
76
|
+
color: theme.colors.text.hint,
|
|
77
|
+
typography: !!size
|
|
78
|
+
? 'description_xs_regular'
|
|
79
|
+
: 'description_default_regular',
|
|
80
|
+
};
|
|
81
|
+
let time: StepTypo = {
|
|
82
|
+
color: theme.colors.text.hint,
|
|
83
|
+
typography: 'description_xs_regular',
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
switch (status) {
|
|
87
|
+
case 'current': {
|
|
88
|
+
title.color = theme.colors.primary;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'error': {
|
|
92
|
+
title.color = theme.colors.error.primary;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {title, description, time};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const getStepColor = (
|
|
101
|
+
activeIndex: number,
|
|
102
|
+
currentIndex: number,
|
|
103
|
+
error?: boolean,
|
|
104
|
+
length: number = 1,
|
|
105
|
+
disabled?: boolean
|
|
106
|
+
) => {
|
|
107
|
+
const {theme} = useContext(ApplicationContext);
|
|
108
|
+
const DEFAULT_LINE_COLOR = theme.colors.background.default;
|
|
109
|
+
const COMPLETED_LINE_COLOR = theme.colors.primary + '33';
|
|
110
|
+
|
|
111
|
+
let backgroundColor = Colors.black_06;
|
|
112
|
+
let borderColor = theme.colors.border.default;
|
|
113
|
+
let lineColorLeft = DEFAULT_LINE_COLOR;
|
|
114
|
+
let lineColorRight = DEFAULT_LINE_COLOR;
|
|
115
|
+
const status = getStatus(activeIndex, currentIndex, error, disabled);
|
|
116
|
+
|
|
117
|
+
if (activeIndex > currentIndex) {
|
|
118
|
+
lineColorLeft = COMPLETED_LINE_COLOR;
|
|
119
|
+
lineColorRight = COMPLETED_LINE_COLOR;
|
|
120
|
+
}
|
|
121
|
+
if (activeIndex === currentIndex) {
|
|
122
|
+
lineColorLeft = COMPLETED_LINE_COLOR;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (currentIndex === 0) {
|
|
126
|
+
lineColorLeft = 'transparent';
|
|
127
|
+
}
|
|
128
|
+
if (currentIndex === length - 1) {
|
|
129
|
+
lineColorRight = 'transparent';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
switch (status) {
|
|
133
|
+
case 'current': {
|
|
134
|
+
backgroundColor = theme.colors.primary;
|
|
135
|
+
borderColor = theme.colors.background.tonal;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
case 'completed': {
|
|
140
|
+
backgroundColor = theme.colors.primary;
|
|
141
|
+
borderColor = theme.colors.background.tonal;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
case 'error': {
|
|
146
|
+
backgroundColor = theme.colors.error.primary;
|
|
147
|
+
borderColor = theme.colors.error.container;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
case 'disable': {
|
|
152
|
+
backgroundColor = Colors.pink_08;
|
|
153
|
+
borderColor = Colors.pink_10;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {backgroundColor, borderColor, lineColorLeft, lineColorRight, status};
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const getOnPressCompleted = (
|
|
162
|
+
item: Step,
|
|
163
|
+
activeIndex: number,
|
|
164
|
+
currentIndex: number,
|
|
165
|
+
error?: boolean,
|
|
166
|
+
disabled?: boolean,
|
|
167
|
+
onPress?: (item: Step, index: number) => void
|
|
168
|
+
) => {
|
|
169
|
+
const status = getStatus(activeIndex, currentIndex, error, disabled);
|
|
170
|
+
|
|
171
|
+
if (status === 'completed' && onPress) {
|
|
172
|
+
return () => onPress(item, currentIndex);
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
};
|
package/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, {FC} from 'react';
|
|
2
2
|
import {View} from 'react-native';
|
|
3
|
-
import {Step, StepsProps} from './types';
|
|
3
|
+
import {Step, StepsProps, Align} from './types';
|
|
4
4
|
import StepsHorizontal from './StepsHorizontal';
|
|
5
5
|
import StepsVertical from './StepsVertical';
|
|
6
6
|
|
|
@@ -17,4 +17,4 @@ const Steps: FC<StepsProps> = ({horizontal = false, ...props}) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export {Steps};
|
|
20
|
-
export type {StepsProps, Step};
|
|
20
|
+
export type {StepsProps, Step, Align};
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
"name": "@momo-kits/step",
|
|
3
|
+
"version": "0.109.1-beta.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@momo-kits/foundation": "latest",
|
|
9
|
+
"prop-types": "^15.7.2",
|
|
10
|
+
"react": "16.9.0",
|
|
11
|
+
"react-native": ">=0.55"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@momo-platform/versions": "4.1.11"
|
|
15
|
+
},
|
|
16
|
+
"license": "MoMo"
|
|
17
17
|
}
|
package/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {ViewStyle} from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Properties for the Steps component, a guided progress through a sequence of procedural steps.
|
|
@@ -29,17 +30,34 @@ export type StepsProps = {
|
|
|
29
30
|
*/
|
|
30
31
|
activeIndex: number;
|
|
31
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Optional. If `true`, the step numbers are displayed within the step icons.
|
|
35
|
+
*/
|
|
32
36
|
useNumber?: boolean;
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Optional. Specifies the alignment of the steps within the component.
|
|
40
|
+
*/
|
|
41
|
+
align?: Align;
|
|
35
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Optional. If `true`, the step descriptions are displayed below the step titles.
|
|
45
|
+
*/
|
|
36
46
|
customIcon?: string;
|
|
37
47
|
|
|
38
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Optional. If `true`, the step descriptions are displayed below the step titles.
|
|
50
|
+
*/
|
|
51
|
+
onPress?: (item: Step, index: number) => void;
|
|
39
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Optional. If `true`, the user won't be able to interact with the Steps component.
|
|
55
|
+
*/
|
|
40
56
|
disabled?: boolean;
|
|
41
57
|
};
|
|
42
58
|
|
|
59
|
+
export type Align = 'left' | 'right' | 'center' | 'stretch';
|
|
60
|
+
|
|
43
61
|
/**
|
|
44
62
|
* Represents a single step within the Steps component. Each step has a
|
|
45
63
|
* title and can have optional properties such as a description or error state.
|
|
@@ -54,7 +72,7 @@ export type Step = {
|
|
|
54
72
|
* Optional. More detailed text about this particular step.
|
|
55
73
|
* It can provide users with guidance on what to expect or what's required.
|
|
56
74
|
*/
|
|
57
|
-
description?: string;
|
|
75
|
+
description?: string | React.ReactNode;
|
|
58
76
|
|
|
59
77
|
/**
|
|
60
78
|
* Optional. If `true`, the step is marked as having an error, typically displayed
|
|
@@ -104,10 +122,19 @@ export type StepIconProps = {
|
|
|
104
122
|
*/
|
|
105
123
|
style?: ViewStyle;
|
|
106
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Optional. If `true`, the step number is displayed within the step icon.
|
|
127
|
+
*/
|
|
107
128
|
useNumber?: boolean;
|
|
108
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Optional. The number to display within the step icon.
|
|
132
|
+
*/
|
|
109
133
|
index: number;
|
|
110
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Optional. If `true`, the step icon is marked as active.
|
|
137
|
+
*/
|
|
111
138
|
isActive?: boolean;
|
|
112
139
|
|
|
113
140
|
/**
|
|
@@ -116,6 +143,9 @@ export type StepIconProps = {
|
|
|
116
143
|
customIcon?: string;
|
|
117
144
|
};
|
|
118
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Properties for the ProgressInfo component, which displays a progress bar
|
|
148
|
+
*/
|
|
119
149
|
export type ProgressInfoProps = {
|
|
120
150
|
steps: Step[];
|
|
121
151
|
horizontal?: boolean;
|
package/utils.ts
CHANGED
|
@@ -1,67 +1,99 @@
|
|
|
1
1
|
import {ApplicationContext, Colors, Typography} from '@momo-kits/foundation';
|
|
2
|
+
import {Step} from '@momo-kits/step';
|
|
2
3
|
import {useContext} from 'react';
|
|
3
4
|
|
|
4
|
-
type StepStatus = 'incomplete' | 'current' | 'completed' | 'error';
|
|
5
|
+
type StepStatus = 'incomplete' | 'current' | 'completed' | 'error' | 'disable';
|
|
5
6
|
type StepTypo = {
|
|
6
7
|
typography: Typography;
|
|
7
8
|
color: string;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
const getStatus = (
|
|
11
12
|
activeIndex: number,
|
|
12
13
|
currentIndex: number,
|
|
13
14
|
error?: boolean,
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
): StepStatus => {
|
|
17
|
+
if (disabled) return 'disable';
|
|
18
|
+
if (error) return 'error';
|
|
19
|
+
if (activeIndex === currentIndex) return 'current';
|
|
20
|
+
if (activeIndex > currentIndex) return 'completed';
|
|
21
|
+
return 'incomplete';
|
|
22
|
+
};
|
|
23
|
+
const checkSizeAndStepType = (
|
|
24
|
+
stepType?: 'vertical' | 'horizontal',
|
|
14
25
|
size?: 'small' | 'large'
|
|
26
|
+
) => {
|
|
27
|
+
return (
|
|
28
|
+
stepType === 'horizontal' || (stepType === 'vertical' && size === 'small')
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getTypoTitle = (
|
|
33
|
+
status: StepStatus,
|
|
34
|
+
size?: 'small' | 'large',
|
|
35
|
+
stepType?: 'vertical' | 'horizontal'
|
|
36
|
+
): Typography => {
|
|
37
|
+
const defaultTypo =
|
|
38
|
+
!!size && stepType === 'vertical'
|
|
39
|
+
? 'body_default_regular'
|
|
40
|
+
: 'description_default_regular';
|
|
41
|
+
|
|
42
|
+
switch (status) {
|
|
43
|
+
case 'current':
|
|
44
|
+
case 'error': {
|
|
45
|
+
return checkSizeAndStepType(stepType, size)
|
|
46
|
+
? 'header_xs_semibold'
|
|
47
|
+
: 'header_s_semibold';
|
|
48
|
+
}
|
|
49
|
+
case 'incomplete':
|
|
50
|
+
case 'completed': {
|
|
51
|
+
return checkSizeAndStepType(stepType, size)
|
|
52
|
+
? 'description_default_regular'
|
|
53
|
+
: 'body_default_regular';
|
|
54
|
+
}
|
|
55
|
+
default: {
|
|
56
|
+
return defaultTypo;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const getStepTypo = (
|
|
62
|
+
activeIndex: number,
|
|
63
|
+
currentIndex: number,
|
|
64
|
+
error?: boolean,
|
|
65
|
+
size?: 'small' | 'large',
|
|
66
|
+
stepType?: 'vertical' | 'horizontal'
|
|
15
67
|
) => {
|
|
16
68
|
const {theme} = useContext(ApplicationContext);
|
|
69
|
+
const status = getStatus(activeIndex, currentIndex, error);
|
|
17
70
|
|
|
18
71
|
let title: StepTypo = {
|
|
19
72
|
color: theme.colors.text.default,
|
|
20
|
-
typography:
|
|
73
|
+
typography: getTypoTitle(status, size, stepType),
|
|
21
74
|
};
|
|
22
75
|
let description: StepTypo = {
|
|
23
76
|
color: theme.colors.text.hint,
|
|
24
|
-
typography:
|
|
77
|
+
typography: !!size
|
|
78
|
+
? 'description_xs_regular'
|
|
79
|
+
: 'description_default_regular',
|
|
25
80
|
};
|
|
26
81
|
let time: StepTypo = {
|
|
27
82
|
color: theme.colors.text.hint,
|
|
28
83
|
typography: 'description_xs_regular',
|
|
29
84
|
};
|
|
30
85
|
|
|
31
|
-
let status: StepStatus = 'incomplete';
|
|
32
|
-
if (activeIndex > currentIndex) {
|
|
33
|
-
status = 'completed';
|
|
34
|
-
}
|
|
35
|
-
if (activeIndex === currentIndex) {
|
|
36
|
-
status = 'current';
|
|
37
|
-
}
|
|
38
|
-
if (error) {
|
|
39
|
-
status = 'error';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
86
|
switch (status) {
|
|
43
87
|
case 'current': {
|
|
44
88
|
title.color = theme.colors.primary;
|
|
45
|
-
title.typography = 'header_xs_semibold';
|
|
46
89
|
break;
|
|
47
90
|
}
|
|
48
|
-
|
|
49
|
-
case 'completed': {
|
|
50
|
-
title.typography = 'header_xs_semibold';
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
91
|
case 'error': {
|
|
55
|
-
title.typography = 'header_xs_semibold';
|
|
56
92
|
title.color = theme.colors.error.primary;
|
|
57
93
|
break;
|
|
58
94
|
}
|
|
59
95
|
}
|
|
60
96
|
|
|
61
|
-
if (size === 'small') {
|
|
62
|
-
description.typography = 'description_xs_regular';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
97
|
return {title, description, time};
|
|
66
98
|
};
|
|
67
99
|
|
|
@@ -69,7 +101,8 @@ export const getStepColor = (
|
|
|
69
101
|
activeIndex: number,
|
|
70
102
|
currentIndex: number,
|
|
71
103
|
error?: boolean,
|
|
72
|
-
length: number = 1
|
|
104
|
+
length: number = 1,
|
|
105
|
+
disabled?: boolean
|
|
73
106
|
) => {
|
|
74
107
|
const {theme} = useContext(ApplicationContext);
|
|
75
108
|
const DEFAULT_LINE_COLOR = theme.colors.background.default;
|
|
@@ -79,20 +112,15 @@ export const getStepColor = (
|
|
|
79
112
|
let borderColor = theme.colors.border.default;
|
|
80
113
|
let lineColorLeft = DEFAULT_LINE_COLOR;
|
|
81
114
|
let lineColorRight = DEFAULT_LINE_COLOR;
|
|
82
|
-
|
|
115
|
+
const status = getStatus(activeIndex, currentIndex, error, disabled);
|
|
83
116
|
|
|
84
117
|
if (activeIndex > currentIndex) {
|
|
85
|
-
status = 'completed';
|
|
86
118
|
lineColorLeft = COMPLETED_LINE_COLOR;
|
|
87
119
|
lineColorRight = COMPLETED_LINE_COLOR;
|
|
88
120
|
}
|
|
89
121
|
if (activeIndex === currentIndex) {
|
|
90
|
-
status = 'current';
|
|
91
122
|
lineColorLeft = COMPLETED_LINE_COLOR;
|
|
92
123
|
}
|
|
93
|
-
if (error) {
|
|
94
|
-
status = 'error';
|
|
95
|
-
}
|
|
96
124
|
|
|
97
125
|
if (currentIndex === 0) {
|
|
98
126
|
lineColorLeft = 'transparent';
|
|
@@ -119,7 +147,29 @@ export const getStepColor = (
|
|
|
119
147
|
borderColor = theme.colors.error.container;
|
|
120
148
|
break;
|
|
121
149
|
}
|
|
150
|
+
|
|
151
|
+
case 'disable': {
|
|
152
|
+
backgroundColor = Colors.pink_08;
|
|
153
|
+
borderColor = Colors.pink_10;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
122
156
|
}
|
|
123
157
|
|
|
124
158
|
return {backgroundColor, borderColor, lineColorLeft, lineColorRight, status};
|
|
125
159
|
};
|
|
160
|
+
|
|
161
|
+
export const getOnPressCompleted = (
|
|
162
|
+
item: Step,
|
|
163
|
+
activeIndex: number,
|
|
164
|
+
currentIndex: number,
|
|
165
|
+
error?: boolean,
|
|
166
|
+
disabled?: boolean,
|
|
167
|
+
onPress?: (item: Step, index: number) => void
|
|
168
|
+
) => {
|
|
169
|
+
const status = getStatus(activeIndex, currentIndex, error, disabled);
|
|
170
|
+
|
|
171
|
+
if (status === 'completed' && onPress) {
|
|
172
|
+
return () => onPress(item, currentIndex);
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
};
|