@momo-kits/foundation 0.92.1-tracking.8 → 0.92.2-tracking.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.
package/Title/index.tsx CHANGED
@@ -1,129 +1,175 @@
1
1
  import React, {FC, useContext, useState} from 'react';
2
- import {
3
- LayoutChangeEvent,
4
- NativeSyntheticEvent,
5
- Text as RNText,
6
- TextLayoutEventData,
7
- TouchableOpacity,
8
- View,
9
- } from 'react-native';
10
- import {TitleProps} from './types';
11
- import {Icon} from '../Icon';
2
+ import {Text as RNText, TouchableOpacity, View, ViewStyle} from 'react-native';
12
3
  import styles from './styles';
13
- import {ApplicationContext} from '../Application';
14
- import {Colors, Spacing} from '../Consts';
4
+ import {Icon} from '../Icon';
15
5
  import {scaleSize, Text} from '../Text';
6
+ import {ApplicationContext} from '../Application';
7
+ import {Badge} from '../Badge';
8
+ import {Typography} from '../Text/types';
9
+ import {TitleProps} from './types';
10
+ import {Colors} from '../Consts';
16
11
 
17
12
  const Title: FC<TitleProps> = ({
18
- size = 'large',
19
- type = 'section',
20
- onPressAction,
21
- actionTitle,
22
13
  title = 'Title',
23
- titleFlex = true,
24
- showAction = true,
14
+ type = 'section',
15
+ size = 'medium',
25
16
  icon,
26
17
  description,
27
- usePadding = true,
18
+ iconColor = null,
19
+ iconAlign = 'top',
20
+ showRightAction = false,
21
+ showTrailingAction = false,
22
+ badgeLabel,
23
+ buttonTitle,
24
+ onPressRightAction = () => {},
25
+ buttonSize = 'small',
26
+ textOnly = false,
28
27
  }) => {
29
28
  const {theme} = useContext(ApplicationContext);
30
- const [containerWidth, setContainerWidth] = useState(0);
31
- const [textLines, setTextLines] = useState(0);
32
- const typeStyle =
33
- type === 'screen' ? styles.screen : styles[`${type}_${size}`];
34
- const titleWeight = type === 'screen' ? 'Semibold' : 'Bold';
35
- const marginStyle =
36
- type === 'section' && usePadding ? {marginTop: Spacing.S} : {};
37
- const numberOfLines = type === 'section' ? 1 : 2;
29
+ const [badgeWidth, setBadgeWidth] = useState(0);
30
+ const [contentWidth, setContentWidth] = useState(0);
31
+ const styleSheet: {
32
+ [key: string]: any;
33
+ } = styles;
34
+ const typography = `${type}_${size}`;
35
+ const isSection = type === 'section';
36
+ const numberOfLines = showTrailingAction || !!badgeLabel ? 1 : 2;
37
+ const buttonTypo: Typography =
38
+ buttonSize === 'small' ? 'action_xs_bold' : 'action_s_bold';
39
+ const flexStyle = showTrailingAction && {maxWidth: '70%'};
38
40
 
39
- const renderAction = () => {
40
- return !!actionTitle && titleFlex ? (
41
- <TouchableOpacity onPress={onPressAction}>
42
- <Text typography={'action_s_bold'} color={theme.colors.primary}>
43
- {actionTitle}
44
- </Text>
45
- </TouchableOpacity>
46
- ) : (
47
- <TouchableOpacity
48
- style={[
49
- {backgroundColor: theme.colors.primary + '0F'},
50
- styles.actionIcon,
51
- {width: scaleSize(22), height: scaleSize(22)},
52
- ]}
53
- onPress={onPressAction}>
54
- <Icon
55
- size={scaleSize(22)}
56
- color={theme.colors.primary}
57
- source={'arrow_chevron_right_small'}
58
- />
59
- </TouchableOpacity>
41
+ const renderIcon = () => {
42
+ if (!icon) return null;
43
+
44
+ let iconStyle: ViewStyle = {
45
+ justifyContent: 'flex-start',
46
+ };
47
+
48
+ if (iconAlign === 'middle') {
49
+ iconStyle = {justifyContent: 'center'};
50
+ }
51
+
52
+ if (iconAlign === 'bottom') {
53
+ iconStyle = {justifyContent: 'flex-end'};
54
+ }
55
+
56
+ return (
57
+ <View style={[styles.iconView, iconStyle]}>
58
+ <Icon color={iconColor} source={icon} />
59
+ </View>
60
60
  );
61
61
  };
62
62
 
63
- const renderSemiAction = () => {
64
- if (textLines > 1) return null;
63
+ const renderContent = () => {
65
64
  return (
66
- <TouchableOpacity
67
- style={[
68
- {backgroundColor: Colors.black_06},
69
- styles.actionIcon,
70
- {width: scaleSize(18), height: scaleSize(18)},
71
- ]}
72
- onPress={onPressAction}>
73
- <Icon
74
- size={scaleSize(18)}
75
- color={theme.colors.text.default}
76
- source={'arrow_chevron_right_small'}
77
- />
78
- </TouchableOpacity>
65
+ <View style={styles.contentView}>
66
+ <View
67
+ onLayout={e => {
68
+ setContentWidth(e.nativeEvent.layout.width);
69
+ }}
70
+ style={[styles.iconLeftView, flexStyle]}>
71
+ <RNText
72
+ numberOfLines={numberOfLines}
73
+ style={[
74
+ styleSheet[typography],
75
+ styles.title,
76
+ {maxWidth: contentWidth - badgeWidth},
77
+ ]}>
78
+ {title}
79
+ </RNText>
80
+ {badgeLabel && (
81
+ <View
82
+ onLayout={e => {
83
+ setBadgeWidth(e.nativeEvent.layout.width);
84
+ }}
85
+ style={{
86
+ alignItems: 'center',
87
+ }}>
88
+ <Badge style={styles.badge} label={badgeLabel} />
89
+ </View>
90
+ )}
91
+ {renderActionLeft()}
92
+ </View>
93
+ <Text
94
+ color={theme.colors.text.secondary}
95
+ typography={'description_default_regular'}>
96
+ {description}
97
+ </Text>
98
+ </View>
79
99
  );
80
100
  };
81
- const onLayout = (e: LayoutChangeEvent) => {
82
- setContainerWidth(e.nativeEvent.layout.width);
83
- };
84
101
 
85
- const onTextLayout = (e: NativeSyntheticEvent<TextLayoutEventData>) => {
86
- setTextLines(e.nativeEvent.lines.length);
102
+ const renderActionLeft = () => {
103
+ return (
104
+ <View style={styles.iconLeftView}>
105
+ {showTrailingAction && !showRightAction && (
106
+ <View
107
+ style={[
108
+ styles.iconLeft,
109
+ {
110
+ backgroundColor: isSection
111
+ ? Colors.black_06 + '99'
112
+ : Colors.black_06 + '4D',
113
+ },
114
+ ]}>
115
+ <Icon
116
+ source={'arrow_chevron_right_small'}
117
+ size={scaleSize(18)}
118
+ color={theme.colors.text.default}
119
+ />
120
+ </View>
121
+ )}
122
+ </View>
123
+ );
87
124
  };
88
125
 
89
- return (
90
- <View onLayout={onLayout} style={[styles.wrapper, marginStyle]}>
91
- {!!icon && type !== 'screen' && (
92
- <Icon style={styles.icon} source={icon} />
93
- )}
94
- <View style={{flex: 1, flexDirection: 'row'}}>
95
- <View style={styles.textContent}>
126
+ const renderActionRight = () => {
127
+ if (!showRightAction || showTrailingAction) return false;
128
+
129
+ return (
130
+ <View>
131
+ {!buttonTitle ? (
96
132
  <View
97
- style={{
98
- flexDirection: 'row',
99
- maxWidth: containerWidth - scaleSize(22),
100
- }}>
101
- <RNText
102
- onTextLayout={onTextLayout}
103
- numberOfLines={numberOfLines}
104
- style={[
105
- typeStyle,
106
- {
107
- fontFamily: `${theme.font}-${titleWeight}`,
108
- color: theme.colors.text.default,
109
- marginRight: Spacing.S,
110
- },
111
- ]}>
112
- {title}
113
- </RNText>
114
- {!titleFlex && renderSemiAction()}
133
+ style={[
134
+ styles.iconRight,
135
+ {
136
+ backgroundColor: theme.colors.primary + '0F',
137
+ },
138
+ ]}>
139
+ <Icon
140
+ source={'arrow_chevron_right_small'}
141
+ size={scaleSize(22)}
142
+ color={theme.colors.primary}
143
+ />
115
144
  </View>
116
- {!!description && type !== 'screen' && (
117
- <Text
118
- numberOfLines={1}
119
- typography={'description_default_regular'}
120
- color={theme.colors.text.secondary}>
121
- {description}
145
+ ) : (
146
+ <TouchableOpacity onPress={onPressRightAction}>
147
+ <Text color={theme.colors.primary} typography={buttonTypo}>
148
+ {buttonTitle}
122
149
  </Text>
123
- )}
124
- </View>
125
- {showAction && titleFlex && type !== 'screen' && renderAction()}
150
+ </TouchableOpacity>
151
+ )}
126
152
  </View>
153
+ );
154
+ };
155
+
156
+ if (textOnly) {
157
+ return (
158
+ <View style={isSection && styles.margin}>
159
+ <RNText
160
+ numberOfLines={numberOfLines}
161
+ style={[styleSheet[typography], styles.title]}>
162
+ {title}
163
+ </RNText>
164
+ </View>
165
+ );
166
+ }
167
+
168
+ return (
169
+ <View style={[styles.wrapper, isSection && styles.margin]}>
170
+ {renderIcon()}
171
+ {renderContent()}
172
+ {renderActionRight()}
127
173
  </View>
128
174
  );
129
175
  };
package/Title/styles.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {StyleSheet} from 'react-native';
2
2
  import {scaleSize} from '../Text';
3
- import {Radius, Spacing} from '../Consts';
3
+ import {Colors, Radius, Spacing} from '../Consts';
4
4
 
5
5
  export default StyleSheet.create({
6
6
  card_small: {
@@ -27,10 +27,6 @@ export default StyleSheet.create({
27
27
  fontSize: scaleSize(24),
28
28
  lineHeight: scaleSize(34),
29
29
  },
30
- screen: {
31
- fontSize: scaleSize(36),
32
- lineHeight: scaleSize(44),
33
- },
34
30
  actionIcon: {
35
31
  borderRadius: Radius.M,
36
32
  alignItems: 'center',
@@ -41,12 +37,40 @@ export default StyleSheet.create({
41
37
  borderRadius: Radius.XS,
42
38
  },
43
39
  wrapper: {
44
- width: '100%',
45
40
  flexDirection: 'row',
46
- alignItems: 'center',
47
41
  },
48
- textContent: {
42
+ margin: {
43
+ marginTop: Spacing.S,
44
+ },
45
+ iconView: {
49
46
  marginRight: Spacing.S,
50
- flex: 1,
47
+ },
48
+ iconRight: {
49
+ width: scaleSize(22),
50
+ height: scaleSize(22),
51
+ borderRadius: Radius.M,
52
+ alignItems: 'center',
53
+ justifyContent: 'center',
54
+ marginLeft: Spacing.S,
55
+ },
56
+ iconLeft: {
57
+ width: scaleSize(18),
58
+ height: scaleSize(18),
59
+ borderRadius: Radius.M,
60
+ alignItems: 'center',
61
+ justifyContent: 'center',
62
+ marginHorizontal: Spacing.XS,
63
+ },
64
+ iconLeftView: {
65
+ flexDirection: 'row',
66
+ alignItems: 'center',
67
+ },
68
+ contentView: {marginRight: Spacing.S, flex: 1},
69
+ title: {
70
+ fontWeight: 'bold',
71
+ marginBottom: Spacing.XS,
72
+ },
73
+ badge: {
74
+ marginLeft: Spacing.XS,
51
75
  },
52
76
  });
package/Title/types.ts CHANGED
@@ -1,52 +1,16 @@
1
1
  export type TitleProps = {
2
- /**
3
- * Optional. Defines the type of Title component.
4
- * 'screen' - Used for screen titles.
5
- * 'section' - Used for section titles within a screen.
6
- * 'card' - Used for titles within a card component.
7
- */
8
- type?: 'screen' | 'section' | 'card';
9
-
10
- /**
11
- * Required. The text of the title.
12
- */
2
+ type?: 'card' | 'section';
3
+ size?: 'small' | 'medium' | 'large';
13
4
  title: string;
14
-
15
- /**
16
- * Optional. A description or subtitle that appears below the title.
17
- */
18
- description?: string;
19
-
20
- /**
21
- * Optional. Defines the size of the Title component.
22
- * 'large' - A larger, more prominent title.
23
- * 'small' - A smaller, less prominent title.
24
- */
25
- size?: 'large' | 'medium' | 'small';
26
-
27
- /**
28
- * Optional. Represents the name or key of the icon to be displayed alongside the title.
29
- */
30
5
  icon?: string;
31
-
32
- /**
33
- * Optional. If `true`, the title will be flexible in its container, adjusting its width dynamically.
34
- */
35
- titleFlex?: boolean;
36
-
37
- /**
38
- * Optional. Text for an action button associated with the title.
39
- */
40
- actionTitle?: string;
41
-
42
- /**
43
- * Optional. Function to be called when the action associated with the title is pressed.
44
- */
45
- onPressAction?: () => void;
46
-
47
- /**
48
- * Optional. If `true`, an action button or icon is displayed alongside the title.
49
- */
50
- showAction?: boolean;
51
- usePadding?: boolean;
6
+ description?: string;
7
+ iconColor?: string;
8
+ iconAlign?: 'top' | 'middle' | 'bottom';
9
+ showRightAction?: boolean;
10
+ showTrailingAction?: boolean;
11
+ badgeLabel?: string;
12
+ buttonTitle?: string;
13
+ buttonSize?: 'small' | 'large';
14
+ onPressRightAction?: () => void;
15
+ textOnly?: boolean;
52
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.92.1-tracking.8",
3
+ "version": "0.92.2-tracking.1",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -14,6 +14,7 @@
14
14
  "react-native-safe-area-context": "3.1.4",
15
15
  "react-native-linear-gradient": "2.8.3",
16
16
  "react-native-gesture-handler": "1.10.3",
17
+ "react-native-modalize": "2.1.1",
17
18
  "react-native-fast-image": "8.1.5",
18
19
  "@react-navigation/bottom-tabs": "git+https://gitlab.com/momo-platform/react-navigation-bottom-tabs.git#main",
19
20
  "@react-navigation/core": "5.16.1",
@@ -32,6 +33,7 @@
32
33
  "@types/jest": "26.0.23",
33
34
  "@types/react-native": "0.64.4",
34
35
  "@types/react-test-renderer": "16.9.2",
36
+ "@types/d3-shape": "1.3.7",
35
37
  "babel-jest": "^26.6.3",
36
38
  "eslint": "^7.14.0",
37
39
  "jest": "^26.6.3",