@momo-kits/avatar 0.169.3 → 0.169.5
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 +21 -16
- package/package.json +1 -1
- package/types.ts +3 -3
package/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {FC, useContext, useMemo} from 'react';
|
|
2
|
-
import {Platform, View} from 'react-native';
|
|
3
|
-
import {AvatarProps} from './types';
|
|
1
|
+
import React, { FC, useContext, useMemo } from 'react';
|
|
2
|
+
import { Platform, View } from 'react-native';
|
|
3
|
+
import { AvatarProps } from './types';
|
|
4
4
|
import {
|
|
5
5
|
ApplicationContext,
|
|
6
6
|
Colors,
|
|
@@ -13,10 +13,14 @@ import {
|
|
|
13
13
|
} from '@momo-kits/foundation';
|
|
14
14
|
import styles from './styles';
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
16
|
+
const KITS_IMG_URL = 'https://static.momocdn.net/app/img/kits';
|
|
17
|
+
const logo = `${KITS_IMG_URL}/logo_momo_circle.png`;
|
|
18
|
+
const iconSupportDefault = `${KITS_IMG_URL}/_indicator.png`;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Shows `image`, else the initials of the last two words of `name`, else a
|
|
22
|
+
* person icon. The MoMo and support badges render only when `rounded`.
|
|
23
|
+
*/
|
|
20
24
|
const Avatar: FC<AvatarProps> = ({
|
|
21
25
|
size = 32,
|
|
22
26
|
name,
|
|
@@ -35,12 +39,11 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
35
39
|
if (accessibilityLabel) {
|
|
36
40
|
return accessibilityLabel;
|
|
37
41
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}`;
|
|
42
|
+
const nameSuffix = name ? `/${name}` : '';
|
|
43
|
+
return `${app.appId}/${app.code}/${screen.screenName}/${componentName}${nameSuffix}`;
|
|
41
44
|
}, [componentName, accessibilityLabel, app, screen, name]);
|
|
42
45
|
|
|
43
|
-
const {theme} = useContext(ApplicationContext);
|
|
46
|
+
const { theme } = useContext(ApplicationContext);
|
|
44
47
|
const borderRadius = rounded ? size / 2 : Spacing.XS;
|
|
45
48
|
|
|
46
49
|
const getShortName = (fullName: string) => {
|
|
@@ -97,12 +100,14 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
97
100
|
},
|
|
98
101
|
Platform.OS === 'web' && styles.webOverflow,
|
|
99
102
|
]}
|
|
100
|
-
accessibilityLabel={componentId}
|
|
103
|
+
accessibilityLabel={componentId}
|
|
104
|
+
>
|
|
101
105
|
{!!name && !image && (
|
|
102
106
|
<Text
|
|
103
107
|
color={Colors.pink_03}
|
|
104
108
|
typography={'description_xs_regular'}
|
|
105
|
-
accessibilityLabel={componentId + '|text'}
|
|
109
|
+
accessibilityLabel={componentId + '|text'}
|
|
110
|
+
>
|
|
106
111
|
{getShortName(name)}
|
|
107
112
|
</Text>
|
|
108
113
|
)}
|
|
@@ -116,7 +121,7 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
116
121
|
)}
|
|
117
122
|
{!!image && (
|
|
118
123
|
<Image
|
|
119
|
-
source={{uri: image}}
|
|
124
|
+
source={{ uri: image }}
|
|
120
125
|
style={[
|
|
121
126
|
styles.image,
|
|
122
127
|
{
|
|
@@ -128,14 +133,14 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
128
133
|
)}
|
|
129
134
|
{shouldShowIconTop && (
|
|
130
135
|
<Image
|
|
131
|
-
source={{uri: logo}}
|
|
136
|
+
source={{ uri: logo }}
|
|
132
137
|
style={[styles.icon, supportIconSize, styles.iconTop]}
|
|
133
138
|
accessibilityLabel={componentId + '|top-icon'}
|
|
134
139
|
/>
|
|
135
140
|
)}
|
|
136
141
|
{shouldShowIconBottom && (
|
|
137
142
|
<Image
|
|
138
|
-
source={{uri: iconSupport}}
|
|
143
|
+
source={{ uri: iconSupport }}
|
|
139
144
|
style={[styles.icon, supportIconSize, styles.iconBottom]}
|
|
140
145
|
accessibilityLabel={componentId + '|bottom-icon'}
|
|
141
146
|
/>
|
|
@@ -144,4 +149,4 @@ const Avatar: FC<AvatarProps> = ({
|
|
|
144
149
|
);
|
|
145
150
|
};
|
|
146
151
|
|
|
147
|
-
export {Avatar};
|
|
152
|
+
export { Avatar };
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -9,13 +9,13 @@ type AvatarSize = 24 | 32 | 40 | 48 | 56 | 72;
|
|
|
9
9
|
export type AvatarProps = {
|
|
10
10
|
/**
|
|
11
11
|
* Optional. Specifies the size of the avatar from a set of predefined sizes.
|
|
12
|
-
*
|
|
12
|
+
* Defaults to 32.
|
|
13
13
|
*/
|
|
14
14
|
size?: AvatarSize;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Optional. If `true`, the avatar
|
|
18
|
-
* Defaults to `
|
|
17
|
+
* Optional. If `true`, the avatar is a circle; otherwise a square with small corners.
|
|
18
|
+
* Defaults to `true`.
|
|
19
19
|
*/
|
|
20
20
|
rounded?: boolean;
|
|
21
21
|
|