@momo-kits/collapse 0.81.7 → 0.81.8
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 +62 -4
- package/package.json +1 -1
- package/styles.ts +11 -1
- package/types.ts +2 -0
package/index.tsx
CHANGED
|
@@ -6,15 +6,17 @@ import {
|
|
|
6
6
|
TouchableOpacity,
|
|
7
7
|
UIManager,
|
|
8
8
|
View,
|
|
9
|
+
Text as RNText,
|
|
9
10
|
} from 'react-native';
|
|
10
11
|
import {
|
|
11
12
|
ApplicationContext,
|
|
12
13
|
Icon,
|
|
13
14
|
Image,
|
|
15
|
+
scaleSize,
|
|
14
16
|
Tag,
|
|
15
17
|
Text,
|
|
16
18
|
} from '@momo-kits/foundation';
|
|
17
|
-
import {
|
|
19
|
+
import {CollapseImageSize, CollapseProps} from './types';
|
|
18
20
|
import styles from './styles';
|
|
19
21
|
|
|
20
22
|
if (Platform.OS === 'android') {
|
|
@@ -35,6 +37,8 @@ const Collapse: FC<CollapseProps> = ({
|
|
|
35
37
|
tagProps,
|
|
36
38
|
scrollEnabled = false,
|
|
37
39
|
scrollContentMaxHeight = 240,
|
|
40
|
+
titleSize = 'medium',
|
|
41
|
+
useBackgroundCollapseButton = false,
|
|
38
42
|
}) => {
|
|
39
43
|
const {theme} = useContext(ApplicationContext);
|
|
40
44
|
const [expanded, setExpanded] = useState(false);
|
|
@@ -45,6 +49,35 @@ const Collapse: FC<CollapseProps> = ({
|
|
|
45
49
|
const radiusStyle = {borderBottomLeftRadius: 0, borderBottomRightRadius: 0};
|
|
46
50
|
const borderWidth = showBorder ? 1 : 0;
|
|
47
51
|
|
|
52
|
+
const getTitleTypo = () => {
|
|
53
|
+
switch (titleSize) {
|
|
54
|
+
case 'small': {
|
|
55
|
+
return {
|
|
56
|
+
fontSize: scaleSize(14),
|
|
57
|
+
lineHeight: scaleSize(20),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
case 'medium': {
|
|
61
|
+
return {
|
|
62
|
+
fontSize: scaleSize(16),
|
|
63
|
+
lineHeight: scaleSize(22),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
case 'large': {
|
|
67
|
+
return {
|
|
68
|
+
fontSize: scaleSize(18),
|
|
69
|
+
lineHeight: scaleSize(26),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
default: {
|
|
73
|
+
return {
|
|
74
|
+
fontSize: scaleSize(14),
|
|
75
|
+
lineHeight: scaleSize(20),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
48
81
|
const renderInfo = () => {
|
|
49
82
|
if (subTitle) {
|
|
50
83
|
return (
|
|
@@ -75,6 +108,23 @@ const Collapse: FC<CollapseProps> = ({
|
|
|
75
108
|
setExpanded(!expanded);
|
|
76
109
|
};
|
|
77
110
|
|
|
111
|
+
const renderCollapseIcon = () => {
|
|
112
|
+
if (useBackgroundCollapseButton) {
|
|
113
|
+
return (
|
|
114
|
+
<View
|
|
115
|
+
style={[
|
|
116
|
+
styles.iconWrapper,
|
|
117
|
+
{
|
|
118
|
+
backgroundColor: theme.colors.background.tonal,
|
|
119
|
+
},
|
|
120
|
+
]}>
|
|
121
|
+
<Icon color={theme.colors.primary} source={iconSource} />
|
|
122
|
+
</View>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return <Icon source={iconSource} style={styles.icon} />;
|
|
126
|
+
};
|
|
127
|
+
|
|
78
128
|
const renderHeader = () => {
|
|
79
129
|
return (
|
|
80
130
|
<TouchableOpacity
|
|
@@ -97,9 +147,17 @@ const Collapse: FC<CollapseProps> = ({
|
|
|
97
147
|
)}
|
|
98
148
|
<View style={styles.headerContent}>
|
|
99
149
|
<View style={styles.flex2}>
|
|
100
|
-
<
|
|
150
|
+
<RNText
|
|
151
|
+
numberOfLines={1}
|
|
152
|
+
style={[
|
|
153
|
+
getTitleTypo(),
|
|
154
|
+
{
|
|
155
|
+
fontFamily: `${theme.font}-Semibold`,
|
|
156
|
+
color: theme.colors.text.default,
|
|
157
|
+
},
|
|
158
|
+
]}>
|
|
101
159
|
{title}
|
|
102
|
-
</
|
|
160
|
+
</RNText>
|
|
103
161
|
{!!description && (
|
|
104
162
|
<Text numberOfLines={2} typography={'description_default'}>
|
|
105
163
|
{description}
|
|
@@ -108,7 +166,7 @@ const Collapse: FC<CollapseProps> = ({
|
|
|
108
166
|
</View>
|
|
109
167
|
<View style={styles.infoWrap}>{renderInfo()}</View>
|
|
110
168
|
</View>
|
|
111
|
-
|
|
169
|
+
{renderCollapseIcon()}
|
|
112
170
|
</TouchableOpacity>
|
|
113
171
|
);
|
|
114
172
|
};
|
package/package.json
CHANGED
package/styles.ts
CHANGED
|
@@ -19,5 +19,15 @@ export default StyleSheet.create({
|
|
|
19
19
|
},
|
|
20
20
|
infoWrap: {maxWidth: 200, alignItems: 'flex-end', marginLeft: Spacing.S},
|
|
21
21
|
flex2: {flex: 2},
|
|
22
|
-
|
|
22
|
+
iconWrapper: {
|
|
23
|
+
width: 24,
|
|
24
|
+
height: 24,
|
|
25
|
+
borderRadius: Radius.M,
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
marginLeft: Spacing.S,
|
|
29
|
+
},
|
|
30
|
+
icon: {
|
|
31
|
+
marginLeft: Spacing.S,
|
|
32
|
+
},
|
|
23
33
|
});
|