@momo-kits/avatar 0.112.1-beta.2 → 0.112.1-beta.20

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.
Files changed (3) hide show
  1. package/index.tsx +30 -12
  2. package/package.json +18 -18
  3. package/types.ts +0 -25
package/index.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, {FC, useContext} from 'react';
1
+ import React, {FC, useContext, useMemo} from 'react';
2
2
  import {View} from 'react-native';
3
3
  import {AvatarProps} from './types';
4
4
  import {
@@ -6,6 +6,8 @@ import {
6
6
  Colors,
7
7
  Icon,
8
8
  Image,
9
+ MiniAppContext,
10
+ ScreenContext,
9
11
  Spacing,
10
12
  Text,
11
13
  } from '@momo-kits/foundation';
@@ -24,12 +26,20 @@ const Avatar: FC<AvatarProps> = ({
24
26
  iconSupport = iconSupportDefault,
25
27
  image,
26
28
  accessibilityLabel,
27
- accessibilityLabelBottomIcon,
28
- accessibilityLabelTopIcon,
29
- accessibilityLabelDescription,
30
- accessibilityLabelIcon,
31
- accessibilityLabelImage
32
29
  }) => {
30
+ const app = useContext<any>(MiniAppContext);
31
+ const screen = useContext<any>(ScreenContext);
32
+ const componentName = 'Avatar';
33
+
34
+ const componentId = useMemo(() => {
35
+ if (accessibilityLabel) {
36
+ return accessibilityLabel;
37
+ }
38
+ return `${app.appId}/${app.code}/${screen.screenName}/${componentName}${
39
+ name ? `/${name}` : ''
40
+ }`;
41
+ }, [componentName, accessibilityLabel, app, screen]);
42
+
33
43
  const {theme} = useContext(ApplicationContext);
34
44
  const borderRadius = rounded ? size / 2 : Spacing.XS;
35
45
 
@@ -86,18 +96,25 @@ const Avatar: FC<AvatarProps> = ({
86
96
  borderRadius: borderRadius,
87
97
  },
88
98
  ]}
89
- accessibilityLabel={accessibilityLabel}>
99
+ accessibilityLabel={componentId}>
90
100
  {!!name && !image && (
91
- <Text accessibilityLabel={accessibilityLabelDescription} color={Colors.pink_03} typography={'description_xs_regular'}>
101
+ <Text
102
+ color={Colors.pink_03}
103
+ typography={'description_xs_regular'}
104
+ accessibilityLabel={componentId + '|text'}>
92
105
  {getShortName(name)}
93
106
  </Text>
94
107
  )}
95
108
  {!name && !image && (
96
- <Icon accessibilityLabel={accessibilityLabelIcon} size={iconSize} source={'basic_person'} color={Colors.pink_03} />
109
+ <Icon
110
+ size={iconSize}
111
+ source={'basic_person'}
112
+ color={Colors.pink_03}
113
+ accessibilityLabel={componentId + '|icon'}
114
+ />
97
115
  )}
98
116
  {!!image && (
99
117
  <Image
100
- accessibilityLabel={accessibilityLabelImage}
101
118
  source={{uri: image}}
102
119
  style={[
103
120
  styles.image,
@@ -105,20 +122,21 @@ const Avatar: FC<AvatarProps> = ({
105
122
  borderRadius,
106
123
  },
107
124
  ]}
125
+ accessibilityLabel={componentId + '|img'}
108
126
  />
109
127
  )}
110
128
  {shouldShowIconTop && (
111
129
  <Image
112
- accessibilityLabel={accessibilityLabelTopIcon}
113
130
  source={{uri: logo}}
114
131
  style={[styles.icon, supportIconSize, {top: -1, right: -1}]}
132
+ accessibilityLabel={componentId + '|top-icon'}
115
133
  />
116
134
  )}
117
135
  {shouldShowIconBottom && (
118
136
  <Image
119
- accessibilityLabel={accessibilityLabelBottomIcon}
120
137
  source={{uri: iconSupport}}
121
138
  style={[styles.icon, supportIconSize, {bottom: -1, right: -1}]}
139
+ accessibilityLabel={componentId + '|bottom-icon'}
122
140
  />
123
141
  )}
124
142
  </View>
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
- "name": "@momo-kits/avatar",
3
- "version": "0.112.1-beta.2",
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
- "publishConfig": {
17
- "registry": "https://registry.npmjs.org/"
18
- },
19
- "dependencies": {}
2
+ "name": "@momo-kits/avatar",
3
+ "version": "0.112.1-beta.20",
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
+ "publishConfig": {
17
+ "registry": "https://registry.npmjs.org/"
18
+ },
19
+ "dependencies": {}
20
20
  }
package/types.ts CHANGED
@@ -54,29 +54,4 @@ export type AvatarProps = {
54
54
  * Optional. Assign accessibility label to the avatar for automated testing.
55
55
  */
56
56
  accessibilityLabel?: string;
57
-
58
- /**
59
- * Optional. Assign accessibility label to the image for automated testing.
60
- */
61
- accessibilityLabelImage?: string;
62
-
63
- /**
64
- * Optional. Assign accessibility label to the description for automated testing.
65
- */
66
- accessibilityLabelDescription?: string;
67
-
68
- /**
69
- * Optional. Assign accessibility label to the icon for automated testing.
70
- */
71
- accessibilityLabelIcon?: string;
72
-
73
- /**
74
- * Optional. Assign accessibility label to the support icon for automated testing.
75
- */
76
- accessibilityLabelTopIcon?: string;
77
-
78
- /**
79
- * Optional. Assign accessibility label to the support icon for automated testing.
80
- */
81
- accessibilityLabelBottomIcon?: string;
82
57
  };