@momo-kits/step 0.103.2-rc.4 → 0.103.2-rc.41

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.
@@ -18,9 +18,9 @@ const StepsHorizontal: FC<StepsProps> = ({
18
18
  onPress,
19
19
  disabled,
20
20
  }) => {
21
- const renderStepItem = (i: Step, ii: number) => {
22
- const {title, description, error, time} = steps[ii];
23
- let typoStyle = getStepTypo(activeIndex, ii, error, size);
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 (ii === 0) {
35
+ if (index === 0) {
36
36
  alignItems = 'flex-start';
37
37
  textAlign = 'left';
38
- } else if (ii === steps.length - 1) {
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
- ii !== steps.length - 1 && align !== 'center' && align !== 'stretch';
45
+ index !== steps.length - 1 && align !== 'center' && align !== 'stretch';
46
46
 
47
47
  return (
48
48
  <TouchableOpacity
49
- key={`Step ${ii}`}
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(i, ii, align)}
65
+ {renderStepIcon(item, index, align, false)}
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
- i: Step,
90
- ii: number,
89
+ item: Step,
90
+ index: number,
91
91
  align: string = 'center',
92
92
  disabled: boolean
93
93
  ) => {
94
- const {error} = steps[ii];
94
+ const {error} = item;
95
95
 
96
- const stepStyle = getStepColor(activeIndex, ii, error, steps.length);
96
+ const stepStyle = getStepColor(activeIndex, index, error, steps.length);
97
97
  const {backgroundColor, borderColor, lineColorRight, lineColorLeft} =
98
98
  stepStyle;
99
99
 
100
- const lineLeftHide = (align === 'stretch' && ii === 0) || align === 'left';
100
+ const lineLeftHide =
101
+ (align === 'stretch' && index === 0) || align === 'left';
101
102
  const lineRightHide =
102
- (align === 'stretch' && ii === steps.length - 1) || align === 'right';
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={ii}
128
+ index={index}
128
129
  useNumber={useNumber}
129
- isActive={activeIndex === ii}
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((i, ii) => {
150
- return renderStepItem(i, ii);
150
+ {steps.map((item, index) => {
151
+ return renderStepItem(item, index);
151
152
  })}
152
153
  </View>
153
154
  );
package/StepsVertical.tsx CHANGED
@@ -14,20 +14,37 @@ const StepsVertical: FC<StepsProps> = ({
14
14
  }) => {
15
15
  const {theme} = useContext(ApplicationContext);
16
16
 
17
- const renderStepItem = (i: Step, ii: number) => {
18
- const {error, description, title, time} = steps[ii];
17
+ const renderStepItem = (item: Step, index: number) => {
18
+ const {error, description, title, time} = item;
19
19
 
20
- const stepStyle = getStepColor(activeIndex, ii, error, steps.length);
21
- let typoStyle = getStepTypo(activeIndex, ii, error, size);
20
+ const stepStyle = getStepColor(activeIndex, index, error, steps.length);
21
+ const typoStyle = getStepTypo(activeIndex, index, error, size, 'vertical');
22
22
 
23
23
  const {backgroundColor, borderColor} = stepStyle;
24
24
  const lineColor =
25
- activeIndex > ii
25
+ activeIndex > index
26
26
  ? theme.colors.primary + '33'
27
27
  : theme.colors.background.default;
28
+
29
+ /**
30
+ * build description
31
+ */
32
+ const buildDescription = () => {
33
+ if (typeof description == 'string') {
34
+ return (
35
+ <Text
36
+ color={typoStyle.description.color}
37
+ typography={typoStyle.description.typography}>
38
+ {description}
39
+ </Text>
40
+ );
41
+ }
42
+ return description;
43
+ };
44
+
28
45
  return (
29
46
  <View
30
- key={`Step ${ii}`}
47
+ key={`Step ${index}`}
31
48
  style={{
32
49
  flexDirection: 'row',
33
50
  marginBottom: Spacing.XS,
@@ -44,10 +61,10 @@ const StepsVertical: FC<StepsProps> = ({
44
61
  backgroundColor={backgroundColor}
45
62
  borderColor={borderColor}
46
63
  useNumber={useNumber}
47
- index={ii}
48
- isActive={activeIndex === ii}
64
+ index={index}
65
+ isActive={activeIndex === index}
49
66
  />
50
- {ii !== steps.length - 1 && (
67
+ {index !== steps.length - 1 && (
51
68
  <View
52
69
  style={[
53
70
  styles.lineVertical,
@@ -77,19 +94,15 @@ const StepsVertical: FC<StepsProps> = ({
77
94
  {time}
78
95
  </Text>
79
96
  </View>
80
- <Text
81
- color={typoStyle.description.color}
82
- typography={typoStyle.description.typography}>
83
- {description}
84
- </Text>
97
+ {buildDescription()}
85
98
  </View>
86
99
  </View>
87
100
  );
88
101
  };
89
102
  return (
90
103
  <View style={{width: '100%'}}>
91
- {steps.map((i, ii) => {
92
- return renderStepItem(i, ii);
104
+ {steps.map((item, index: number) => {
105
+ return renderStepItem(item, index);
93
106
  })}
94
107
  </View>
95
108
  );
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/step",
3
- "version": "0.103.2-rc.4",
3
+ "version": "0.103.2-rc.41",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "dependencies": {},
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
- align?: 'left' | 'right' | 'center' | 'stretch';
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
- onPress?: () => void;
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
@@ -11,7 +11,8 @@ export const getStepTypo = (
11
11
  activeIndex: number,
12
12
  currentIndex: number,
13
13
  error?: boolean,
14
- size?: 'small' | 'large'
14
+ size?: 'small' | 'large',
15
+ stepType?: 'vertical' | 'horizontal'
15
16
  ) => {
16
17
  const {theme} = useContext(ApplicationContext);
17
18
 
@@ -47,7 +48,12 @@ export const getStepTypo = (
47
48
  }
48
49
 
49
50
  case 'completed': {
50
- title.typography = 'header_xs_semibold';
51
+ if (
52
+ stepType === 'horizontal' ||
53
+ (stepType === 'vertical' && size === 'small')
54
+ ) {
55
+ title.typography = 'description_default_regular';
56
+ } else title.typography = 'body_default_regular';
51
57
  break;
52
58
  }
53
59