@momo-kits/collapse 0.77.2-beta.7

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 ADDED
@@ -0,0 +1,127 @@
1
+ import React, {FC, useContext, useRef, useState} from 'react';
2
+ import {TouchableOpacity, View, Animated, Easing} from 'react-native';
3
+ import {ApplicationContext, Icon, Image, Text} from '@momo-kits/foundation';
4
+ import {CollapseProps} from './types';
5
+ import styles from './styles';
6
+
7
+ const Collapse: FC<CollapseProps> = ({
8
+ image,
9
+ title = 'Title',
10
+ description,
11
+ onPress,
12
+ showBorder,
13
+ children,
14
+ }) => {
15
+ const {theme} = useContext(ApplicationContext);
16
+ const [expanded, setExpanded] = useState(false);
17
+ const [height, setHeight] = useState(0);
18
+
19
+ const iconSource = expanded
20
+ ? 'arrow_chevron_up_small'
21
+ : 'arrow_chevron_down_small';
22
+ const radiusStyle = {borderBottomLeftRadius: 0, borderBottomRightRadius: 0};
23
+ const borderWidth = showBorder ? 1 : 0;
24
+
25
+ const animation = useRef(new Animated.Value(0)).current;
26
+ const opacity = useRef(new Animated.Value(0)).current;
27
+ const containerHeight = animation.interpolate({
28
+ inputRange: [0, 1],
29
+ outputRange: [-height, 0],
30
+ });
31
+
32
+ const expand = () => {
33
+ Animated.parallel([
34
+ Animated.timing(animation, {
35
+ toValue: 1,
36
+ duration: 300,
37
+ easing: Easing.linear,
38
+ useNativeDriver: false,
39
+ }),
40
+ Animated.timing(opacity, {
41
+ toValue: 1,
42
+ duration: 100,
43
+ easing: Easing.linear,
44
+ useNativeDriver: false,
45
+ }),
46
+ ]).start();
47
+ };
48
+ const collapse = () => {
49
+ Animated.parallel([
50
+ Animated.timing(animation, {
51
+ toValue: 0,
52
+ duration: 300,
53
+ easing: Easing.linear,
54
+ useNativeDriver: false,
55
+ }),
56
+ Animated.timing(opacity, {
57
+ toValue: 0,
58
+ duration: 300,
59
+ easing: Easing.linear,
60
+ useNativeDriver: false,
61
+ }),
62
+ ]).start();
63
+ };
64
+
65
+ const renderHeader = () => {
66
+ const _onPress = () => {
67
+ onPress?.();
68
+ if (!expanded) {
69
+ expand();
70
+ } else {
71
+ collapse();
72
+ }
73
+ setExpanded(!expanded);
74
+ };
75
+ return (
76
+ <TouchableOpacity
77
+ activeOpacity={1}
78
+ onPress={_onPress}
79
+ style={[
80
+ styles.header,
81
+ {
82
+ backgroundColor: theme.colors.background.surface,
83
+ borderColor: theme.colors.border.default,
84
+ borderWidth,
85
+ },
86
+ expanded && radiusStyle,
87
+ ]}>
88
+ {!!image && <Image source={image} style={styles.image} />}
89
+ <View style={styles.headerContent}>
90
+ <Text numberOfLines={1} typography={'header_default'}>
91
+ {title}
92
+ </Text>
93
+ {!!description && (
94
+ <Text numberOfLines={2} typography={'description_default'}>
95
+ {description}
96
+ </Text>
97
+ )}
98
+ </View>
99
+ <Icon source={iconSource} />
100
+ </TouchableOpacity>
101
+ );
102
+ };
103
+
104
+ const renderContent = () => {
105
+ return (
106
+ <Animated.View
107
+ onLayout={e => {
108
+ setHeight(e.nativeEvent.layout.height);
109
+ }}
110
+ style={{
111
+ transform: [{translateY: containerHeight}],
112
+ zIndex: -1,
113
+ opacity,
114
+ }}>
115
+ {children}
116
+ </Animated.View>
117
+ );
118
+ };
119
+ return (
120
+ <View style={{overflow: 'hidden'}}>
121
+ {renderHeader()}
122
+ {renderContent()}
123
+ </View>
124
+ );
125
+ };
126
+
127
+ export default Collapse;
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@momo-kits/collapse",
3
+ "version": "0.77.2-beta.07",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "peerDependencies": {
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "16.9.0",
9
+ "react-native": ">=0.55",
10
+ "prop-types": "^15.7.2"
11
+ },
12
+ "devDependencies": {},
13
+ "license": "MoMo",
14
+ "dependencies": {}
15
+ }
package/publish.sh ADDED
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+ rm -rf dist
3
+ 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
23
+ cd dist
24
+ npm publish --tag beta --access=public
25
+ cd ..
26
+ 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 ADDED
@@ -0,0 +1,17 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {Spacing, Radius} from '@momo-kits/foundation';
3
+
4
+ export default StyleSheet.create({
5
+ image: {
6
+ width: 24,
7
+ height: 24,
8
+ marginRight: Spacing.S,
9
+ },
10
+ header: {
11
+ flexDirection: 'row',
12
+ paddingHorizontal: Spacing.M,
13
+ paddingVertical: Spacing.S,
14
+ borderRadius: Radius.S,
15
+ },
16
+ headerContent: {flex: 1},
17
+ });
package/types.ts ADDED
@@ -0,0 +1,8 @@
1
+ import {Source} from 'react-native-fast-image';
2
+ export type CollapseProps = {
3
+ title: string;
4
+ description?: string;
5
+ image?: number | Source;
6
+ onPress?: () => void;
7
+ showBorder?: boolean;
8
+ };