@momo-kits/collapse 0.89.4 → 0.89.6-rc.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 +169 -154
- package/package.json +2 -2
- package/publish.sh +21 -22
- package/styles.ts +5 -1
- package/types.ts +10 -1
package/index.tsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {useContext, useImperativeHandle, useState} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Animated,
|
|
4
4
|
LayoutAnimation,
|
|
5
5
|
Platform,
|
|
6
|
+
Text as RNText,
|
|
6
7
|
TouchableOpacity,
|
|
7
8
|
UIManager,
|
|
8
9
|
View,
|
|
9
|
-
Text as RNText,
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
import {
|
|
12
12
|
ApplicationContext,
|
|
@@ -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,182 +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
|
-
|
|
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);
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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;
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
}
|
|
60
85
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
);
|
|
72
100
|
}
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
fontSize: scaleSize(14),
|
|
76
|
-
lineHeight: scaleSize(20),
|
|
77
|
-
};
|
|
101
|
+
if (tagProps) {
|
|
102
|
+
return <Tag {...tagProps} />;
|
|
78
103
|
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
104
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<Text numberOfLines={1} typography={'body_default_regular'}>
|
|
86
|
-
{subTitle}
|
|
87
|
-
</Text>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
if (tagProps) {
|
|
91
|
-
return <Tag {...tagProps} />;
|
|
92
|
-
}
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
93
107
|
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
const onPressHeader = () => {
|
|
109
|
+
onPress?.();
|
|
96
110
|
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
});
|
|
99
119
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
create: {
|
|
103
|
-
type: LayoutAnimation.Types.easeInEaseOut,
|
|
104
|
-
property: LayoutAnimation.Properties.opacity,
|
|
105
|
-
},
|
|
106
|
-
update: {type: LayoutAnimation.Types.easeInEaseOut},
|
|
107
|
-
});
|
|
120
|
+
setExpanded(!expanded);
|
|
121
|
+
};
|
|
108
122
|
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
};
|
|
111
139
|
|
|
112
|
-
|
|
113
|
-
if (useBackgroundCollapseButton) {
|
|
140
|
+
const renderHeader = () => {
|
|
114
141
|
return (
|
|
115
|
-
<
|
|
142
|
+
<TouchableOpacity
|
|
143
|
+
activeOpacity={1}
|
|
144
|
+
onPress={onPressHeader}
|
|
116
145
|
style={[
|
|
117
|
-
styles.
|
|
146
|
+
styles.header,
|
|
118
147
|
{
|
|
119
|
-
|
|
148
|
+
alignItems: headerAlign,
|
|
120
149
|
},
|
|
121
150
|
]}>
|
|
122
|
-
|
|
123
|
-
|
|
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>
|
|
124
182
|
);
|
|
125
|
-
}
|
|
126
|
-
return <Icon source={iconSource} style={styles.icon} />;
|
|
127
|
-
};
|
|
183
|
+
};
|
|
128
184
|
|
|
129
|
-
|
|
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
|
+
};
|
|
130
203
|
return (
|
|
131
|
-
<
|
|
132
|
-
activeOpacity={1}
|
|
133
|
-
onPress={onPressHeader}
|
|
204
|
+
<View
|
|
134
205
|
style={[
|
|
135
|
-
styles.
|
|
206
|
+
styles.root,
|
|
136
207
|
{
|
|
137
|
-
backgroundColor: theme.colors.background.surface,
|
|
138
|
-
borderColor: theme.colors.border.default,
|
|
139
208
|
borderWidth,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
{
|
|
143
|
-
alignItems: headerAlign,
|
|
144
|
-
},
|
|
145
|
-
]}>
|
|
146
|
-
{!!image && (
|
|
147
|
-
<Image
|
|
148
|
-
source={{uri: image}}
|
|
149
|
-
style={[styles.image, {width: imageSize, height: imageSize}]}
|
|
150
|
-
/>
|
|
151
|
-
)}
|
|
152
|
-
<View style={[styles.headerContent]}>
|
|
153
|
-
<View style={styles.flex2}>
|
|
154
|
-
<RNText
|
|
155
|
-
numberOfLines={1}
|
|
156
|
-
style={[
|
|
157
|
-
getTitleTypo(),
|
|
158
|
-
{
|
|
159
|
-
fontFamily: `${theme.font}-Semibold`,
|
|
160
|
-
color: theme.colors.text.default,
|
|
161
|
-
},
|
|
162
|
-
]}>
|
|
163
|
-
{title}
|
|
164
|
-
</RNText>
|
|
165
|
-
{!!description && (
|
|
166
|
-
<Text numberOfLines={2} typography={'body_default_regular'}>
|
|
167
|
-
{description}
|
|
168
|
-
</Text>
|
|
169
|
-
)}
|
|
170
|
-
</View>
|
|
171
|
-
<View style={[styles.infoWrap, {justifyContent: headerAlign}]}>
|
|
172
|
-
{renderInfo()}
|
|
173
|
-
</View>
|
|
174
|
-
</View>
|
|
175
|
-
{renderCollapseIcon()}
|
|
176
|
-
</TouchableOpacity>
|
|
177
|
-
);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const renderContent = () => {
|
|
181
|
-
return (
|
|
182
|
-
<Animated.ScrollView
|
|
183
|
-
scrollEnabled={scrollEnabled}
|
|
184
|
-
showsVerticalScrollIndicator={false}
|
|
185
|
-
style={[
|
|
186
|
-
scrollEnabled && {
|
|
187
|
-
maxHeight: scrollContentMaxHeight,
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
backgroundColor: theme.colors.background.surface,
|
|
209
|
+
borderColor,
|
|
210
|
+
backgroundColor,
|
|
191
211
|
},
|
|
192
212
|
]}>
|
|
193
|
-
{
|
|
194
|
-
|
|
213
|
+
{renderHeader()}
|
|
214
|
+
{renderContent()}
|
|
215
|
+
</View>
|
|
195
216
|
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
<View>
|
|
199
|
-
{renderHeader()}
|
|
200
|
-
{renderContent()}
|
|
201
|
-
</View>
|
|
202
|
-
);
|
|
203
|
-
};
|
|
217
|
+
}
|
|
218
|
+
);
|
|
204
219
|
|
|
205
220
|
export {Collapse};
|
|
206
221
|
export type {CollapseProps, CollapseImageSize};
|
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Prepare dist files
|
|
2
4
|
rm -rf dist
|
|
3
5
|
mkdir dist
|
|
4
|
-
|
|
5
|
-
cp . ./dist
|
|
6
|
-
|
|
7
|
-
# GET VERSION from mck_package.json
|
|
8
|
-
VERSIONSTRING=( v$(jq .version package.json) )
|
|
9
|
-
VERSION=(${VERSIONSTRING//[\"]/})
|
|
10
|
-
echo VERSION: $VERSION
|
|
11
|
-
|
|
12
|
-
rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
|
|
13
|
-
|
|
14
|
-
# #babel component to dist
|
|
15
|
-
#babel ./dist -d dist --copy-files
|
|
16
|
-
|
|
17
|
-
#copy option
|
|
18
|
-
#cp -r ./src/ dist
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#npm login
|
|
22
|
-
#publish dist to npm
|
|
6
|
+
rsync -r --exclude=/dist ./* dist
|
|
23
7
|
cd dist
|
|
24
|
-
|
|
8
|
+
|
|
9
|
+
if [ "$1" == "stable" ]; then
|
|
10
|
+
npm version $(npm view @momo-kits/foundation@stable version)
|
|
11
|
+
npm version patch
|
|
12
|
+
npm publish --tag stable --access=public
|
|
13
|
+
elif [ "$1" == "latest" ]; then
|
|
14
|
+
npm version $(npm view @momo-kits/foundation@latest version)
|
|
15
|
+
npm publish --tag latest --access=public
|
|
16
|
+
else
|
|
17
|
+
npm version $(npm view @momo-kits/collapse@beta version)
|
|
18
|
+
npm version prerelease --preid=beta
|
|
19
|
+
npm publish --tag beta --access=public
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
PACKAGE_NAME=$(npm pkg get name)
|
|
23
|
+
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
24
|
+
|
|
25
|
+
# Clean up
|
|
25
26
|
cd ..
|
|
26
27
|
rm -rf dist
|
|
27
|
-
|
|
28
|
-
##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/collapse new version release: '*"$VERSION"*' `https://www.npmjs.com/package/@momo-kits/collapse`"}'
|
package/styles.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {StyleSheet} from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import {Radius, Spacing} from '@momo-kits/foundation';
|
|
3
3
|
|
|
4
4
|
export default StyleSheet.create({
|
|
5
5
|
image: {
|
|
@@ -30,4 +30,8 @@ export default StyleSheet.create({
|
|
|
30
30
|
icon: {
|
|
31
31
|
marginLeft: Spacing.S,
|
|
32
32
|
},
|
|
33
|
+
root: {
|
|
34
|
+
borderRadius: Radius.S,
|
|
35
|
+
overflow: 'hidden',
|
|
36
|
+
},
|
|
33
37
|
});
|
package/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {TagProps} from '@momo-kits/foundation';
|
|
2
|
-
import {
|
|
2
|
+
import React, {Dispatch, SetStateAction} from 'react';
|
|
3
3
|
|
|
4
4
|
export type CollapseImageSize = 24 | 32 | 40;
|
|
5
5
|
|
|
@@ -48,4 +48,13 @@ export type CollapseProps = {
|
|
|
48
48
|
useBackgroundCollapseButton?: boolean;
|
|
49
49
|
|
|
50
50
|
headerAlign: 'flex-start' | 'flex-end' | 'center';
|
|
51
|
+
|
|
52
|
+
expandDefault?: boolean;
|
|
53
|
+
|
|
54
|
+
children?: React.ReactNode;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type CollapseHandle = {
|
|
58
|
+
setExpanded: Dispatch<SetStateAction<boolean>>;
|
|
59
|
+
expanded: boolean;
|
|
51
60
|
};
|