@momo-kits/title 0.153.2 → 0.154.1-beta.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/index.tsx +69 -20
- package/package.json +1 -1
- package/styles.ts +1 -25
package/index.tsx
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React, { FC, useContext, useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Text as RNText,
|
|
4
|
+
TouchableOpacity,
|
|
5
|
+
View,
|
|
6
|
+
ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
3
8
|
import {
|
|
4
9
|
ApplicationContext,
|
|
5
10
|
Badge,
|
|
@@ -10,6 +15,7 @@ import {
|
|
|
10
15
|
setAutomationID,
|
|
11
16
|
Text,
|
|
12
17
|
Typography,
|
|
18
|
+
useScaleSize,
|
|
13
19
|
} from '@momo-kits/foundation';
|
|
14
20
|
import styles from './styles';
|
|
15
21
|
import { TitleProps } from './types';
|
|
@@ -33,19 +39,48 @@ const Title: FC<TitleProps> = ({
|
|
|
33
39
|
textOnly = false,
|
|
34
40
|
style,
|
|
35
41
|
}) => {
|
|
36
|
-
const {theme} = useContext(ApplicationContext);
|
|
42
|
+
const { theme } = useContext(ApplicationContext);
|
|
37
43
|
const [badgeWidth, setBadgeWidth] = useState(0);
|
|
38
44
|
const [contentWidth, setContentWidth] = useState(0);
|
|
45
|
+
|
|
46
|
+
// Dynamic styles using useScaleSize hook
|
|
47
|
+
const dynamicStyles = {
|
|
48
|
+
card_small: {
|
|
49
|
+
fontSize: useScaleSize(14),
|
|
50
|
+
lineHeight: useScaleSize(20),
|
|
51
|
+
},
|
|
52
|
+
card_medium: {
|
|
53
|
+
fontSize: useScaleSize(16),
|
|
54
|
+
lineHeight: useScaleSize(22),
|
|
55
|
+
},
|
|
56
|
+
card_large: {
|
|
57
|
+
fontSize: useScaleSize(18),
|
|
58
|
+
lineHeight: useScaleSize(26),
|
|
59
|
+
},
|
|
60
|
+
section_medium: {
|
|
61
|
+
fontSize: useScaleSize(20),
|
|
62
|
+
lineHeight: useScaleSize(28),
|
|
63
|
+
},
|
|
64
|
+
section_small: {
|
|
65
|
+
fontSize: useScaleSize(16),
|
|
66
|
+
lineHeight: useScaleSize(22),
|
|
67
|
+
},
|
|
68
|
+
section_large: {
|
|
69
|
+
fontSize: useScaleSize(24),
|
|
70
|
+
lineHeight: useScaleSize(34),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
39
74
|
const styleSheet: {
|
|
40
75
|
[key: string]: any;
|
|
41
|
-
} = styles;
|
|
76
|
+
} = { ...styles, ...dynamicStyles };
|
|
42
77
|
const typography = `${type}_${size}`;
|
|
43
78
|
const isSection = type === 'section';
|
|
44
79
|
const numberOfLines = showTrailingAction || !!badgeLabel ? 1 : 2;
|
|
45
80
|
const buttonTypo: Typography =
|
|
46
81
|
buttonSize === 'small' ? 'action_xs_bold' : 'action_s_bold';
|
|
47
82
|
const flexStyle: ViewStyle | undefined = showTrailingAction
|
|
48
|
-
? {width: '70%'}
|
|
83
|
+
? { width: '70%' }
|
|
49
84
|
: undefined;
|
|
50
85
|
const componentName = 'Title';
|
|
51
86
|
|
|
@@ -68,17 +103,18 @@ const Title: FC<TitleProps> = ({
|
|
|
68
103
|
};
|
|
69
104
|
|
|
70
105
|
if (iconAlign === 'middle') {
|
|
71
|
-
iconStyle = {justifyContent: 'center'};
|
|
106
|
+
iconStyle = { justifyContent: 'center' };
|
|
72
107
|
}
|
|
73
108
|
|
|
74
109
|
if (iconAlign === 'bottom') {
|
|
75
|
-
iconStyle = {justifyContent: 'flex-end'};
|
|
110
|
+
iconStyle = { justifyContent: 'flex-end' };
|
|
76
111
|
}
|
|
77
112
|
|
|
78
113
|
return (
|
|
79
114
|
<View
|
|
80
115
|
accessibilityLabel={componentId + '|icon'}
|
|
81
|
-
style={[styles.iconView, iconStyle]}
|
|
116
|
+
style={[styles.iconView, iconStyle]}
|
|
117
|
+
>
|
|
82
118
|
<Icon color={iconColor} source={icon} />
|
|
83
119
|
</View>
|
|
84
120
|
);
|
|
@@ -93,9 +129,11 @@ const Title: FC<TitleProps> = ({
|
|
|
93
129
|
setContentWidth(e.nativeEvent.layout.width);
|
|
94
130
|
}
|
|
95
131
|
}}
|
|
96
|
-
style={[styles.iconLeftView, flexStyle]}
|
|
132
|
+
style={[styles.iconLeftView, flexStyle]}
|
|
133
|
+
>
|
|
97
134
|
<RNText
|
|
98
135
|
{...setAutomationID(componentId + '|title-text')}
|
|
136
|
+
allowFontScaling={false}
|
|
99
137
|
numberOfLines={numberOfLines}
|
|
100
138
|
style={[
|
|
101
139
|
styleSheet[typography],
|
|
@@ -104,7 +142,8 @@ const Title: FC<TitleProps> = ({
|
|
|
104
142
|
maxWidth:
|
|
105
143
|
contentWidth > 0 ? contentWidth - badgeWidth : undefined,
|
|
106
144
|
},
|
|
107
|
-
]}
|
|
145
|
+
]}
|
|
146
|
+
>
|
|
108
147
|
{title}
|
|
109
148
|
</RNText>
|
|
110
149
|
{badgeLabel && (
|
|
@@ -116,7 +155,8 @@ const Title: FC<TitleProps> = ({
|
|
|
116
155
|
}}
|
|
117
156
|
style={{
|
|
118
157
|
alignItems: 'center',
|
|
119
|
-
}}
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
120
160
|
<Badge
|
|
121
161
|
style={styles.badge}
|
|
122
162
|
label={badgeLabel}
|
|
@@ -131,7 +171,8 @@ const Title: FC<TitleProps> = ({
|
|
|
131
171
|
accessibilityLabel={componentId + '|description-text'}
|
|
132
172
|
style={styles.description}
|
|
133
173
|
color={theme.colors.text.secondary}
|
|
134
|
-
typography={'description_default_regular'}
|
|
174
|
+
typography={'description_default_regular'}
|
|
175
|
+
>
|
|
135
176
|
{description}
|
|
136
177
|
</Text>
|
|
137
178
|
)}
|
|
@@ -145,7 +186,8 @@ const Title: FC<TitleProps> = ({
|
|
|
145
186
|
accessibilityLabel={componentId + '|trailing-touch'}
|
|
146
187
|
onPress={onPressTrailingAction}
|
|
147
188
|
style={styles.iconLeftView}
|
|
148
|
-
hitSlop={{top: 10, bottom: 10, left: 50, right: 10}}
|
|
189
|
+
hitSlop={{ top: 10, bottom: 10, left: 50, right: 10 }}
|
|
190
|
+
>
|
|
149
191
|
{showTrailingAction && !showRightAction && (
|
|
150
192
|
<View
|
|
151
193
|
style={[
|
|
@@ -155,7 +197,8 @@ const Title: FC<TitleProps> = ({
|
|
|
155
197
|
? Colors.black_06 + '99'
|
|
156
198
|
: Colors.black_06 + '4D',
|
|
157
199
|
},
|
|
158
|
-
]}
|
|
200
|
+
]}
|
|
201
|
+
>
|
|
159
202
|
<Icon
|
|
160
203
|
source={'arrow_chevron_right_small'}
|
|
161
204
|
size={18}
|
|
@@ -177,7 +220,8 @@ const Title: FC<TitleProps> = ({
|
|
|
177
220
|
style={{
|
|
178
221
|
height: lineHeight,
|
|
179
222
|
justifyContent: 'center',
|
|
180
|
-
}}
|
|
223
|
+
}}
|
|
224
|
+
>
|
|
181
225
|
{!buttonTitle ? (
|
|
182
226
|
<TouchableOpacity
|
|
183
227
|
onPress={onPressRightAction}
|
|
@@ -187,7 +231,8 @@ const Title: FC<TitleProps> = ({
|
|
|
187
231
|
backgroundColor: theme.colors.primary + '0F',
|
|
188
232
|
},
|
|
189
233
|
]}
|
|
190
|
-
accessibilityLabel={componentId + '|label-right-action-touch'}
|
|
234
|
+
accessibilityLabel={componentId + '|label-right-action-touch'}
|
|
235
|
+
>
|
|
191
236
|
<Icon
|
|
192
237
|
source={'arrow_chevron_right_small'}
|
|
193
238
|
size={22}
|
|
@@ -197,7 +242,8 @@ const Title: FC<TitleProps> = ({
|
|
|
197
242
|
) : (
|
|
198
243
|
<TouchableOpacity
|
|
199
244
|
onPress={onPressRightAction}
|
|
200
|
-
accessibilityLabel={componentId + '|label-right-action-touch'}
|
|
245
|
+
accessibilityLabel={componentId + '|label-right-action-touch'}
|
|
246
|
+
>
|
|
201
247
|
<Text color={theme.colors.primary} typography={buttonTypo}>
|
|
202
248
|
{buttonTitle}
|
|
203
249
|
</Text>
|
|
@@ -212,8 +258,10 @@ const Title: FC<TitleProps> = ({
|
|
|
212
258
|
<View style={isSection && styles.margin}>
|
|
213
259
|
<RNText
|
|
214
260
|
{...setAutomationID(componentId + '|title-text')}
|
|
261
|
+
allowFontScaling={false}
|
|
215
262
|
numberOfLines={numberOfLines}
|
|
216
|
-
style={[styleSheet[typography], styles.title]}
|
|
263
|
+
style={[styleSheet[typography], styles.title]}
|
|
264
|
+
>
|
|
217
265
|
{title}
|
|
218
266
|
</RNText>
|
|
219
267
|
</View>
|
|
@@ -223,7 +271,8 @@ const Title: FC<TitleProps> = ({
|
|
|
223
271
|
return (
|
|
224
272
|
<View
|
|
225
273
|
style={[style, styles.wrapper, isSection && styles.margin]}
|
|
226
|
-
accessibilityLabel={componentId}
|
|
274
|
+
accessibilityLabel={componentId}
|
|
275
|
+
>
|
|
227
276
|
{renderIcon()}
|
|
228
277
|
{renderContent()}
|
|
229
278
|
{renderActionRight()}
|
|
@@ -231,5 +280,5 @@ const Title: FC<TitleProps> = ({
|
|
|
231
280
|
);
|
|
232
281
|
};
|
|
233
282
|
|
|
234
|
-
export {Title};
|
|
235
|
-
export type {TitleProps};
|
|
283
|
+
export { Title };
|
|
284
|
+
export type { TitleProps };
|
package/package.json
CHANGED
package/styles.ts
CHANGED
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
import {StyleSheet} from 'react-native';
|
|
2
|
-
import {Colors, Radius,
|
|
2
|
+
import {Colors, Radius, Spacing} from '@momo-kits/foundation';
|
|
3
3
|
|
|
4
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
5
|
actionIcon: {
|
|
30
6
|
borderRadius: Radius.M,
|
|
31
7
|
alignItems: 'center',
|