@momo-kits/avatar 0.0.48-rc.4 → 0.0.48
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 +119 -0
- package/package.json +16 -15
- package/publish.sh +17 -23
- package/styles.ts +18 -0
- package/types.ts +52 -0
- package/Avatar.js +0 -699
- package/Avatar.web.js +0 -588
- package/index.js +0 -3
package/index.tsx
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import React, {FC, useContext} from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {AvatarProps} from './types';
|
|
4
|
+
import {
|
|
5
|
+
ApplicationContext,
|
|
6
|
+
Colors,
|
|
7
|
+
Icon,
|
|
8
|
+
Image,
|
|
9
|
+
scaleSize,
|
|
10
|
+
Spacing,
|
|
11
|
+
Text,
|
|
12
|
+
} from '@momo-kits/foundation';
|
|
13
|
+
import styles from './styles';
|
|
14
|
+
|
|
15
|
+
const logo = 'https://static.momocdn.net/app/img/kits/logo_momo_circle.png';
|
|
16
|
+
const iconSupportDefault =
|
|
17
|
+
'https://static.momocdn.net/app/img/kits/_indicator.png';
|
|
18
|
+
|
|
19
|
+
const Avatar: FC<AvatarProps> = ({
|
|
20
|
+
size = 32,
|
|
21
|
+
name,
|
|
22
|
+
rounded = true,
|
|
23
|
+
showIconMomo = false,
|
|
24
|
+
showIconSupport = false,
|
|
25
|
+
iconSupport = iconSupportDefault,
|
|
26
|
+
image,
|
|
27
|
+
}) => {
|
|
28
|
+
const {theme} = useContext(ApplicationContext);
|
|
29
|
+
const borderRadius = rounded ? size / 2 : Spacing.XS;
|
|
30
|
+
|
|
31
|
+
const getShortName = (name: string) => {
|
|
32
|
+
const words = name.split(' ');
|
|
33
|
+
const lastTwoWords = words.slice(-2);
|
|
34
|
+
return lastTwoWords.map(word => word.charAt(0).toUpperCase()).join('');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getIconSize = () => {
|
|
38
|
+
switch (size) {
|
|
39
|
+
case 24: {
|
|
40
|
+
return 16;
|
|
41
|
+
}
|
|
42
|
+
case 32: {
|
|
43
|
+
return 16;
|
|
44
|
+
}
|
|
45
|
+
case 40: {
|
|
46
|
+
return 24;
|
|
47
|
+
}
|
|
48
|
+
case 48: {
|
|
49
|
+
return 32;
|
|
50
|
+
}
|
|
51
|
+
case 56: {
|
|
52
|
+
return 32;
|
|
53
|
+
}
|
|
54
|
+
case 72: {
|
|
55
|
+
return 40;
|
|
56
|
+
}
|
|
57
|
+
default: {
|
|
58
|
+
return 16;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const iconSize = getIconSize();
|
|
64
|
+
const shouldShowIconTop = showIconMomo && rounded;
|
|
65
|
+
const shouldShowIconBottom = showIconSupport && rounded;
|
|
66
|
+
const supportIconSize = {
|
|
67
|
+
width: getIconSize() / 2,
|
|
68
|
+
height: getIconSize() / 2,
|
|
69
|
+
borderRadius: getIconSize() / 4,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<View
|
|
74
|
+
style={[
|
|
75
|
+
styles.container,
|
|
76
|
+
{
|
|
77
|
+
width: scaleSize(size),
|
|
78
|
+
height: scaleSize(size),
|
|
79
|
+
backgroundColor: Colors.pink_09,
|
|
80
|
+
borderColor: theme.colors.border.default,
|
|
81
|
+
borderRadius: scaleSize(borderRadius),
|
|
82
|
+
},
|
|
83
|
+
]}>
|
|
84
|
+
{!!name && !image && (
|
|
85
|
+
<Text color={Colors.pink_03} typography={'description_xs_regular'}>
|
|
86
|
+
{getShortName(name)}
|
|
87
|
+
</Text>
|
|
88
|
+
)}
|
|
89
|
+
{!name && !image && (
|
|
90
|
+
<Icon size={iconSize} source={'basic_person'} color={Colors.pink_03} />
|
|
91
|
+
)}
|
|
92
|
+
{!!image && (
|
|
93
|
+
<Image
|
|
94
|
+
source={{uri: image}}
|
|
95
|
+
style={[
|
|
96
|
+
styles.image,
|
|
97
|
+
{
|
|
98
|
+
borderRadius,
|
|
99
|
+
},
|
|
100
|
+
]}
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
{shouldShowIconTop && (
|
|
104
|
+
<Image
|
|
105
|
+
source={{uri: logo}}
|
|
106
|
+
style={[styles.icon, supportIconSize, {top: -1, right: -1}]}
|
|
107
|
+
/>
|
|
108
|
+
)}
|
|
109
|
+
{shouldShowIconBottom && (
|
|
110
|
+
<Image
|
|
111
|
+
source={{uri: iconSupport}}
|
|
112
|
+
style={[styles.icon, supportIconSize, {bottom: -1, right: -1}]}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
</View>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export {Avatar};
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
2
|
+
"name": "@momo-kits/avatar",
|
|
3
|
+
"version": "0.0.48",
|
|
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
|
+
"@momo-platform/versions": "4.1.11"
|
|
14
|
+
},
|
|
15
|
+
"license": "MoMo",
|
|
16
|
+
"dependencies": {}
|
|
17
|
+
}
|
package/publish.sh
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
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' --exclude 'web.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" == "beta" ]; then # Publish beta
|
|
10
|
+
npm version $(npm view @momo-kits/avatar@beta version)
|
|
11
|
+
npm version prepatch --preid=beta
|
|
12
|
+
npm publish --tag beta --access=public
|
|
13
|
+
else # Publish latest
|
|
14
|
+
npm version $(npm view @momo-kits/avatar version)
|
|
15
|
+
npm version patch
|
|
16
|
+
npm publish --tag latest --access=public
|
|
17
|
+
fi
|
|
18
|
+
PACKAGE_NAME=$(npm pkg get name)
|
|
19
|
+
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
20
|
+
|
|
21
|
+
# Clean up
|
|
25
22
|
cd ..
|
|
26
23
|
rm -rf dist
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#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/avatar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/avatar"}'
|
package/styles.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
|
|
3
|
+
export default StyleSheet.create({
|
|
4
|
+
icon: {
|
|
5
|
+
position: 'absolute',
|
|
6
|
+
overflow: 'hidden',
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
container: {
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
borderWidth: 1,
|
|
13
|
+
},
|
|
14
|
+
image: {
|
|
15
|
+
width: '100%',
|
|
16
|
+
height: '100%',
|
|
17
|
+
},
|
|
18
|
+
});
|
package/types.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predefined set of sizes for the avatar. The numbers represent pixel values.
|
|
3
|
+
*/
|
|
4
|
+
type AvatarSize = 24 | 32 | 40 | 48 | 56 | 72;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for the Avatar component, which displays an image or icon representing a user.
|
|
8
|
+
*/
|
|
9
|
+
export type AvatarProps = {
|
|
10
|
+
/**
|
|
11
|
+
* Optional. Specifies the size of the avatar from a set of predefined sizes.
|
|
12
|
+
* If not provided, the component may use a default size.
|
|
13
|
+
*/
|
|
14
|
+
size?: AvatarSize;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Optional. If `true`, the avatar will have rounded corners, providing a circular appearance.
|
|
18
|
+
* Defaults to `false` if not provided, resulting in a square or rectangular avatar.
|
|
19
|
+
*/
|
|
20
|
+
rounded?: boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Optional. If `true`, an icon representing "Momo" will be displayed.
|
|
24
|
+
* This is specific to the use-case where the application requires a Momo icon.
|
|
25
|
+
* Defaults to `false` if not provided.
|
|
26
|
+
*/
|
|
27
|
+
showIconMomo?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Optional. If `true`, a support icon will be displayed, suggesting this avatar is for support or helpdesk representation.
|
|
31
|
+
* Defaults to `false` if not provided.
|
|
32
|
+
*/
|
|
33
|
+
showIconSupport?: boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Optional. Specifies the icon for support. This is used in conjunction with `showIconSupport`.
|
|
37
|
+
* If `showIconSupport` is `true` but no `iconSupport` is provided, a default icon may be used.
|
|
38
|
+
*/
|
|
39
|
+
iconSupport?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Optional. The name associated with the avatar. This could be the user’s full name,
|
|
43
|
+
* first name, or a username, depending on the implementation.
|
|
44
|
+
*/
|
|
45
|
+
name?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Optional. The URL or local path of the image to be displayed as the avatar.
|
|
49
|
+
* If not provided, a placeholder or default avatar may be displayed.
|
|
50
|
+
*/
|
|
51
|
+
image?: string;
|
|
52
|
+
};
|