@momo-kits/step 0.76.1-beta.2 → 0.77.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/StepIcon.tsx ADDED
@@ -0,0 +1,31 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {View} from 'react-native';
3
+ import {StepIconProps} from './types';
4
+ import styles from './styles';
5
+ import {ApplicationContext, Icon, Colors} from '@momo-kits/foundation';
6
+
7
+ const StepIcon: FC<StepIconProps> = ({
8
+ size = 'large',
9
+ backgroundColor,
10
+ borderColor,
11
+ error,
12
+ style,
13
+ }) => {
14
+ const {theme} = useContext(ApplicationContext);
15
+ let iconStyle = styles.stepIcon;
16
+ let checkIconSize = 16;
17
+ let iconSource = error ? 'navigation_close' : 'notifications_check';
18
+
19
+ if (size === 'small') {
20
+ iconStyle = styles.stepIconSmall;
21
+ checkIconSize = 12;
22
+ }
23
+ return (
24
+ <View
25
+ style={[iconStyle, styles.center, {backgroundColor, borderColor}, style]}>
26
+ <Icon size={checkIconSize} color={Colors.black_01} source={iconSource} />
27
+ </View>
28
+ );
29
+ };
30
+
31
+ export default StepIcon;
@@ -0,0 +1,94 @@
1
+ import React, {FC} from 'react';
2
+ import {View} from 'react-native';
3
+ import {Step, StepsProps} from './types';
4
+ import StepIcon from './StepIcon';
5
+ import {Spacing, Text} from '@momo-kits/foundation';
6
+ import {getStepColor, getStepTypo} from './utils';
7
+ import styles from './styles';
8
+
9
+ const StepsHorizontal: FC<StepsProps> = ({steps, size, activeIndex}) => {
10
+ const renderStepItem = (i: Step, ii: number) => {
11
+ const {title, description, error, time} = steps[ii];
12
+ let typoStyle = getStepTypo(activeIndex, ii, error, size);
13
+
14
+ return (
15
+ <View style={{flex: 1, alignItems: 'center'}}>
16
+ {!!time && (
17
+ <Text
18
+ style={styles.textCenter}
19
+ color={typoStyle.time.color}
20
+ typography={typoStyle.time.typography}>
21
+ {time}
22
+ </Text>
23
+ )}
24
+ {renderStepIcon(i, ii)}
25
+ {!!title && (
26
+ <Text
27
+ style={[styles.title, styles.textCenter]}
28
+ color={typoStyle.title.color}
29
+ typography={typoStyle.title.typography}>
30
+ {title}
31
+ </Text>
32
+ )}
33
+ {!!description && (
34
+ <Text
35
+ style={styles.textCenter}
36
+ color={typoStyle.description.color}
37
+ typography={typoStyle.description.typography}>
38
+ {description}
39
+ </Text>
40
+ )}
41
+ </View>
42
+ );
43
+ };
44
+
45
+ const renderStepIcon = (i: Step, ii: number) => {
46
+ const {error} = steps[ii];
47
+
48
+ const stepStyle = getStepColor(activeIndex, ii, error, steps.length);
49
+ const {backgroundColor, borderColor, lineColorRight, lineColorLeft} =
50
+ stepStyle;
51
+
52
+ return (
53
+ <View style={styles.rowStep}>
54
+ {
55
+ <View
56
+ style={[
57
+ styles.lineHorizontal,
58
+ styles.radiusRight,
59
+ {
60
+ backgroundColor: lineColorLeft,
61
+ },
62
+ ]}
63
+ />
64
+ }
65
+ <StepIcon
66
+ size={size}
67
+ error={error}
68
+ backgroundColor={backgroundColor}
69
+ borderColor={borderColor}
70
+ style={{marginHorizontal: Spacing.XS, marginVertical: Spacing.XS}}
71
+ />
72
+ <View
73
+ style={[
74
+ styles.lineHorizontal,
75
+ styles.radiusLeft,
76
+ {
77
+ backgroundColor: lineColorRight,
78
+ },
79
+ ]}
80
+ />
81
+ </View>
82
+ );
83
+ };
84
+
85
+ return (
86
+ <View style={{flexDirection: 'row'}}>
87
+ {steps.map((i, ii) => {
88
+ return renderStepItem(i, ii);
89
+ })}
90
+ </View>
91
+ );
92
+ };
93
+
94
+ export default StepsHorizontal;
@@ -0,0 +1,88 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {View} from 'react-native';
3
+ import {Step, StepsProps} from './types';
4
+ import {getStepColor, getStepTypo} from './utils';
5
+ import {ApplicationContext, Spacing, Text} from '@momo-kits/foundation';
6
+ import styles from './styles';
7
+ import StepIcon from './StepIcon';
8
+
9
+ const StepsVertical: FC<StepsProps> = ({steps, activeIndex, size}) => {
10
+ const {theme} = useContext(ApplicationContext);
11
+ const renderStepItem = (i: Step, ii: number) => {
12
+ const {error, description, title, time} = steps[ii];
13
+
14
+ const stepStyle = getStepColor(activeIndex, ii, error, steps.length);
15
+ let typoStyle = getStepTypo(activeIndex, ii, error, size);
16
+
17
+ const {backgroundColor, borderColor} = stepStyle;
18
+ const lineColor =
19
+ activeIndex >= ii
20
+ ? theme.colors.secondary
21
+ : theme.colors.background.default;
22
+ return (
23
+ <View
24
+ style={{
25
+ flexDirection: 'row',
26
+ marginBottom: Spacing.XS,
27
+ }}>
28
+ <View
29
+ style={{
30
+ alignItems: 'center',
31
+ marginRight: Spacing.M,
32
+ minHeight: 48,
33
+ }}>
34
+ <StepIcon
35
+ size={size}
36
+ error={error}
37
+ backgroundColor={backgroundColor}
38
+ borderColor={borderColor}
39
+ />
40
+ {ii !== steps.length - 1 && (
41
+ <View
42
+ style={[
43
+ styles.lineVertical,
44
+ {backgroundColor: lineColor, marginVertical: Spacing.XS},
45
+ ]}
46
+ />
47
+ )}
48
+ </View>
49
+ <View style={{flex: 1}}>
50
+ <View
51
+ style={[
52
+ {
53
+ flexDirection: 'row',
54
+ justifyContent: 'space-between',
55
+ },
56
+ ]}>
57
+ <Text
58
+ numberOfLines={2}
59
+ style={{marginRight: Spacing.S, flex: 1}}
60
+ color={typoStyle.title.color}
61
+ typography={typoStyle.title.typography}>
62
+ {title}
63
+ </Text>
64
+ <Text
65
+ color={typoStyle.time.color}
66
+ typography={typoStyle.time.typography}>
67
+ {time}
68
+ </Text>
69
+ </View>
70
+ <Text
71
+ color={typoStyle.description.color}
72
+ typography={typoStyle.description.typography}>
73
+ {description}
74
+ </Text>
75
+ </View>
76
+ </View>
77
+ );
78
+ };
79
+ return (
80
+ <View style={{width: '100%'}}>
81
+ {steps.map((i, ii) => {
82
+ return renderStepItem(i, ii);
83
+ })}
84
+ </View>
85
+ );
86
+ };
87
+
88
+ export default StepsVertical;
package/index.tsx ADDED
@@ -0,0 +1,19 @@
1
+ import React, {FC} from 'react';
2
+ import {View} from 'react-native';
3
+ import {StepsProps} 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 default Steps;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@momo-kits/step",
3
- "version": "0.76.1-beta.2",
3
+ "version": "0.77.2",
4
4
  "private": false,
5
- "main": "index.js",
5
+ "main": "index.tsx",
6
6
  "dependencies": {},
7
7
  "peerDependencies": {
8
- "react-native": ">=0.55",
8
+ "@momo-kits/foundation": "latest",
9
9
  "prop-types": "^15.7.2",
10
10
  "react": "16.9.0",
11
- "@momo-kits/core-v2": ">=0.0.5-beta"
11
+ "react-native": ">=0.55"
12
12
  },
13
13
  "devDependencies": {},
14
14
  "license": "MoMo"
package/publish.sh CHANGED
@@ -26,4 +26,4 @@ cd ..
26
26
  rm -rf dist
27
27
 
28
28
 
29
- #curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/step new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/step"}'
29
+ ##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/stepper new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/stepper"}'
package/styles.ts ADDED
@@ -0,0 +1,48 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {Radius, Spacing} from '@momo-kits/foundation';
3
+
4
+ export default StyleSheet.create({
5
+ stepIcon: {
6
+ width: 24,
7
+ height: 24,
8
+ borderWidth: 2,
9
+ borderRadius: Radius.M,
10
+ },
11
+ stepIconSmall: {
12
+ width: 16,
13
+ height: 16,
14
+ borderWidth: 2,
15
+ borderRadius: Radius.S,
16
+ },
17
+ lineHorizontal: {
18
+ height: 2,
19
+ flex: 1,
20
+ },
21
+ lineVertical: {
22
+ width: 2,
23
+ minHeight: 20,
24
+ flex: 1,
25
+ },
26
+ radiusLeft: {
27
+ borderTopLeftRadius: Radius.S,
28
+ borderBottomLeftRadius: Radius.S,
29
+ },
30
+ radiusRight: {
31
+ borderTopRightRadius: Radius.S,
32
+ borderBottomRightRadius: Radius.S,
33
+ },
34
+ center: {
35
+ alignItems: 'center',
36
+ justifyContent: 'center',
37
+ },
38
+ rowStep: {
39
+ flexDirection: 'row',
40
+ alignItems: 'center',
41
+ },
42
+ title: {
43
+ marginBottom: Spacing.XS,
44
+ },
45
+ textCenter: {
46
+ textAlign: 'center',
47
+ },
48
+ });
package/types.ts ADDED
@@ -0,0 +1,23 @@
1
+ import {ViewStyle} from 'react-native';
2
+
3
+ export type StepsProps = {
4
+ horizontal?: boolean;
5
+ steps: Step[];
6
+ size?: 'small' | 'large';
7
+ activeIndex: number;
8
+ };
9
+
10
+ export type Step = {
11
+ title: string;
12
+ description?: string;
13
+ error?: boolean;
14
+ time?: string;
15
+ };
16
+
17
+ export type StepIconProps = {
18
+ size?: 'small' | 'large';
19
+ backgroundColor?: string;
20
+ borderColor?: string;
21
+ error?: boolean;
22
+ style?: ViewStyle;
23
+ };
package/utils.ts ADDED
@@ -0,0 +1,126 @@
1
+ import {useContext} from 'react';
2
+ import {ApplicationContext, Colors, Typography} from '@momo-kits/foundation';
3
+
4
+ type StepStatus = 'inactive' | 'active' | 'completed' | 'error';
5
+ type StepTypo = {
6
+ typography: Typography;
7
+ color: string;
8
+ };
9
+
10
+ export const getStepTypo = (
11
+ activeIndex: number,
12
+ currentIndex: number,
13
+ error?: boolean,
14
+ size?: 'small' | 'large',
15
+ ) => {
16
+ const {theme} = useContext(ApplicationContext);
17
+
18
+ let title: StepTypo = {
19
+ color: theme.colors.text.default,
20
+ typography: 'description_s',
21
+ };
22
+ let description: StepTypo = {
23
+ color: theme.colors.text.hint,
24
+ typography: 'description_s',
25
+ };
26
+ let time: StepTypo = {
27
+ color: theme.colors.text.hint,
28
+ typography: 'description_xs',
29
+ };
30
+
31
+ let status: StepStatus = 'inactive';
32
+ if (activeIndex > currentIndex) {
33
+ status = 'completed';
34
+ }
35
+ if (activeIndex === currentIndex) {
36
+ status = 'active';
37
+ }
38
+ if (error) {
39
+ status = 'error';
40
+ }
41
+
42
+ switch (status) {
43
+ case 'active': {
44
+ title.typography = 'header_xs';
45
+ break;
46
+ }
47
+
48
+ case 'completed': {
49
+ title.color = theme.colors.text.disable;
50
+ description.color = theme.colors.text.disable;
51
+ time.color = theme.colors.text.disable;
52
+ break;
53
+ }
54
+
55
+ case 'error': {
56
+ title.typography = 'header_xs';
57
+ title.color = theme.colors.error.primary;
58
+ break;
59
+ }
60
+ }
61
+
62
+ if (size === 'small') {
63
+ description.typography = 'description_xs';
64
+ }
65
+
66
+ return {title, description, time};
67
+ };
68
+
69
+ export const getStepColor = (
70
+ activeIndex: number,
71
+ currentIndex: number,
72
+ error?: boolean,
73
+ length: number = 1,
74
+ ) => {
75
+ const {theme} = useContext(ApplicationContext);
76
+ const DEFAULT_LINE_COLOR = theme.colors.background.default;
77
+ const COMPLETED_LINE_COLOR = theme.colors.secondary;
78
+
79
+ let backgroundColor = Colors.black_06;
80
+ let borderColor = theme.colors.border.default;
81
+ let lineColorLeft = DEFAULT_LINE_COLOR;
82
+ let lineColorRight = DEFAULT_LINE_COLOR;
83
+ let status: StepStatus = 'inactive';
84
+
85
+ if (activeIndex > currentIndex) {
86
+ status = 'completed';
87
+ lineColorLeft = COMPLETED_LINE_COLOR;
88
+ lineColorRight = COMPLETED_LINE_COLOR;
89
+ }
90
+ if (activeIndex === currentIndex) {
91
+ status = 'active';
92
+ lineColorLeft = COMPLETED_LINE_COLOR;
93
+ }
94
+ if (error) {
95
+ status = 'error';
96
+ }
97
+
98
+ if (currentIndex === 0) {
99
+ lineColorLeft = 'transparent';
100
+ }
101
+ if (currentIndex === length - 1) {
102
+ lineColorRight = 'transparent';
103
+ }
104
+
105
+ switch (status) {
106
+ case 'active': {
107
+ backgroundColor = theme.colors.primary;
108
+ borderColor = theme.colors.background.tonal;
109
+ break;
110
+ }
111
+
112
+ case 'completed': {
113
+ backgroundColor = Colors.pink_08;
114
+ borderColor = Colors.pink_10;
115
+ break;
116
+ }
117
+
118
+ case 'error': {
119
+ backgroundColor = theme.colors.error.primary;
120
+ borderColor = theme.colors.error.container;
121
+ break;
122
+ }
123
+ }
124
+
125
+ return {backgroundColor, borderColor, lineColorLeft, lineColorRight};
126
+ };