@momo-kits/progress-info 0.103.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,128 @@
1
+ import React, {FC} from 'react';
2
+ import {FlexAlignType, View} from 'react-native';
3
+ import {ProgressInfoItem, ProgressInfoProps} from './types';
4
+ import {Colors, Spacing, Text} from '@momo-kits/foundation';
5
+ import styles from './styles';
6
+ import ProgressInfoIcon from './ProgressInfoIcon';
7
+
8
+ type TextAlign = 'left' | 'right' | 'center';
9
+
10
+ const ProgressInfoHorizontal: FC<ProgressInfoProps> = ({
11
+ steps,
12
+ size,
13
+ useNumber = false,
14
+ showDescription = true,
15
+ showTitle = true,
16
+ align,
17
+ customIcon,
18
+ }) => {
19
+ const renderProgressItem = (i: ProgressInfoItem, ii: number) => {
20
+ const {title, description} = steps[ii];
21
+
22
+ let alignItems: FlexAlignType = 'center';
23
+ let textAlign: TextAlign = 'center';
24
+
25
+ if (align === 'left') {
26
+ alignItems = 'flex-start';
27
+ textAlign = 'left';
28
+ } else if (align === 'right') {
29
+ alignItems = 'flex-end';
30
+ textAlign = 'right';
31
+ } else if (align === 'stretch') {
32
+ if (ii === 0) {
33
+ alignItems = 'flex-start';
34
+ textAlign = 'left';
35
+ } else if (ii === steps.length - 1) {
36
+ textAlign = 'right';
37
+ alignItems = 'flex-end';
38
+ }
39
+ }
40
+
41
+ const haveMarginRight =
42
+ ii !== steps.length - 1 && align !== 'center' && align !== 'stretch';
43
+
44
+ return (
45
+ <View
46
+ key={`Step ${ii}`}
47
+ style={{
48
+ flex: 1,
49
+ alignItems,
50
+ marginRight: haveMarginRight ? Spacing.XS : 0,
51
+ }}>
52
+ {renderStepIcon(i, ii, align)}
53
+ {!!title && showTitle && (
54
+ <Text
55
+ style={[styles.title, {textAlign}]}
56
+ typography={'header_xs_semibold'}>
57
+ {title}
58
+ </Text>
59
+ )}
60
+ {!!description && showDescription && (
61
+ <Text
62
+ style={{textAlign}}
63
+ color={Colors.black_12}
64
+ typography={'description_default_regular'}>
65
+ {description}
66
+ </Text>
67
+ )}
68
+ </View>
69
+ );
70
+ };
71
+ const renderStepIcon = (
72
+ i: ProgressInfoItem,
73
+ ii: number,
74
+ align: string = 'center'
75
+ ) => {
76
+ const lineLeftHide = (align === 'stretch' && ii === 0) || align === 'left';
77
+ const lineRightHide =
78
+ (align === 'stretch' && ii === steps.length - 1) || align === 'right';
79
+
80
+ return (
81
+ <View style={styles.rowStep}>
82
+ {!lineLeftHide && (
83
+ <View
84
+ style={[
85
+ styles.lineHorizontal,
86
+ styles.radiusRight,
87
+ {
88
+ backgroundColor: Colors.pink_08,
89
+ },
90
+ ]}
91
+ />
92
+ )}
93
+ <ProgressInfoIcon
94
+ size={size}
95
+ index={ii}
96
+ backgroundColor={Colors.pink_08}
97
+ borderColor={Colors.pink_08}
98
+ style={{
99
+ marginVertical: Spacing.XS,
100
+ }}
101
+ useNumber={useNumber}
102
+ customIcon={customIcon}
103
+ />
104
+ {!lineRightHide && (
105
+ <View
106
+ style={[
107
+ styles.lineHorizontal,
108
+ styles.radiusLeft,
109
+ {
110
+ backgroundColor: Colors.pink_08,
111
+ },
112
+ ]}
113
+ />
114
+ )}
115
+ </View>
116
+ );
117
+ };
118
+
119
+ return (
120
+ <View style={{flexDirection: 'row'}}>
121
+ {steps.map((i, ii) => {
122
+ return renderProgressItem(i, ii);
123
+ })}
124
+ </View>
125
+ );
126
+ };
127
+
128
+ export default ProgressInfoHorizontal;
@@ -0,0 +1,65 @@
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 {ProgressInfoItemIcon} from './types';
6
+
7
+ const ProgressInfoIcon: FC<ProgressInfoItemIcon> = ({
8
+ size = 'large',
9
+ backgroundColor,
10
+ borderColor,
11
+ style,
12
+ useNumber,
13
+ customIcon,
14
+ index,
15
+ }) => {
16
+ let iconStyle = styles.stepIcon;
17
+ let checkIconSize = 16;
18
+ let contentIconSize = 8;
19
+
20
+ if (size === 'small') {
21
+ iconStyle = styles.stepIconSmall;
22
+ checkIconSize = 12;
23
+ contentIconSize = 6;
24
+ }
25
+
26
+ const renderIcon = () => {
27
+ // useNumber is true, render number
28
+ if (useNumber) {
29
+ return (
30
+ <Text
31
+ style={{position: 'absolute'}}
32
+ typography={'header_xs_semibold'}
33
+ color={Colors.pink_MoMo_Branding}>
34
+ {index + 1}
35
+ </Text>
36
+ );
37
+ }
38
+
39
+ // customIcon is true, render customIcon
40
+ if (customIcon) {
41
+ return (
42
+ <Icon
43
+ size={checkIconSize}
44
+ color={Colors.pink_MoMo_Branding}
45
+ source={customIcon}
46
+ />
47
+ );
48
+ }
49
+ // render default Icon
50
+ return (
51
+ <View
52
+ style={[styles.currIcon, {width: contentIconSize, aspectRatio: 1}]}
53
+ />
54
+ );
55
+ };
56
+
57
+ return (
58
+ <View
59
+ style={[iconStyle, styles.center, {backgroundColor, borderColor}, style]}>
60
+ {renderIcon()}
61
+ </View>
62
+ );
63
+ };
64
+
65
+ export default ProgressInfoIcon;
@@ -0,0 +1,85 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {View} from 'react-native';
3
+ import {ProgressInfoItem, ProgressInfoProps} from './types';
4
+ import {ApplicationContext, Colors, Spacing, Text} from '@momo-kits/foundation';
5
+ import ProgressInfoIcon from './ProgressInfoIcon';
6
+ import styles from './styles';
7
+
8
+ const ProgressInfoVertical: FC<ProgressInfoProps> = ({
9
+ steps,
10
+ size,
11
+ useNumber = false,
12
+ showDescription = true,
13
+ showTitle = true,
14
+ customIcon,
15
+ }) => {
16
+ const {theme} = useContext(ApplicationContext);
17
+
18
+ const renderStepItem = (i: ProgressInfoItem, ii: number) => {
19
+ const {description, title} = steps[ii];
20
+
21
+ const lineColor = theme.colors.primary + '33';
22
+
23
+ return (
24
+ <View
25
+ key={`Step ${ii}`}
26
+ style={{
27
+ flexDirection: 'row',
28
+ }}>
29
+ <View
30
+ style={{
31
+ alignItems: 'center',
32
+ marginRight: Spacing.M,
33
+ minHeight: 48,
34
+ }}>
35
+ <ProgressInfoIcon
36
+ size={size}
37
+ backgroundColor={Colors.pink_08}
38
+ borderColor={Colors.pink_08}
39
+ useNumber={useNumber}
40
+ customIcon={customIcon}
41
+ index={ii}
42
+ />
43
+ {ii !== steps.length - 1 && (
44
+ <View style={[styles.lineVertical, {backgroundColor: lineColor}]} />
45
+ )}
46
+ </View>
47
+ <View style={{flex: 1}}>
48
+ <View
49
+ style={[
50
+ {
51
+ flexDirection: 'row',
52
+ justifyContent: 'space-between',
53
+ },
54
+ ]}>
55
+ {showTitle && (
56
+ <Text
57
+ numberOfLines={2}
58
+ style={{marginRight: Spacing.S, flex: 1}}
59
+ typography={'header_xs_semibold'}>
60
+ {title}
61
+ </Text>
62
+ )}
63
+ </View>
64
+ {showDescription && (
65
+ <Text
66
+ color={Colors.black_12}
67
+ typography={'description_default_regular'}>
68
+ {description}
69
+ </Text>
70
+ )}
71
+ </View>
72
+ </View>
73
+ );
74
+ };
75
+
76
+ return (
77
+ <View style={{width: '100%'}}>
78
+ {steps.map((i, ii) => {
79
+ return renderStepItem(i, ii);
80
+ })}
81
+ </View>
82
+ );
83
+ };
84
+
85
+ export default ProgressInfoVertical;
package/index.tsx ADDED
@@ -0,0 +1,22 @@
1
+ import React, {FC} from 'react';
2
+ import {ProgressInfoItem, ProgressInfoProps} from './types';
3
+ import ProgressInfoHorizontal from './ProgressInfoHorizontal';
4
+ import ProgressInfoVertical from './ProgressInfoVertical';
5
+
6
+ const ProgressInfo: FC<ProgressInfoProps> = ({
7
+ horizontal = false,
8
+ ...props
9
+ }) => {
10
+ return (
11
+ <>
12
+ {horizontal ? (
13
+ <ProgressInfoHorizontal {...props} />
14
+ ) : (
15
+ <ProgressInfoVertical {...props} />
16
+ )}
17
+ </>
18
+ );
19
+ };
20
+
21
+ export {ProgressInfo};
22
+ export type {ProgressInfoProps, ProgressInfoItem};
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@momo-kits/progress-info",
3
+ "version": "0.103.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/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/progress-info@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/styles.ts ADDED
@@ -0,0 +1,60 @@
1
+ import {Colors, 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: Colors.pink_MoMo_Branding,
57
+ borderRadius: Radius.L,
58
+ aspectRatio: 1,
59
+ },
60
+ });
package/types.ts ADDED
@@ -0,0 +1,60 @@
1
+ import {ViewStyle} from 'react-native';
2
+
3
+ export type ProgressInfoItem = {
4
+ /**
5
+ * The title of the step, briefly describing the purpose or task of this stage.
6
+ */
7
+ title: string;
8
+
9
+ /**
10
+ * Optional. More detailed text about this particular step.
11
+ * It can provide users with guidance on what to expect or what's required.
12
+ */
13
+ description?: string;
14
+ };
15
+
16
+ /**
17
+ * Properties for the StepIcon component, which displays an icon
18
+ * representing a step within the Steps component.
19
+ */
20
+ export type ProgressInfoItemIcon = {
21
+ /**
22
+ * Optional. Specifies the size of the step icon. If not provided, a default size is used.
23
+ */
24
+ size?: 'small' | 'large';
25
+
26
+ /**
27
+ * Optional. The background color of the step icon.
28
+ * If not provided, a default background color is used.
29
+ */
30
+ backgroundColor?: string;
31
+
32
+ /**
33
+ * Optional. The border color of the step icon.
34
+ * If not provided, a default border color is used.
35
+ */
36
+ borderColor?: string;
37
+
38
+ /**
39
+ * Optional. Custom styles to apply to the StepIcon component.
40
+ * Can be used to adjust the visual presentation or layout.
41
+ */
42
+ style?: ViewStyle;
43
+
44
+ index: number;
45
+
46
+ useNumber?: boolean;
47
+
48
+ customIcon?: string;
49
+ };
50
+
51
+ export type ProgressInfoProps = {
52
+ steps: ProgressInfoItem[];
53
+ horizontal?: boolean;
54
+ size?: 'small' | 'large';
55
+ useNumber?: boolean;
56
+ align?: 'left' | 'right' | 'center' | 'stretch' | undefined;
57
+ showDescription?: boolean;
58
+ showTitle?: boolean;
59
+ customIcon?: string;
60
+ };