@momo-kits/collapse 0.74.2-react-native.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 ADDED
@@ -0,0 +1,206 @@
1
+ import React, {FC, useContext, useState} from 'react';
2
+ import {
3
+ Animated,
4
+ LayoutAnimation,
5
+ Platform,
6
+ TouchableOpacity,
7
+ UIManager,
8
+ View,
9
+ Text as RNText,
10
+ } from 'react-native';
11
+ import {
12
+ ApplicationContext,
13
+ Icon,
14
+ Image,
15
+ scaleSize,
16
+ Tag,
17
+ Text,
18
+ } from '@momo-kits/foundation';
19
+ import {CollapseImageSize, CollapseProps} from './types';
20
+ import styles from './styles';
21
+
22
+ if (Platform.OS === 'android') {
23
+ if (UIManager.setLayoutAnimationEnabledExperimental) {
24
+ UIManager.setLayoutAnimationEnabledExperimental(true);
25
+ }
26
+ }
27
+
28
+ const Collapse: FC<CollapseProps> = ({
29
+ image,
30
+ title = 'Title',
31
+ description,
32
+ onPress,
33
+ showBorder,
34
+ children,
35
+ imageSize = 24,
36
+ subTitle,
37
+ tagProps,
38
+ scrollEnabled = false,
39
+ scrollContentMaxHeight = 240,
40
+ titleSize = 'medium',
41
+ useBackgroundCollapseButton = false,
42
+ headerAlign = 'flex-start',
43
+ }) => {
44
+ const {theme} = useContext(ApplicationContext);
45
+ const [expanded, setExpanded] = useState(false);
46
+
47
+ const iconSource = expanded
48
+ ? 'arrow_chevron_up_small'
49
+ : 'arrow_chevron_down_small';
50
+ const radiusStyle = {borderBottomLeftRadius: 0, borderBottomRightRadius: 0};
51
+ const borderWidth = showBorder ? 1 : 0;
52
+
53
+ const getTitleTypo = () => {
54
+ switch (titleSize) {
55
+ case 'small': {
56
+ return {
57
+ fontSize: scaleSize(14),
58
+ lineHeight: scaleSize(20),
59
+ };
60
+ }
61
+ case 'medium': {
62
+ return {
63
+ fontSize: scaleSize(16),
64
+ lineHeight: scaleSize(22),
65
+ };
66
+ }
67
+ case 'large': {
68
+ return {
69
+ fontSize: scaleSize(18),
70
+ lineHeight: scaleSize(26),
71
+ };
72
+ }
73
+ default: {
74
+ return {
75
+ fontSize: scaleSize(14),
76
+ lineHeight: scaleSize(20),
77
+ };
78
+ }
79
+ }
80
+ };
81
+
82
+ const renderInfo = () => {
83
+ if (subTitle) {
84
+ return (
85
+ <Text numberOfLines={1} typography={'body_default_regular'}>
86
+ {subTitle}
87
+ </Text>
88
+ );
89
+ }
90
+ if (tagProps) {
91
+ return <Tag {...tagProps} />;
92
+ }
93
+
94
+ return null;
95
+ };
96
+
97
+ const onPressHeader = () => {
98
+ onPress?.();
99
+
100
+ LayoutAnimation.configureNext({
101
+ duration: 300,
102
+ create: {
103
+ type: LayoutAnimation.Types.easeInEaseOut,
104
+ property: LayoutAnimation.Properties.opacity,
105
+ },
106
+ update: {type: LayoutAnimation.Types.easeInEaseOut},
107
+ });
108
+
109
+ setExpanded(!expanded);
110
+ };
111
+
112
+ const renderCollapseIcon = () => {
113
+ if (useBackgroundCollapseButton) {
114
+ return (
115
+ <View
116
+ style={[
117
+ styles.iconWrapper,
118
+ {
119
+ backgroundColor: theme.colors.background.tonal,
120
+ },
121
+ ]}>
122
+ <Icon color={theme.colors.primary} source={iconSource} />
123
+ </View>
124
+ );
125
+ }
126
+ return <Icon source={iconSource} style={styles.icon} />;
127
+ };
128
+
129
+ const renderHeader = () => {
130
+ return (
131
+ <TouchableOpacity
132
+ activeOpacity={1}
133
+ onPress={onPressHeader}
134
+ style={[
135
+ styles.header,
136
+ {
137
+ backgroundColor: theme.colors.background.surface,
138
+ borderColor: theme.colors.border.default,
139
+ borderWidth,
140
+ },
141
+ expanded && radiusStyle,
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,
191
+ },
192
+ ]}>
193
+ {expanded && children}
194
+ </Animated.ScrollView>
195
+ );
196
+ };
197
+ return (
198
+ <View>
199
+ {renderHeader()}
200
+ {renderContent()}
201
+ </View>
202
+ );
203
+ };
204
+
205
+ export {Collapse};
206
+ export type {CollapseProps, CollapseImageSize};
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@momo-kits/collapse",
3
+ "version": "0.74.2-react-native.1",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "peerDependencies": {
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "*",
9
+ "react-native": "*",
10
+ "prop-types": "15.7.2"
11
+ },
12
+ "devDependencies": {
13
+ "@momo-platform/versions": "4.1.11"
14
+ },
15
+ "license": "MoMo",
16
+ "dependencies": {}
17
+ }
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,33 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {Spacing, Radius} from '@momo-kits/foundation';
3
+
4
+ export default StyleSheet.create({
5
+ image: {
6
+ borderRadius: Radius.XS,
7
+ marginRight: Spacing.S,
8
+ },
9
+ header: {
10
+ flexDirection: 'row',
11
+ paddingHorizontal: Spacing.M,
12
+ paddingVertical: Spacing.S,
13
+ borderRadius: Radius.S,
14
+ },
15
+ headerContent: {
16
+ flex: 1,
17
+ flexDirection: 'row',
18
+ justifyContent: 'space-between',
19
+ },
20
+ infoWrap: {maxWidth: 200, alignItems: 'flex-end', marginLeft: Spacing.S},
21
+ flex2: {flex: 2},
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
+ },
33
+ });
package/types.ts ADDED
@@ -0,0 +1,51 @@
1
+ import {TagProps} from '@momo-kits/foundation';
2
+ import {FlexAlignType} from 'react-native';
3
+
4
+ export type CollapseImageSize = 24 | 32 | 40;
5
+
6
+ export type CollapseProps = {
7
+ /**
8
+ * The title represents what is being collapsed or expanded. It is usually a summary or
9
+ * a brief heading corresponding to the detailed content that gets revealed.
10
+ */
11
+ title: string;
12
+
13
+ /**
14
+ * Optional. A more detailed explanation or continuation of the title. This text provides
15
+ * additional context or information, which is particularly useful when the collapsed content
16
+ * is not immediately visible or requires extra explanation.
17
+ */
18
+ description?: string;
19
+
20
+ /**
21
+ * Optional. The URL or local file path of an image to be displayed. This feature is often
22
+ * used to provide a visual context or decoration, enhancing user engagement or understanding
23
+ * of the information being toggled.
24
+ */
25
+ image?: string;
26
+
27
+ /**
28
+ * Optional. A callback function that is triggered when the collapse component is pressed or
29
+ * selected. This function is typically used to toggle the view state of the collapsible content.
30
+ */
31
+ onPress?: () => void;
32
+
33
+ /**
34
+ * Optional. If `true`, a border is displayed around the collapse component, visually separating
35
+ * it from other UI elements. This is particularly useful in densely packed interfaces to delineate
36
+ * between different sections.
37
+ * Defaults to `false` if not provided.
38
+ */
39
+ showBorder?: boolean;
40
+
41
+ imageSize?: CollapseImageSize;
42
+
43
+ subTitle?: string;
44
+ tagProps?: TagProps;
45
+ scrollEnabled?: boolean;
46
+ scrollContentMaxHeight?: number;
47
+ titleSize?: 'small' | 'medium' | 'large';
48
+ useBackgroundCollapseButton?: boolean;
49
+
50
+ headerAlign: 'flex-start' | 'flex-end' | 'center';
51
+ };