@momo-kits/avatar 0.77.5 → 0.77.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 +32 -8
- package/package.json +1 -1
- package/styles.ts +6 -0
- package/types.ts +42 -1
package/index.tsx
CHANGED
|
@@ -11,19 +11,21 @@ import {
|
|
|
11
11
|
import styles from './styles';
|
|
12
12
|
|
|
13
13
|
const logo = 'https://static.momocdn.net/app/img/kits/logo_momo_circle.png';
|
|
14
|
+
const iconSupportDefault =
|
|
15
|
+
'https://static.momocdn.net/app/img/kits/_indicator.png';
|
|
14
16
|
|
|
15
17
|
const Avatar: FC<AvatarProps> = ({
|
|
16
|
-
size =
|
|
18
|
+
size = 32,
|
|
17
19
|
name,
|
|
18
20
|
rounded = true,
|
|
19
|
-
showIconMomo =
|
|
20
|
-
showIconSupport =
|
|
21
|
-
|
|
21
|
+
showIconMomo = false,
|
|
22
|
+
showIconSupport = false,
|
|
23
|
+
iconSupport = iconSupportDefault,
|
|
22
24
|
image,
|
|
23
25
|
}) => {
|
|
24
26
|
const {theme} = useContext(ApplicationContext);
|
|
25
27
|
const borderRadius = rounded ? size / 2 : Spacing.XS;
|
|
26
|
-
const iconStyle = size
|
|
28
|
+
const iconStyle = size <= 32 ? styles.smallIcon : styles.icon;
|
|
27
29
|
|
|
28
30
|
const getShortName = (name: string) => {
|
|
29
31
|
const words = name.split(' ');
|
|
@@ -42,6 +44,10 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
42
44
|
position = 0;
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
if (size < 32) {
|
|
48
|
+
position = -2;
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
return position;
|
|
46
52
|
};
|
|
47
53
|
|
|
@@ -70,7 +76,8 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
70
76
|
|
|
71
77
|
const iconPosition = getIconPosition();
|
|
72
78
|
const iconSize = getIconSize();
|
|
73
|
-
const
|
|
79
|
+
const shouldShowIconTop = showIconMomo && rounded;
|
|
80
|
+
const shouldShowIconBottom = showIconSupport && rounded;
|
|
74
81
|
|
|
75
82
|
return (
|
|
76
83
|
<View
|
|
@@ -84,13 +91,13 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
84
91
|
borderRadius,
|
|
85
92
|
},
|
|
86
93
|
]}>
|
|
87
|
-
{
|
|
94
|
+
{shouldShowIconTop && (
|
|
88
95
|
<Image
|
|
89
96
|
source={{uri: logo}}
|
|
90
97
|
style={[iconStyle, {top: iconPosition, right: iconPosition}]}
|
|
91
98
|
/>
|
|
92
99
|
)}
|
|
93
|
-
{!!name && (
|
|
100
|
+
{!!name && !image && (
|
|
94
101
|
<Text color={theme.colors.primary} typography={'description_xs'}>
|
|
95
102
|
{getShortName(name)}
|
|
96
103
|
</Text>
|
|
@@ -102,6 +109,23 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
102
109
|
color={theme.colors.primary}
|
|
103
110
|
/>
|
|
104
111
|
)}
|
|
112
|
+
{!!image && (
|
|
113
|
+
<Image
|
|
114
|
+
source={{uri: image}}
|
|
115
|
+
style={[
|
|
116
|
+
styles.image,
|
|
117
|
+
{
|
|
118
|
+
borderRadius,
|
|
119
|
+
},
|
|
120
|
+
]}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
{shouldShowIconBottom && (
|
|
124
|
+
<Image
|
|
125
|
+
source={{uri: iconSupport}}
|
|
126
|
+
style={[iconStyle, {bottom: iconPosition, right: iconPosition}]}
|
|
127
|
+
/>
|
|
128
|
+
)}
|
|
105
129
|
</View>
|
|
106
130
|
);
|
|
107
131
|
};
|
package/package.json
CHANGED
package/styles.ts
CHANGED
|
@@ -6,16 +6,22 @@ export default StyleSheet.create({
|
|
|
6
6
|
height: 12,
|
|
7
7
|
borderRadius: Radius.S,
|
|
8
8
|
position: 'absolute',
|
|
9
|
+
overflow: 'hidden',
|
|
9
10
|
},
|
|
10
11
|
smallIcon: {
|
|
11
12
|
width: 8,
|
|
12
13
|
height: 8,
|
|
13
14
|
borderRadius: Radius.XS,
|
|
14
15
|
position: 'absolute',
|
|
16
|
+
overflow: 'hidden',
|
|
15
17
|
},
|
|
16
18
|
container: {
|
|
17
19
|
alignItems: 'center',
|
|
18
20
|
justifyContent: 'center',
|
|
19
21
|
borderWidth: 1,
|
|
20
22
|
},
|
|
23
|
+
image: {
|
|
24
|
+
width: '100%',
|
|
25
|
+
height: '100%',
|
|
26
|
+
},
|
|
21
27
|
});
|
package/types.ts
CHANGED
|
@@ -1,11 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predefined set of sizes for the avatar. The numbers represent pixel values.
|
|
3
|
+
*/
|
|
1
4
|
type AvatarSize = 24 | 32 | 40 | 56 | 72;
|
|
2
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Props for the Avatar component, which displays an image or icon representing a user.
|
|
8
|
+
*/
|
|
3
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
|
+
*/
|
|
4
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
|
+
*/
|
|
5
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
|
+
*/
|
|
6
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
|
+
*/
|
|
7
33
|
showIconSupport?: boolean;
|
|
8
|
-
|
|
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
|
+
*/
|
|
9
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
|
+
*/
|
|
10
51
|
image?: string;
|
|
11
52
|
};
|