@momo-kits/collapse 0.92.21-beta.1 → 0.92.21-beta.2
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 +168 -158
- package/package.json +1 -1
- package/publish.sh +1 -2
- package/types.ts +6 -0
package/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {useContext, useImperativeHandle, useState} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Animated,
|
|
4
4
|
LayoutAnimation,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
Tag,
|
|
17
17
|
Text,
|
|
18
18
|
} from '@momo-kits/foundation';
|
|
19
|
-
import {CollapseImageSize, CollapseProps} from './types';
|
|
19
|
+
import {CollapseHandle, CollapseImageSize, CollapseProps} from './types';
|
|
20
20
|
import styles from './styles';
|
|
21
21
|
|
|
22
22
|
if (Platform.OS === 'android') {
|
|
@@ -25,187 +25,197 @@ if (Platform.OS === 'android') {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const Collapse
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
29
|
+
(
|
|
30
|
+
{
|
|
31
|
+
image,
|
|
32
|
+
title = 'Title',
|
|
33
|
+
description,
|
|
34
|
+
onPress,
|
|
35
|
+
showBorder,
|
|
36
|
+
children,
|
|
37
|
+
imageSize = 24,
|
|
38
|
+
subTitle,
|
|
39
|
+
tagProps,
|
|
40
|
+
scrollEnabled = false,
|
|
41
|
+
scrollContentMaxHeight = 240,
|
|
42
|
+
titleSize = 'medium',
|
|
43
|
+
useBackgroundCollapseButton = false,
|
|
44
|
+
headerAlign = 'flex-start',
|
|
45
|
+
expandDefault = false,
|
|
46
|
+
},
|
|
47
|
+
ref
|
|
48
|
+
) => {
|
|
49
|
+
const {theme} = useContext(ApplicationContext);
|
|
50
|
+
const [expanded, setExpanded] = useState(expandDefault);
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const iconSource = expanded
|
|
53
|
+
? 'arrow_chevron_up_small'
|
|
54
|
+
: 'arrow_chevron_down_small';
|
|
55
|
+
const borderWidth = showBorder ? 1 : 0;
|
|
56
|
+
const borderColor = theme.colors.border.default;
|
|
57
|
+
const backgroundColor = theme.colors.background.surface;
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const getTitleTypo = () => {
|
|
60
|
+
switch (titleSize) {
|
|
61
|
+
case 'small': {
|
|
62
|
+
return {
|
|
63
|
+
fontSize: scaleSize(14),
|
|
64
|
+
lineHeight: scaleSize(20),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
case 'medium': {
|
|
68
|
+
return {
|
|
69
|
+
fontSize: scaleSize(16),
|
|
70
|
+
lineHeight: scaleSize(22),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
case 'large': {
|
|
74
|
+
return {
|
|
75
|
+
fontSize: scaleSize(18),
|
|
76
|
+
lineHeight: scaleSize(26),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
default: {
|
|
80
|
+
return {
|
|
81
|
+
fontSize: scaleSize(14),
|
|
82
|
+
lineHeight: scaleSize(20),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
62
85
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
useImperativeHandle(ref, () => ({
|
|
89
|
+
setExpanded,
|
|
90
|
+
expanded,
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
const renderInfo = () => {
|
|
94
|
+
if (subTitle) {
|
|
95
|
+
return (
|
|
96
|
+
<Text numberOfLines={1} typography={'body_default_regular'}>
|
|
97
|
+
{subTitle}
|
|
98
|
+
</Text>
|
|
99
|
+
);
|
|
74
100
|
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
fontSize: scaleSize(14),
|
|
78
|
-
lineHeight: scaleSize(20),
|
|
79
|
-
};
|
|
101
|
+
if (tagProps) {
|
|
102
|
+
return <Tag {...tagProps} />;
|
|
80
103
|
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
104
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<Text numberOfLines={1} typography={'body_default_regular'}>
|
|
88
|
-
{subTitle}
|
|
89
|
-
</Text>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
if (tagProps) {
|
|
93
|
-
return <Tag {...tagProps} />;
|
|
94
|
-
}
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
95
107
|
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
const onPressHeader = () => {
|
|
109
|
+
onPress?.();
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
LayoutAnimation.configureNext({
|
|
112
|
+
duration: 300,
|
|
113
|
+
create: {
|
|
114
|
+
type: LayoutAnimation.Types.easeInEaseOut,
|
|
115
|
+
property: LayoutAnimation.Properties.opacity,
|
|
116
|
+
},
|
|
117
|
+
update: {type: LayoutAnimation.Types.easeInEaseOut},
|
|
118
|
+
});
|
|
101
119
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
create: {
|
|
105
|
-
type: LayoutAnimation.Types.easeInEaseOut,
|
|
106
|
-
property: LayoutAnimation.Properties.opacity,
|
|
107
|
-
},
|
|
108
|
-
update: {type: LayoutAnimation.Types.easeInEaseOut},
|
|
109
|
-
});
|
|
120
|
+
setExpanded(!expanded);
|
|
121
|
+
};
|
|
110
122
|
|
|
111
|
-
|
|
112
|
-
|
|
123
|
+
const renderCollapseIcon = () => {
|
|
124
|
+
if (useBackgroundCollapseButton) {
|
|
125
|
+
return (
|
|
126
|
+
<View
|
|
127
|
+
style={[
|
|
128
|
+
styles.iconWrapper,
|
|
129
|
+
{
|
|
130
|
+
backgroundColor: theme.colors.background.tonal,
|
|
131
|
+
},
|
|
132
|
+
]}>
|
|
133
|
+
<Icon color={theme.colors.primary} source={iconSource} />
|
|
134
|
+
</View>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return <Icon source={iconSource} style={styles.icon} />;
|
|
138
|
+
};
|
|
113
139
|
|
|
114
|
-
|
|
115
|
-
if (useBackgroundCollapseButton) {
|
|
140
|
+
const renderHeader = () => {
|
|
116
141
|
return (
|
|
117
|
-
<
|
|
142
|
+
<TouchableOpacity
|
|
143
|
+
activeOpacity={1}
|
|
144
|
+
onPress={onPressHeader}
|
|
118
145
|
style={[
|
|
119
|
-
styles.
|
|
146
|
+
styles.header,
|
|
120
147
|
{
|
|
121
|
-
|
|
148
|
+
alignItems: headerAlign,
|
|
122
149
|
},
|
|
123
150
|
]}>
|
|
124
|
-
|
|
125
|
-
|
|
151
|
+
{!!image && (
|
|
152
|
+
<Image
|
|
153
|
+
source={{uri: image}}
|
|
154
|
+
style={[styles.image, {width: imageSize, height: imageSize}]}
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
<View style={[styles.headerContent]}>
|
|
158
|
+
<View style={styles.flex2}>
|
|
159
|
+
<RNText
|
|
160
|
+
numberOfLines={1}
|
|
161
|
+
style={[
|
|
162
|
+
getTitleTypo(),
|
|
163
|
+
{
|
|
164
|
+
fontFamily: `${theme.font}-Semibold`,
|
|
165
|
+
color: theme.colors.text.default,
|
|
166
|
+
},
|
|
167
|
+
]}>
|
|
168
|
+
{title}
|
|
169
|
+
</RNText>
|
|
170
|
+
{!!description && (
|
|
171
|
+
<Text numberOfLines={2} typography={'body_default_regular'}>
|
|
172
|
+
{description}
|
|
173
|
+
</Text>
|
|
174
|
+
)}
|
|
175
|
+
</View>
|
|
176
|
+
<View style={[styles.infoWrap, {justifyContent: headerAlign}]}>
|
|
177
|
+
{renderInfo()}
|
|
178
|
+
</View>
|
|
179
|
+
</View>
|
|
180
|
+
{renderCollapseIcon()}
|
|
181
|
+
</TouchableOpacity>
|
|
126
182
|
);
|
|
127
|
-
}
|
|
128
|
-
return <Icon source={iconSource} style={styles.icon} />;
|
|
129
|
-
};
|
|
183
|
+
};
|
|
130
184
|
|
|
131
|
-
|
|
185
|
+
const renderContent = () => {
|
|
186
|
+
return (
|
|
187
|
+
<Animated.ScrollView
|
|
188
|
+
scrollEnabled={scrollEnabled}
|
|
189
|
+
showsVerticalScrollIndicator={false}
|
|
190
|
+
style={[
|
|
191
|
+
scrollEnabled && {
|
|
192
|
+
maxHeight: scrollContentMaxHeight,
|
|
193
|
+
},
|
|
194
|
+
expanded && {
|
|
195
|
+
borderTopWidth: borderWidth,
|
|
196
|
+
borderColor,
|
|
197
|
+
},
|
|
198
|
+
]}>
|
|
199
|
+
{expanded && children}
|
|
200
|
+
</Animated.ScrollView>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
132
203
|
return (
|
|
133
|
-
<
|
|
134
|
-
activeOpacity={1}
|
|
135
|
-
onPress={onPressHeader}
|
|
204
|
+
<View
|
|
136
205
|
style={[
|
|
137
|
-
styles.
|
|
206
|
+
styles.root,
|
|
138
207
|
{
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
]}>
|
|
142
|
-
{!!image && (
|
|
143
|
-
<Image
|
|
144
|
-
source={{uri: image}}
|
|
145
|
-
style={[styles.image, {width: imageSize, height: imageSize}]}
|
|
146
|
-
/>
|
|
147
|
-
)}
|
|
148
|
-
<View style={[styles.headerContent]}>
|
|
149
|
-
<View style={styles.flex2}>
|
|
150
|
-
<RNText
|
|
151
|
-
numberOfLines={1}
|
|
152
|
-
style={[
|
|
153
|
-
getTitleTypo(),
|
|
154
|
-
{
|
|
155
|
-
fontFamily: `${theme.font}-Semibold`,
|
|
156
|
-
color: theme.colors.text.default,
|
|
157
|
-
},
|
|
158
|
-
]}>
|
|
159
|
-
{title}
|
|
160
|
-
</RNText>
|
|
161
|
-
{!!description && (
|
|
162
|
-
<Text numberOfLines={2} typography={'body_default_regular'}>
|
|
163
|
-
{description}
|
|
164
|
-
</Text>
|
|
165
|
-
)}
|
|
166
|
-
</View>
|
|
167
|
-
<View style={[styles.infoWrap, {justifyContent: headerAlign}]}>
|
|
168
|
-
{renderInfo()}
|
|
169
|
-
</View>
|
|
170
|
-
</View>
|
|
171
|
-
{renderCollapseIcon()}
|
|
172
|
-
</TouchableOpacity>
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const renderContent = () => {
|
|
177
|
-
return (
|
|
178
|
-
<Animated.ScrollView
|
|
179
|
-
scrollEnabled={scrollEnabled}
|
|
180
|
-
showsVerticalScrollIndicator={false}
|
|
181
|
-
style={[
|
|
182
|
-
scrollEnabled && {
|
|
183
|
-
maxHeight: scrollContentMaxHeight,
|
|
184
|
-
},
|
|
185
|
-
expanded && {
|
|
186
|
-
borderTopWidth: borderWidth,
|
|
208
|
+
borderWidth,
|
|
187
209
|
borderColor,
|
|
210
|
+
backgroundColor,
|
|
188
211
|
},
|
|
189
212
|
]}>
|
|
190
|
-
{
|
|
191
|
-
|
|
213
|
+
{renderHeader()}
|
|
214
|
+
{renderContent()}
|
|
215
|
+
</View>
|
|
192
216
|
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
<View
|
|
196
|
-
style={[
|
|
197
|
-
styles.root,
|
|
198
|
-
{
|
|
199
|
-
borderWidth,
|
|
200
|
-
borderColor,
|
|
201
|
-
backgroundColor,
|
|
202
|
-
},
|
|
203
|
-
]}>
|
|
204
|
-
{renderHeader()}
|
|
205
|
-
{renderContent()}
|
|
206
|
-
</View>
|
|
207
|
-
);
|
|
208
|
-
};
|
|
217
|
+
}
|
|
218
|
+
);
|
|
209
219
|
|
|
210
220
|
export {Collapse};
|
|
211
221
|
export type {CollapseProps, CollapseImageSize};
|
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -11,8 +11,7 @@ if [ "$1" == "stable" ]; then
|
|
|
11
11
|
npm version patch
|
|
12
12
|
npm publish --tag stable --access=public
|
|
13
13
|
elif [ "$1" == "latest" ]; then
|
|
14
|
-
npm version $
|
|
15
|
-
npm version prerelease --preid=rc
|
|
14
|
+
npm version $NEW_PACKAGE_VERSION
|
|
16
15
|
npm publish --tag latest --access=public
|
|
17
16
|
else
|
|
18
17
|
npm version $(npm view @momo-kits/collapse@beta version)
|
package/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {TagProps} from '@momo-kits/foundation';
|
|
2
|
+
import {Dispatch, SetStateAction} from 'react';
|
|
2
3
|
|
|
3
4
|
export type CollapseImageSize = 24 | 32 | 40;
|
|
4
5
|
|
|
@@ -50,3 +51,8 @@ export type CollapseProps = {
|
|
|
50
51
|
|
|
51
52
|
expandDefault?: boolean;
|
|
52
53
|
};
|
|
54
|
+
|
|
55
|
+
export type CollapseHandle = {
|
|
56
|
+
setExpanded: Dispatch<SetStateAction<boolean>>;
|
|
57
|
+
expanded: boolean;
|
|
58
|
+
};
|