@momo-kits/uploader 0.77.5-beta.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 +86 -0
- package/package.json +15 -0
- package/publish.sh +28 -0
- package/styles.ts +30 -0
- package/types.ts +69 -0
package/index.tsx
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, {FC, useContext} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ActivityIndicator,
|
|
4
|
+
ScrollView,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
View,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import {UploaderProps, UploadImage} from './types';
|
|
9
|
+
import {ApplicationContext, Icon, Image, Text} from '@momo-kits/foundation';
|
|
10
|
+
import styles from './styles';
|
|
11
|
+
|
|
12
|
+
const Uploader: FC<UploaderProps> = ({
|
|
13
|
+
images = [],
|
|
14
|
+
onAdd,
|
|
15
|
+
onCancel,
|
|
16
|
+
onPressImage,
|
|
17
|
+
numberOfImages = 1,
|
|
18
|
+
disabled,
|
|
19
|
+
width = 64,
|
|
20
|
+
height = 64,
|
|
21
|
+
}) => {
|
|
22
|
+
const {theme} = useContext(ApplicationContext);
|
|
23
|
+
const renderPicker = () => {
|
|
24
|
+
let mainColor = theme.colors.text.hint;
|
|
25
|
+
let borderColor = theme.colors.border.default;
|
|
26
|
+
|
|
27
|
+
if (disabled) {
|
|
28
|
+
mainColor = theme.colors.text.disable;
|
|
29
|
+
borderColor = theme.colors.border.disable;
|
|
30
|
+
}
|
|
31
|
+
return (
|
|
32
|
+
<TouchableOpacity
|
|
33
|
+
onPress={onAdd}
|
|
34
|
+
disabled={disabled}
|
|
35
|
+
style={[styles.picker, {borderColor, width, height}]}>
|
|
36
|
+
<Icon source={'16_navigation_plus'} color={mainColor} />
|
|
37
|
+
<Text typography={'description_xs'} color={mainColor}>
|
|
38
|
+
Thêm hình
|
|
39
|
+
</Text>
|
|
40
|
+
</TouchableOpacity>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const renderLoadingLayer = () => {
|
|
45
|
+
return (
|
|
46
|
+
<View style={styles.loading}>
|
|
47
|
+
<ActivityIndicator color={theme.colors.primary} />
|
|
48
|
+
</View>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
const renderImageItem = (image: UploadImage, index: number) => {
|
|
52
|
+
const {uri, loading} = image;
|
|
53
|
+
return (
|
|
54
|
+
<TouchableOpacity
|
|
55
|
+
onPress={() => onPressImage?.(image, index)}
|
|
56
|
+
style={styles.imageWrapper}>
|
|
57
|
+
<Image source={{uri}} style={[styles.image, {width, height}]} />
|
|
58
|
+
{onCancel && !loading && (
|
|
59
|
+
<TouchableOpacity
|
|
60
|
+
onPress={() => onCancel(image, index)}
|
|
61
|
+
style={styles.cancelIcon}>
|
|
62
|
+
<Icon size={16} source={'navigation_close_circle_full'} />
|
|
63
|
+
</TouchableOpacity>
|
|
64
|
+
)}
|
|
65
|
+
{loading && renderLoadingLayer()}
|
|
66
|
+
</TouchableOpacity>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const shouldShowPicker = images.length < numberOfImages;
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<View style={styles.uploader}>
|
|
74
|
+
{shouldShowPicker && renderPicker()}
|
|
75
|
+
<ScrollView showsHorizontalScrollIndicator={false} horizontal>
|
|
76
|
+
{images?.map((image, index) => {
|
|
77
|
+
return renderImageItem(image, index);
|
|
78
|
+
})}
|
|
79
|
+
</ScrollView>
|
|
80
|
+
</View>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default Uploader;
|
|
85
|
+
|
|
86
|
+
export type {UploadImage};
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momo-kits/uploader",
|
|
3
|
+
"version": "0.77.5-beta.01",
|
|
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/bank new version release: '*"$VERSION"*' `https://www.npmjs.com/package/@momo-kits/avatar`"}'
|
package/styles.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
import {Radius, Spacing} from '@momo-kits/foundation';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
picker: {
|
|
6
|
+
borderWidth: 1,
|
|
7
|
+
alignItems: 'center',
|
|
8
|
+
justifyContent: 'center',
|
|
9
|
+
borderRadius: Radius.XS,
|
|
10
|
+
borderStyle: 'dashed',
|
|
11
|
+
},
|
|
12
|
+
image: {
|
|
13
|
+
borderRadius: Radius.XS,
|
|
14
|
+
},
|
|
15
|
+
uploader: {
|
|
16
|
+
flexDirection: 'row',
|
|
17
|
+
},
|
|
18
|
+
cancelIcon: {position: 'absolute', top: Spacing.XXS, right: Spacing.XXS},
|
|
19
|
+
imageWrapper: {marginLeft: Spacing.S},
|
|
20
|
+
loading: {
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
top: 0,
|
|
23
|
+
bottom: 0,
|
|
24
|
+
left: 0,
|
|
25
|
+
right: 0,
|
|
26
|
+
backgroundColor: 'rgba(255,255,255,0.4)',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
justifyContent: 'center',
|
|
29
|
+
},
|
|
30
|
+
});
|
package/types.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an individual image being uploaded, containing details about its source and loading state.
|
|
3
|
+
*/
|
|
4
|
+
export type UploadImage = {
|
|
5
|
+
/**
|
|
6
|
+
* Optional. The URI (Uniform Resource Identifier) pointing to the image's location. This can be a web URL,
|
|
7
|
+
* local file path, or any other valid image source identifier.
|
|
8
|
+
*/
|
|
9
|
+
uri?: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Optional. Indicates whether the image is currently being uploaded.
|
|
13
|
+
* If `true`, the image is in the process of being uploaded. Defaults to `false` if not provided.
|
|
14
|
+
*/
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Properties for the Uploader component, designed for handling multiple image uploads.
|
|
20
|
+
*/
|
|
21
|
+
export type UploaderProps = {
|
|
22
|
+
/**
|
|
23
|
+
* An array of `UploadImage` objects, each representing an image to be uploaded.
|
|
24
|
+
*/
|
|
25
|
+
images: UploadImage[];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Optional. Specifies the maximum number of images that can be uploaded.
|
|
29
|
+
* If not provided, there is no limit by default.
|
|
30
|
+
*/
|
|
31
|
+
numberOfImages?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Optional. If `true`, uploading new images is disabled, and any associated upload controls are not interactive.
|
|
35
|
+
* Defaults to `false` if not provided.
|
|
36
|
+
*/
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Optional. A callback function that is called when the user initiates the addition of a new image.
|
|
41
|
+
* Typically used to trigger the file selection dialog.
|
|
42
|
+
*/
|
|
43
|
+
onAdd?: () => void;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Optional. A callback function invoked when the user cancels an ongoing upload.
|
|
47
|
+
* Receives the `UploadImage` object being canceled and its index in the images array as parameters.
|
|
48
|
+
*/
|
|
49
|
+
onCancel?: (image: UploadImage, index: number) => void;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Optional. A callback function invoked when the user clicks or taps on an uploaded image.
|
|
53
|
+
* This can be used to open a preview overlay, for example.
|
|
54
|
+
* Receives the `UploadImage` object being interacted with and its index in the images array as parameters.
|
|
55
|
+
*/
|
|
56
|
+
onPressImage?: (image: UploadImage, index: number) => void;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Optional. Specifies the width of the Uploader component's bounding box,
|
|
60
|
+
* typically in pixels (px). If not provided, the width will adapt based on container or content.
|
|
61
|
+
*/
|
|
62
|
+
width?: number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Optional. Specifies the height of the Uploader component's bounding box,
|
|
66
|
+
* typically in pixels (px). If not provided, the height will adapt based on container or content.
|
|
67
|
+
*/
|
|
68
|
+
height?: number;
|
|
69
|
+
};
|