@momo-kits/step 0.169.4 → 0.169.6
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/StepIcon.tsx +24 -14
- package/StepsHorizontal.tsx +40 -27
- package/StepsVertical.tsx +1 -3
- package/index.tsx +7 -6
- package/package.json +1 -1
- package/types.ts +6 -6
- package/utils.ts +30 -13
package/StepIcon.tsx
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
Colors,
|
|
3
|
+
Icon,
|
|
4
|
+
Text,
|
|
5
|
+
useScaleSize,
|
|
6
|
+
Radius,
|
|
7
|
+
} from '@momo-kits/foundation';
|
|
8
|
+
import React, { FC } from 'react';
|
|
9
|
+
import { StyleProp, View, ViewStyle } from 'react-native';
|
|
4
10
|
import styles from './styles';
|
|
5
|
-
import {StepIconProps} from './types';
|
|
11
|
+
import { StepIconProps } from './types';
|
|
6
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Step marker: the step number, else a custom icon or dot while active,
|
|
15
|
+
* else a check (close on error).
|
|
16
|
+
*/
|
|
7
17
|
const StepIcon: FC<StepIconProps> = ({
|
|
8
18
|
size = 'large',
|
|
9
19
|
backgroundColor,
|
|
@@ -39,20 +49,19 @@ const StepIcon: FC<StepIconProps> = ({
|
|
|
39
49
|
let iconSource = error ? 'navigation_close' : 'notifications_check';
|
|
40
50
|
|
|
41
51
|
const renderIcon = () => {
|
|
42
|
-
// useNumber is true, render number
|
|
43
52
|
if (useNumber) {
|
|
44
53
|
return (
|
|
45
54
|
<Text
|
|
46
55
|
style={styles.numberLabel}
|
|
47
56
|
typography={'header_xs_semibold'}
|
|
48
|
-
color={Colors.black_01}
|
|
57
|
+
color={Colors.black_01}
|
|
58
|
+
>
|
|
49
59
|
{index + 1}
|
|
50
60
|
</Text>
|
|
51
61
|
);
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
if (isActive) {
|
|
55
|
-
// customIcon is true, render customIcon
|
|
56
65
|
if (customIcon) {
|
|
57
66
|
return (
|
|
58
67
|
<Icon
|
|
@@ -62,12 +71,7 @@ const StepIcon: FC<StepIconProps> = ({
|
|
|
62
71
|
/>
|
|
63
72
|
);
|
|
64
73
|
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<View
|
|
68
|
-
style={[styles.currIcon, {width: contentIconSize}]}
|
|
69
|
-
/>
|
|
70
|
-
);
|
|
74
|
+
return <View style={[styles.currIcon, { width: contentIconSize }]} />;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
return (
|
|
@@ -77,7 +81,13 @@ const StepIcon: FC<StepIconProps> = ({
|
|
|
77
81
|
|
|
78
82
|
return (
|
|
79
83
|
<View
|
|
80
|
-
style={[
|
|
84
|
+
style={[
|
|
85
|
+
iconStyle,
|
|
86
|
+
styles.center,
|
|
87
|
+
{ backgroundColor, borderColor },
|
|
88
|
+
style,
|
|
89
|
+
]}
|
|
90
|
+
>
|
|
81
91
|
{renderIcon()}
|
|
82
92
|
</View>
|
|
83
93
|
);
|
package/StepsHorizontal.tsx
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ApplicationContext,
|
|
3
|
+
Colors,
|
|
4
|
+
Spacing,
|
|
5
|
+
Text,
|
|
6
|
+
} from '@momo-kits/foundation';
|
|
7
|
+
import React, { FC, useContext, useState } from 'react';
|
|
3
8
|
import {
|
|
4
9
|
FlexAlignType,
|
|
5
10
|
LayoutChangeEvent,
|
|
@@ -8,11 +13,15 @@ import {
|
|
|
8
13
|
} from 'react-native';
|
|
9
14
|
import StepIcon from './StepIcon';
|
|
10
15
|
import styles from './styles';
|
|
11
|
-
import {Step, StepsProps} from './types';
|
|
12
|
-
import {GetStepColor, GetStepTypo} from './utils';
|
|
16
|
+
import { Step, StepsProps } from './types';
|
|
17
|
+
import { GetStepColor, GetStepTypo } from './utils';
|
|
13
18
|
|
|
14
19
|
type TextAlign = 'left' | 'right' | 'center';
|
|
15
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Steps in a row: time, marker with connector lines, title and description.
|
|
23
|
+
* Time rows share the tallest measured height so markers stay aligned.
|
|
24
|
+
*/
|
|
16
25
|
const StepsHorizontal: FC<StepsProps> = ({
|
|
17
26
|
steps,
|
|
18
27
|
size,
|
|
@@ -28,7 +37,7 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
28
37
|
const { theme } = useContext(ApplicationContext);
|
|
29
38
|
|
|
30
39
|
const renderStepItem = (item: Step, index: number) => {
|
|
31
|
-
const {title, description, error, time} = item;
|
|
40
|
+
const { title, description, error, time } = item;
|
|
32
41
|
let typoStyle = GetStepTypo(activeIndex, index, error, size, 'horizontal');
|
|
33
42
|
let alignItems: FlexAlignType = 'center';
|
|
34
43
|
let textAlign: TextAlign = 'center';
|
|
@@ -50,13 +59,13 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
const onTimesLayout = (e: LayoutChangeEvent) => {
|
|
53
|
-
const {height} = e.nativeEvent.layout;
|
|
62
|
+
const { height } = e.nativeEvent.layout;
|
|
54
63
|
if (height !== timeHeight && height > timeHeight) setTimeHeight(height);
|
|
55
64
|
};
|
|
56
65
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const marginRight =
|
|
66
|
+
const isLastStep = index === steps.length - 1;
|
|
67
|
+
const isEdgeAlign = align !== 'center' && align !== 'stretch';
|
|
68
|
+
const marginRight = !isLastStep && isEdgeAlign ? Spacing.XS : 0;
|
|
60
69
|
|
|
61
70
|
return (
|
|
62
71
|
<TouchableOpacity
|
|
@@ -70,23 +79,26 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
70
79
|
]}
|
|
71
80
|
disabled={disabled || !onPress}
|
|
72
81
|
onPress={() => onPress && onPress(item, index)}
|
|
73
|
-
accessibilityLabel={`${accessibilityLabel}-touch-${index}`}
|
|
82
|
+
accessibilityLabel={`${accessibilityLabel}-touch-${index}`}
|
|
83
|
+
>
|
|
74
84
|
<View
|
|
75
85
|
style={[
|
|
76
86
|
styles.timeContainer,
|
|
77
87
|
{
|
|
78
88
|
minHeight: timeHeight,
|
|
79
89
|
},
|
|
80
|
-
]}
|
|
90
|
+
]}
|
|
91
|
+
>
|
|
81
92
|
{!!time && (
|
|
82
93
|
<Text
|
|
83
94
|
onLayout={onTimesLayout}
|
|
84
|
-
style={{textAlign}}
|
|
95
|
+
style={{ textAlign }}
|
|
85
96
|
color={
|
|
86
97
|
disabled ? theme.colors.text.disable : typoStyle.time.color
|
|
87
98
|
}
|
|
88
99
|
typography={typoStyle.time.typography}
|
|
89
|
-
accessibilityLabel={`${accessibilityLabel}-time-${index}`}
|
|
100
|
+
accessibilityLabel={`${accessibilityLabel}-time-${index}`}
|
|
101
|
+
>
|
|
90
102
|
{time}
|
|
91
103
|
</Text>
|
|
92
104
|
)}
|
|
@@ -94,21 +106,23 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
94
106
|
{renderStepIcon(item, index, align, disabled)}
|
|
95
107
|
{!!title && (
|
|
96
108
|
<Text
|
|
97
|
-
style={[styles.title, {textAlign}]}
|
|
109
|
+
style={[styles.title, { textAlign }]}
|
|
98
110
|
color={disabled ? theme.colors.text.disable : typoStyle.title.color}
|
|
99
111
|
typography={typoStyle.title.typography}
|
|
100
|
-
accessibilityLabel={`${accessibilityLabel}-title-${index}`}
|
|
112
|
+
accessibilityLabel={`${accessibilityLabel}-title-${index}`}
|
|
113
|
+
>
|
|
101
114
|
{title}
|
|
102
115
|
</Text>
|
|
103
116
|
)}
|
|
104
117
|
{!!description && (
|
|
105
118
|
<Text
|
|
106
|
-
style={{textAlign}}
|
|
119
|
+
style={{ textAlign }}
|
|
107
120
|
color={
|
|
108
121
|
disabled ? theme.colors.text.disable : typoStyle.description.color
|
|
109
122
|
}
|
|
110
123
|
typography={typoStyle.description.typography}
|
|
111
|
-
accessibilityLabel={`${accessibilityLabel}-description-${index}`}
|
|
124
|
+
accessibilityLabel={`${accessibilityLabel}-description-${index}`}
|
|
125
|
+
>
|
|
112
126
|
{description}
|
|
113
127
|
</Text>
|
|
114
128
|
)}
|
|
@@ -120,25 +134,24 @@ const StepsHorizontal: FC<StepsProps> = ({
|
|
|
120
134
|
item: Step,
|
|
121
135
|
index: number,
|
|
122
136
|
stepAlign: string = 'center',
|
|
123
|
-
stepDisabled?: boolean
|
|
137
|
+
stepDisabled?: boolean,
|
|
124
138
|
) => {
|
|
125
|
-
const {error} = item;
|
|
139
|
+
const { error } = item;
|
|
126
140
|
|
|
127
141
|
const stepStyle = GetStepColor(
|
|
128
142
|
activeIndex,
|
|
129
143
|
index,
|
|
130
144
|
error,
|
|
131
145
|
steps.length,
|
|
132
|
-
stepDisabled
|
|
146
|
+
stepDisabled,
|
|
133
147
|
);
|
|
134
|
-
const {backgroundColor, borderColor
|
|
135
|
-
|
|
148
|
+
const { backgroundColor, borderColor } = stepStyle;
|
|
149
|
+
const { lineColorRight, lineColorLeft } = stepStyle;
|
|
136
150
|
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
stepAlign === 'right';
|
|
151
|
+
const isStretch = stepAlign === 'stretch';
|
|
152
|
+
const isLastStep = index === steps.length - 1;
|
|
153
|
+
const lineLeftHide = (isStretch && index === 0) || stepAlign === 'left';
|
|
154
|
+
const lineRightHide = (isStretch && isLastStep) || stepAlign === 'right';
|
|
142
155
|
const iconMarginRight = !lineRightHide ? Spacing.XS : 0;
|
|
143
156
|
const iconMarginLeft = !lineLeftHide ? Spacing.XS : 0;
|
|
144
157
|
|
package/StepsVertical.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import styles from './styles';
|
|
|
11
11
|
import { Step, StepsProps } from './types';
|
|
12
12
|
import { GetStepColor, GetStepTypo } from './utils';
|
|
13
13
|
|
|
14
|
+
/** Steps in a column: marker and connector, then title, time, description. */
|
|
14
15
|
const StepsVertical: FC<StepsProps> = ({
|
|
15
16
|
steps,
|
|
16
17
|
activeIndex,
|
|
@@ -32,9 +33,6 @@ const StepsVertical: FC<StepsProps> = ({
|
|
|
32
33
|
const { primary, border } = theme.colors;
|
|
33
34
|
const lineColor = activeIndex > index ? primary + '33' : border.default;
|
|
34
35
|
|
|
35
|
-
/**
|
|
36
|
-
* build description
|
|
37
|
-
*/
|
|
38
36
|
const buildDescription = () => {
|
|
39
37
|
if (typeof description === 'string') {
|
|
40
38
|
return (
|
package/index.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React, {FC} from 'react';
|
|
2
|
-
import {View} from 'react-native';
|
|
3
|
-
import {Step, StepsProps, Align} from './types';
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { Step, StepsProps, Align } from './types';
|
|
4
4
|
import StepsHorizontal from './StepsHorizontal';
|
|
5
5
|
import StepsVertical from './StepsVertical';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/** Step progress list; renders the horizontal or vertical layout. */
|
|
8
|
+
const Steps: FC<StepsProps> = ({ horizontal = false, ...props }) => {
|
|
8
9
|
return (
|
|
9
10
|
<View>
|
|
10
11
|
{horizontal ? (
|
|
@@ -16,5 +17,5 @@ const Steps: FC<StepsProps> = ({horizontal = false, ...props}) => {
|
|
|
16
17
|
);
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
export {Steps};
|
|
20
|
-
export type {StepsProps, Step, Align};
|
|
20
|
+
export { Steps };
|
|
21
|
+
export type { StepsProps, Step, Align };
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ViewStyle} from 'react-native';
|
|
1
|
+
import { ViewStyle } from 'react-native';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -41,12 +41,12 @@ export type StepsProps = {
|
|
|
41
41
|
align?: Align;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Optional.
|
|
44
|
+
* Optional. Icon source shown in the active step marker instead of the default dot.
|
|
45
45
|
*/
|
|
46
46
|
customIcon?: string;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Optional.
|
|
49
|
+
* Optional. Called with the step and its index when a step is pressed.
|
|
50
50
|
*/
|
|
51
51
|
onPress?: (item: Step, index: number) => void;
|
|
52
52
|
|
|
@@ -130,7 +130,7 @@ export type StepIconProps = {
|
|
|
130
130
|
useNumber?: boolean;
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Zero-based step index; `index + 1` is shown when `useNumber` is set.
|
|
134
134
|
*/
|
|
135
135
|
index: number;
|
|
136
136
|
|
|
@@ -140,13 +140,13 @@ export type StepIconProps = {
|
|
|
140
140
|
isActive?: boolean;
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
|
-
* Optional.
|
|
143
|
+
* Optional. Icon source shown when the step is active.
|
|
144
144
|
*/
|
|
145
145
|
customIcon?: string;
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
* Properties for the ProgressInfo component, which displays a progress bar
|
|
149
|
+
* Properties for the ProgressInfo component, which displays a progress bar.
|
|
150
150
|
*/
|
|
151
151
|
export type ProgressInfoProps = {
|
|
152
152
|
steps: Step[];
|
package/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {ApplicationContext, Colors, Typography} from '@momo-kits/foundation';
|
|
2
|
-
import {Step} from '@momo-kits/step';
|
|
3
|
-
import {useContext} from 'react';
|
|
1
|
+
import { ApplicationContext, Colors, Typography } from '@momo-kits/foundation';
|
|
2
|
+
import { Step } from '@momo-kits/step';
|
|
3
|
+
import { useContext } from 'react';
|
|
4
4
|
|
|
5
5
|
type StepStatus = 'incomplete' | 'current' | 'completed' | 'error' | 'disable';
|
|
6
6
|
type StepTypo = {
|
|
@@ -8,11 +8,12 @@ type StepTypo = {
|
|
|
8
8
|
color: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
/** Step status; `disabled` wins over `error`, which wins over position. */
|
|
11
12
|
const getStatus = (
|
|
12
13
|
activeIndex: number,
|
|
13
14
|
currentIndex: number,
|
|
14
15
|
error?: boolean,
|
|
15
|
-
disabled?: boolean
|
|
16
|
+
disabled?: boolean,
|
|
16
17
|
): StepStatus => {
|
|
17
18
|
if (disabled) return 'disable';
|
|
18
19
|
if (error) return 'error';
|
|
@@ -20,9 +21,10 @@ const getStatus = (
|
|
|
20
21
|
if (activeIndex > currentIndex) return 'completed';
|
|
21
22
|
return 'incomplete';
|
|
22
23
|
};
|
|
24
|
+
/** Whether the step uses the compact title typography. */
|
|
23
25
|
const checkSizeAndStepType = (
|
|
24
26
|
stepType?: 'vertical' | 'horizontal',
|
|
25
|
-
size?: 'small' | 'large'
|
|
27
|
+
size?: 'small' | 'large',
|
|
26
28
|
) => {
|
|
27
29
|
return (
|
|
28
30
|
stepType === 'horizontal' || (stepType === 'vertical' && size === 'small')
|
|
@@ -32,7 +34,7 @@ const checkSizeAndStepType = (
|
|
|
32
34
|
const getTypoTitle = (
|
|
33
35
|
status: StepStatus,
|
|
34
36
|
size?: 'small' | 'large',
|
|
35
|
-
stepType?: 'vertical' | 'horizontal'
|
|
37
|
+
stepType?: 'vertical' | 'horizontal',
|
|
36
38
|
): Typography => {
|
|
37
39
|
let defaultTypo: Typography = 'description_default_regular';
|
|
38
40
|
if (size && stepType === 'vertical') {
|
|
@@ -55,14 +57,18 @@ const getTypoTitle = (
|
|
|
55
57
|
}
|
|
56
58
|
};
|
|
57
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Typography and colors for a step's title, description and time.
|
|
62
|
+
* Reads the theme with `useContext`, so call it only while rendering.
|
|
63
|
+
*/
|
|
58
64
|
export const GetStepTypo = (
|
|
59
65
|
activeIndex: number,
|
|
60
66
|
currentIndex: number,
|
|
61
67
|
error?: boolean,
|
|
62
68
|
size?: 'small' | 'large',
|
|
63
|
-
stepType?: 'vertical' | 'horizontal'
|
|
69
|
+
stepType?: 'vertical' | 'horizontal',
|
|
64
70
|
) => {
|
|
65
|
-
const {theme} = useContext(ApplicationContext);
|
|
71
|
+
const { theme } = useContext(ApplicationContext);
|
|
66
72
|
const status = getStatus(activeIndex, currentIndex, error);
|
|
67
73
|
|
|
68
74
|
let title: StepTypo = {
|
|
@@ -89,17 +95,21 @@ export const GetStepTypo = (
|
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
return {title, description, time};
|
|
98
|
+
return { title, description, time };
|
|
93
99
|
};
|
|
94
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Marker and connector-line colors of a step, plus its status.
|
|
103
|
+
* Reads the theme with `useContext`, so call it only while rendering.
|
|
104
|
+
*/
|
|
95
105
|
export const GetStepColor = (
|
|
96
106
|
activeIndex: number,
|
|
97
107
|
currentIndex: number,
|
|
98
108
|
error?: boolean,
|
|
99
109
|
length: number = 1,
|
|
100
|
-
disabled?: boolean
|
|
110
|
+
disabled?: boolean,
|
|
101
111
|
) => {
|
|
102
|
-
const {theme} = useContext(ApplicationContext);
|
|
112
|
+
const { theme } = useContext(ApplicationContext);
|
|
103
113
|
const DEFAULT_LINE_COLOR = theme.colors.border.default;
|
|
104
114
|
const COMPLETED_LINE_COLOR = theme.colors.primary + '33';
|
|
105
115
|
|
|
@@ -150,16 +160,23 @@ export const GetStepColor = (
|
|
|
150
160
|
}
|
|
151
161
|
}
|
|
152
162
|
|
|
153
|
-
return {
|
|
163
|
+
return {
|
|
164
|
+
backgroundColor,
|
|
165
|
+
borderColor,
|
|
166
|
+
lineColorLeft,
|
|
167
|
+
lineColorRight,
|
|
168
|
+
status,
|
|
169
|
+
};
|
|
154
170
|
};
|
|
155
171
|
|
|
172
|
+
/** Press handler for a completed step, or `undefined` for any other status. */
|
|
156
173
|
export const getOnPressCompleted = (
|
|
157
174
|
item: Step,
|
|
158
175
|
activeIndex: number,
|
|
159
176
|
currentIndex: number,
|
|
160
177
|
error?: boolean,
|
|
161
178
|
disabled?: boolean,
|
|
162
|
-
onPress?: (item: Step, index: number) => void
|
|
179
|
+
onPress?: (item: Step, index: number) => void,
|
|
163
180
|
) => {
|
|
164
181
|
const status = getStatus(activeIndex, currentIndex, error, disabled);
|
|
165
182
|
|