@momo-kits/foundation 0.89.6 → 0.92.1-rc.10

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,135 @@
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';
1
+ import React, {FC, useContext} from 'react';
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';
16
10
 
17
11
  const Title: FC<TitleProps> = ({
18
- size = 'large',
19
- type = 'section',
20
- onPressAction,
21
- actionTitle,
22
12
  title = 'Title',
23
- titleFlex = true,
24
- showAction = true,
13
+ type = 'section',
14
+ size = 'medium',
25
15
  icon,
26
16
  description,
27
- usePadding = true,
17
+ iconColor = null,
18
+ iconAlign = 'top',
19
+ showRightAction = false,
20
+ showLeftAction = false,
21
+ badgeLabel,
22
+ buttonTitle,
23
+ onPressRightAction = () => {},
24
+ buttonSize = 'small',
28
25
  }) => {
29
26
  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;
38
27
 
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>
28
+ const styleSheet: {
29
+ [key: string]: any;
30
+ } = styles;
31
+ const typography = `${type}_${size}`;
32
+ const isSection = type === 'section';
33
+ const numberOfLines = showLeftAction || !!badgeLabel ? 1 : 2;
34
+ const buttonTypo: Typography =
35
+ buttonSize === 'small' ? 'action_xs_bold' : 'action_s_bold';
36
+
37
+ const renderIcon = () => {
38
+ if (!icon) return null;
39
+
40
+ let iconStyle: ViewStyle = {
41
+ justifyContent: 'flex-start',
42
+ };
43
+
44
+ if (iconAlign === 'middle') {
45
+ iconStyle = {justifyContent: 'center'};
46
+ }
47
+
48
+ if (iconAlign === 'bottom') {
49
+ iconStyle = {justifyContent: 'flex-end'};
50
+ }
51
+
52
+ return (
53
+ <View style={[styles.iconView, iconStyle]}>
54
+ <Icon color={iconColor} source={icon} />
55
+ </View>
60
56
  );
61
57
  };
62
58
 
63
- const renderSemiAction = () => {
64
- if (textLines > 1) return null;
59
+ const renderContent = () => {
65
60
  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>
61
+ <View style={styles.contentView}>
62
+ <View style={[styles.iconLeftView]}>
63
+ <RNText
64
+ numberOfLines={numberOfLines}
65
+ style={[styleSheet[typography], styles.title]}>
66
+ {title}
67
+ </RNText>
68
+
69
+ <View style={{alignItems: 'center'}}>
70
+ {badgeLabel && <Badge style={styles.badge} label={badgeLabel} />}
71
+ </View>
72
+ {renderActionLeft()}
73
+ </View>
74
+ <Text
75
+ color={theme.colors.text.secondary}
76
+ typography={'description_default_regular'}>
77
+ {description}
78
+ </Text>
79
+ </View>
79
80
  );
80
81
  };
81
- const onLayout = (e: LayoutChangeEvent) => {
82
- setContainerWidth(e.nativeEvent.layout.width);
83
- };
84
82
 
85
- const onTextLayout = (e: NativeSyntheticEvent<TextLayoutEventData>) => {
86
- setTextLines(e.nativeEvent.lines.length);
83
+ const renderActionLeft = () => {
84
+ return (
85
+ <View style={styles.iconLeftView}>
86
+ {showLeftAction && !showRightAction && (
87
+ <View style={styles.iconLeft}>
88
+ <Icon
89
+ source={'arrow_chevron_right_small'}
90
+ size={scaleSize(18)}
91
+ color={theme.colors.text.default}
92
+ />
93
+ </View>
94
+ )}
95
+ </View>
96
+ );
87
97
  };
88
98
 
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}>
99
+ const renderActionRight = () => {
100
+ if (!showRightAction || showLeftAction) return false;
101
+
102
+ return (
103
+ <View>
104
+ {!buttonTitle ? (
96
105
  <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()}
106
+ style={[
107
+ styles.iconRight,
108
+ {
109
+ backgroundColor: theme.colors.primary + '0F',
110
+ },
111
+ ]}>
112
+ <Icon
113
+ source={'arrow_chevron_right_small'}
114
+ size={scaleSize(22)}
115
+ color={theme.colors.primary}
116
+ />
115
117
  </View>
116
- {!!description && type !== 'screen' && (
117
- <Text
118
- numberOfLines={1}
119
- typography={'description_default_regular'}
120
- color={theme.colors.text.secondary}>
121
- {description}
118
+ ) : (
119
+ <TouchableOpacity onPress={onPressRightAction}>
120
+ <Text color={theme.colors.primary} typography={buttonTypo}>
121
+ {buttonTitle}
122
122
  </Text>
123
- )}
124
- </View>
125
- {showAction && titleFlex && type !== 'screen' && renderAction()}
123
+ </TouchableOpacity>
124
+ )}
126
125
  </View>
126
+ );
127
+ };
128
+ return (
129
+ <View style={[styles.wrapper, isSection && styles.margin]}>
130
+ {renderIcon()}
131
+ {renderContent()}
132
+ {renderActionRight()}
127
133
  </View>
128
134
  );
129
135
  };
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,42 @@ 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,
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
+ backgroundColor: Colors.black_06,
64
+ },
65
+ iconLeftView: {
66
+ flexDirection: 'row',
67
+ alignItems: 'center',
68
+ },
69
+ contentView: {marginRight: Spacing.S, flex: 1},
70
+ title: {
71
+ fontWeight: 'bold',
72
+ marginBottom: Spacing.XS,
50
73
  flex: 1,
51
74
  },
75
+ badge: {
76
+ marginLeft: Spacing.XS,
77
+ },
52
78
  });
package/Title/types.ts CHANGED
@@ -1,52 +1,15 @@
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
+ showLeftAction?: boolean;
11
+ badgeLabel?: string;
12
+ buttonTitle?: string;
13
+ buttonSize?: 'small' | 'large';
14
+ onPressRightAction?: () => void;
52
15
  };
package/index.ts CHANGED
@@ -4,11 +4,12 @@ import {
4
4
  useSafeAreaInsets,
5
5
  } from 'react-native-safe-area-context';
6
6
  import LinearGradient from 'react-native-linear-gradient';
7
+ import {getAccessibilityID} from "./Application/utils";
7
8
 
8
9
  /**
9
10
  * native export
10
11
  */
11
- export {SafeAreaView, useSafeAreaInsets, SafeAreaProvider, LinearGradient};
12
+ export {SafeAreaView, useSafeAreaInsets, SafeAreaProvider, LinearGradient, getAccessibilityID};
12
13
 
13
14
  /**
14
15
  * foundation component
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.89.6",
3
+ "version": "0.92.1-rc.10",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -10,6 +10,7 @@
10
10
  "@momo-kits/foundation"
11
11
  ],
12
12
  "dependencies": {
13
+ "@gorhom/bottom-sheet": "git+https://gitlab.com/momo-platform/bottom-sheet.git#main",
13
14
  "react-native-safe-area-context": "3.1.4",
14
15
  "react-native-linear-gradient": "2.8.3",
15
16
  "react-native-gesture-handler": "1.10.3",
@@ -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",