@momo-kits/title 0.81.1-rc.0
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/index.tsx +201 -0
- package/package.json +17 -0
- package/publish.sh +28 -0
- package/styles.ts +78 -0
- package/types.ts +20 -0
package/index.tsx
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import React, {FC, useContext, useState} from 'react';
|
|
2
|
+
import {Text as RNText, TouchableOpacity, View, ViewStyle} from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
ApplicationContext,
|
|
5
|
+
Badge,
|
|
6
|
+
Colors,
|
|
7
|
+
Icon,
|
|
8
|
+
Text,
|
|
9
|
+
Typography,
|
|
10
|
+
} from '@momo-kits/foundation';
|
|
11
|
+
import styles from './styles';
|
|
12
|
+
import {TitleProps} from './types';
|
|
13
|
+
|
|
14
|
+
const Title: FC<TitleProps> = ({
|
|
15
|
+
title = 'Title',
|
|
16
|
+
type = 'section',
|
|
17
|
+
size = 'medium',
|
|
18
|
+
icon,
|
|
19
|
+
description,
|
|
20
|
+
iconColor = null,
|
|
21
|
+
iconAlign = 'top',
|
|
22
|
+
showRightAction = false,
|
|
23
|
+
showTrailingAction = false,
|
|
24
|
+
badgeLabel,
|
|
25
|
+
buttonTitle,
|
|
26
|
+
onPressRightAction = () => {},
|
|
27
|
+
onPressTrailingAction = () => {},
|
|
28
|
+
buttonSize = 'small',
|
|
29
|
+
textOnly = false,
|
|
30
|
+
style,
|
|
31
|
+
}) => {
|
|
32
|
+
const {theme} = useContext(ApplicationContext);
|
|
33
|
+
const [badgeWidth, setBadgeWidth] = useState(0);
|
|
34
|
+
const [contentWidth, setContentWidth] = useState(0);
|
|
35
|
+
const styleSheet: {
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
} = styles;
|
|
38
|
+
const typography = `${type}_${size}`;
|
|
39
|
+
const isSection = type === 'section';
|
|
40
|
+
const numberOfLines = showTrailingAction || !!badgeLabel ? 1 : 2;
|
|
41
|
+
const buttonTypo: Typography =
|
|
42
|
+
buttonSize === 'small' ? 'action_xs_bold' : 'action_s_bold';
|
|
43
|
+
const flexStyle = showTrailingAction && {maxWidth: '70%'};
|
|
44
|
+
|
|
45
|
+
const renderIcon = () => {
|
|
46
|
+
if (!icon) return null;
|
|
47
|
+
|
|
48
|
+
let iconStyle: ViewStyle = {
|
|
49
|
+
justifyContent: 'flex-start',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (iconAlign === 'middle') {
|
|
53
|
+
iconStyle = {justifyContent: 'center'};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (iconAlign === 'bottom') {
|
|
57
|
+
iconStyle = {justifyContent: 'flex-end'};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<View style={[styles.iconView, iconStyle]}>
|
|
62
|
+
<Icon color={iconColor} source={icon} />
|
|
63
|
+
</View>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const renderContent = () => {
|
|
68
|
+
return (
|
|
69
|
+
<View style={styles.contentView}>
|
|
70
|
+
<View
|
|
71
|
+
onLayout={e => {
|
|
72
|
+
if (e.nativeEvent.layout.width !== contentWidth) {
|
|
73
|
+
setContentWidth(e.nativeEvent.layout.width);
|
|
74
|
+
}
|
|
75
|
+
}}
|
|
76
|
+
style={[styles.iconLeftView, flexStyle]}>
|
|
77
|
+
<RNText
|
|
78
|
+
numberOfLines={numberOfLines}
|
|
79
|
+
style={[
|
|
80
|
+
styleSheet[typography],
|
|
81
|
+
styles.title,
|
|
82
|
+
{
|
|
83
|
+
maxWidth:
|
|
84
|
+
contentWidth > 0 ? contentWidth - badgeWidth : undefined,
|
|
85
|
+
},
|
|
86
|
+
]}>
|
|
87
|
+
{title}
|
|
88
|
+
</RNText>
|
|
89
|
+
{badgeLabel && (
|
|
90
|
+
<View
|
|
91
|
+
onLayout={e => {
|
|
92
|
+
if (e.nativeEvent.layout.width !== badgeWidth) {
|
|
93
|
+
setBadgeWidth(e.nativeEvent.layout.width);
|
|
94
|
+
}
|
|
95
|
+
}}
|
|
96
|
+
style={{
|
|
97
|
+
alignItems: 'center',
|
|
98
|
+
}}>
|
|
99
|
+
<Badge style={styles.badge} label={badgeLabel} />
|
|
100
|
+
</View>
|
|
101
|
+
)}
|
|
102
|
+
{renderActionLeft()}
|
|
103
|
+
</View>
|
|
104
|
+
{!!description && (
|
|
105
|
+
<Text
|
|
106
|
+
style={styles.description}
|
|
107
|
+
color={theme.colors.text.secondary}
|
|
108
|
+
typography={'description_default_regular'}>
|
|
109
|
+
{description}
|
|
110
|
+
</Text>
|
|
111
|
+
)}
|
|
112
|
+
</View>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const renderActionLeft = () => {
|
|
117
|
+
return (
|
|
118
|
+
<TouchableOpacity
|
|
119
|
+
onPress={onPressTrailingAction}
|
|
120
|
+
style={styles.iconLeftView}>
|
|
121
|
+
{showTrailingAction && !showRightAction && (
|
|
122
|
+
<View
|
|
123
|
+
style={[
|
|
124
|
+
styles.iconLeft,
|
|
125
|
+
{
|
|
126
|
+
backgroundColor: isSection
|
|
127
|
+
? Colors.black_06 + '99'
|
|
128
|
+
: Colors.black_06 + '4D',
|
|
129
|
+
},
|
|
130
|
+
]}>
|
|
131
|
+
<Icon
|
|
132
|
+
source={'arrow_chevron_right_small'}
|
|
133
|
+
size={18}
|
|
134
|
+
color={theme.colors.text.default}
|
|
135
|
+
/>
|
|
136
|
+
</View>
|
|
137
|
+
)}
|
|
138
|
+
</TouchableOpacity>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const renderActionRight = () => {
|
|
143
|
+
if (!showRightAction || showTrailingAction) return false;
|
|
144
|
+
|
|
145
|
+
const lineHeight = styleSheet[typography].lineHeight;
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<View
|
|
149
|
+
style={{
|
|
150
|
+
height: lineHeight,
|
|
151
|
+
justifyContent: 'center',
|
|
152
|
+
}}>
|
|
153
|
+
{!buttonTitle ? (
|
|
154
|
+
<TouchableOpacity
|
|
155
|
+
onPress={onPressRightAction}
|
|
156
|
+
style={[
|
|
157
|
+
styles.iconRight,
|
|
158
|
+
{
|
|
159
|
+
backgroundColor: theme.colors.primary + '0F',
|
|
160
|
+
},
|
|
161
|
+
]}>
|
|
162
|
+
<Icon
|
|
163
|
+
source={'arrow_chevron_right_small'}
|
|
164
|
+
size={22}
|
|
165
|
+
color={theme.colors.primary}
|
|
166
|
+
/>
|
|
167
|
+
</TouchableOpacity>
|
|
168
|
+
) : (
|
|
169
|
+
<TouchableOpacity onPress={onPressRightAction}>
|
|
170
|
+
<Text color={theme.colors.primary} typography={buttonTypo}>
|
|
171
|
+
{buttonTitle}
|
|
172
|
+
</Text>
|
|
173
|
+
</TouchableOpacity>
|
|
174
|
+
)}
|
|
175
|
+
</View>
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
if (textOnly) {
|
|
180
|
+
return (
|
|
181
|
+
<View style={isSection && styles.margin}>
|
|
182
|
+
<RNText
|
|
183
|
+
numberOfLines={numberOfLines}
|
|
184
|
+
style={[styleSheet[typography], styles.title]}>
|
|
185
|
+
{title}
|
|
186
|
+
</RNText>
|
|
187
|
+
</View>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<View style={[style, styles.wrapper, isSection && styles.margin]}>
|
|
193
|
+
{renderIcon()}
|
|
194
|
+
{renderContent()}
|
|
195
|
+
{renderActionRight()}
|
|
196
|
+
</View>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export {Title};
|
|
201
|
+
export type {TitleProps};
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momo-kits/title",
|
|
3
|
+
"version": "0.81.1-rc.0",
|
|
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,28 @@
|
|
|
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
|
+
|
|
10
|
+
if [ "$1" == "stable" ]; then
|
|
11
|
+
npm version $(npm view @momo-kits/foundation@stable version)
|
|
12
|
+
npm version patch
|
|
13
|
+
npm publish --tag stable --access=public
|
|
14
|
+
elif [ "$1" == "latest" ]; then
|
|
15
|
+
npm version $(npm view @momo-kits/foundation@latest version)
|
|
16
|
+
npm publish --tag latest --access=public
|
|
17
|
+
else
|
|
18
|
+
npm version $(npm view @momo-kits/title@beta version)
|
|
19
|
+
npm version prerelease --preid=beta
|
|
20
|
+
npm publish --tag beta --access=public
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
PACKAGE_NAME=$(npm pkg get name)
|
|
24
|
+
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
25
|
+
|
|
26
|
+
# Clean up
|
|
27
|
+
cd ..
|
|
28
|
+
rm -rf dist
|
package/styles.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
import {Colors, Radius, scaleSize, Spacing} from '@momo-kits/foundation';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
card_small: {
|
|
6
|
+
fontSize: scaleSize(14),
|
|
7
|
+
lineHeight: scaleSize(20),
|
|
8
|
+
},
|
|
9
|
+
card_medium: {
|
|
10
|
+
fontSize: scaleSize(16),
|
|
11
|
+
lineHeight: scaleSize(22),
|
|
12
|
+
},
|
|
13
|
+
card_large: {
|
|
14
|
+
fontSize: scaleSize(18),
|
|
15
|
+
lineHeight: scaleSize(26),
|
|
16
|
+
},
|
|
17
|
+
section_medium: {
|
|
18
|
+
fontSize: scaleSize(20),
|
|
19
|
+
lineHeight: scaleSize(28),
|
|
20
|
+
},
|
|
21
|
+
section_small: {
|
|
22
|
+
fontSize: scaleSize(16),
|
|
23
|
+
lineHeight: scaleSize(22),
|
|
24
|
+
},
|
|
25
|
+
section_large: {
|
|
26
|
+
fontSize: scaleSize(24),
|
|
27
|
+
lineHeight: scaleSize(34),
|
|
28
|
+
},
|
|
29
|
+
actionIcon: {
|
|
30
|
+
borderRadius: Radius.M,
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
justifyContent: 'center',
|
|
33
|
+
},
|
|
34
|
+
icon: {
|
|
35
|
+
marginRight: Spacing.S,
|
|
36
|
+
borderRadius: Radius.XS,
|
|
37
|
+
},
|
|
38
|
+
wrapper: {
|
|
39
|
+
flexDirection: 'row',
|
|
40
|
+
},
|
|
41
|
+
margin: {
|
|
42
|
+
marginTop: Spacing.S,
|
|
43
|
+
},
|
|
44
|
+
iconView: {
|
|
45
|
+
marginRight: Spacing.S,
|
|
46
|
+
},
|
|
47
|
+
iconRight: {
|
|
48
|
+
width: 22,
|
|
49
|
+
height: 22,
|
|
50
|
+
borderRadius: Radius.M,
|
|
51
|
+
alignItems: 'center',
|
|
52
|
+
justifyContent: 'center',
|
|
53
|
+
marginLeft: Spacing.S,
|
|
54
|
+
},
|
|
55
|
+
iconLeft: {
|
|
56
|
+
width: 18,
|
|
57
|
+
height: 18,
|
|
58
|
+
borderRadius: Radius.M,
|
|
59
|
+
alignItems: 'center',
|
|
60
|
+
justifyContent: 'center',
|
|
61
|
+
marginHorizontal: Spacing.XS,
|
|
62
|
+
},
|
|
63
|
+
iconLeftView: {
|
|
64
|
+
flexDirection: 'row',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
},
|
|
67
|
+
contentView: {marginRight: Spacing.S, flex: 1},
|
|
68
|
+
title: {
|
|
69
|
+
fontWeight: 'bold',
|
|
70
|
+
color: Colors.black_17,
|
|
71
|
+
},
|
|
72
|
+
badge: {
|
|
73
|
+
marginLeft: Spacing.XS,
|
|
74
|
+
},
|
|
75
|
+
description: {
|
|
76
|
+
marginTop: Spacing.XS,
|
|
77
|
+
},
|
|
78
|
+
});
|
package/types.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {ViewStyle} from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type TitleProps = {
|
|
4
|
+
type?: 'card' | 'section';
|
|
5
|
+
size?: 'small' | 'medium' | 'large';
|
|
6
|
+
title: string;
|
|
7
|
+
icon?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
iconColor?: string;
|
|
10
|
+
iconAlign?: 'top' | 'middle' | 'bottom';
|
|
11
|
+
showRightAction?: boolean;
|
|
12
|
+
showTrailingAction?: boolean;
|
|
13
|
+
badgeLabel?: string;
|
|
14
|
+
buttonTitle?: string;
|
|
15
|
+
buttonSize?: 'small' | 'large';
|
|
16
|
+
onPressRightAction?: () => void;
|
|
17
|
+
onPressTrailingAction?: () => void;
|
|
18
|
+
textOnly?: boolean;
|
|
19
|
+
style?: ViewStyle;
|
|
20
|
+
};
|