@momo-kits/chip 0.113.0-rc.3 → 0.113.1-rc.3
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 +27 -4
- package/package.json +1 -1
- package/types.ts +11 -1
package/index.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import React, {FC, useContext} from 'react';
|
|
1
|
+
import React, {FC, useContext, useMemo} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ApplicationContext,
|
|
4
4
|
Colors,
|
|
5
5
|
Icon,
|
|
6
|
+
MiniAppContext,
|
|
7
|
+
ScreenContext,
|
|
6
8
|
Spacing,
|
|
7
9
|
Text,
|
|
8
10
|
Typography,
|
|
@@ -22,8 +24,23 @@ const Chip: FC<ChipProps> = ({
|
|
|
22
24
|
iconLeftColor,
|
|
23
25
|
iconRightColor,
|
|
24
26
|
itemContainerStyle,
|
|
27
|
+
accessibilityLabel,
|
|
28
|
+
accessibilityState,
|
|
25
29
|
}) => {
|
|
26
30
|
const {theme} = useContext(ApplicationContext);
|
|
31
|
+
|
|
32
|
+
const app = useContext<any>(MiniAppContext);
|
|
33
|
+
const screen = useContext<any>(ScreenContext);
|
|
34
|
+
const componentName = 'Chip';
|
|
35
|
+
|
|
36
|
+
const componentId = useMemo(() => {
|
|
37
|
+
if (accessibilityLabel) {
|
|
38
|
+
return accessibilityLabel;
|
|
39
|
+
}
|
|
40
|
+
let id = `${app.appId}/${app.code}/${screen.screenName}/${componentName}/${label}`;
|
|
41
|
+
return id;
|
|
42
|
+
}, [componentName, accessibilityLabel, app, screen]);
|
|
43
|
+
|
|
27
44
|
let textColor = theme.colors.text.default;
|
|
28
45
|
let backgroundColor = Colors.black_03;
|
|
29
46
|
let iconLeftColorSelected = iconLeftColor;
|
|
@@ -59,7 +76,7 @@ const Chip: FC<ChipProps> = ({
|
|
|
59
76
|
};
|
|
60
77
|
|
|
61
78
|
return (
|
|
62
|
-
<View style={[style, styles.wrapper]}>
|
|
79
|
+
<View style={[style, styles.wrapper]} accessibilityLabel={componentId}>
|
|
63
80
|
<TouchableOpacity
|
|
64
81
|
onPress={onPress}
|
|
65
82
|
style={[
|
|
@@ -68,7 +85,9 @@ const Chip: FC<ChipProps> = ({
|
|
|
68
85
|
{
|
|
69
86
|
backgroundColor,
|
|
70
87
|
},
|
|
71
|
-
]}
|
|
88
|
+
]}
|
|
89
|
+
accessibilityLabel={componentId + '|touch'}
|
|
90
|
+
accessibilityState={{checked: selected, ...accessibilityState}}>
|
|
72
91
|
{!!iconLeft && (
|
|
73
92
|
<Icon
|
|
74
93
|
source={iconLeft}
|
|
@@ -78,7 +97,10 @@ const Chip: FC<ChipProps> = ({
|
|
|
78
97
|
/>
|
|
79
98
|
)}
|
|
80
99
|
{label && (
|
|
81
|
-
<Text
|
|
100
|
+
<Text
|
|
101
|
+
typography={typo}
|
|
102
|
+
color={textColor}
|
|
103
|
+
accessibilityLabel={componentId + '|text'}>
|
|
82
104
|
{label}
|
|
83
105
|
</Text>
|
|
84
106
|
)}
|
|
@@ -88,6 +110,7 @@ const Chip: FC<ChipProps> = ({
|
|
|
88
110
|
color={iconRightColorSelected}
|
|
89
111
|
size={iconSize}
|
|
90
112
|
style={styles.icon}
|
|
113
|
+
accessibilityLabel={componentId + '|icon'}
|
|
91
114
|
/>
|
|
92
115
|
)}
|
|
93
116
|
{selected && renderOverlay()}
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ViewStyle} from 'react-native';
|
|
1
|
+
import {AccessibilityState, ViewStyle} from 'react-native';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Props for the Chip component. A Chip is a compact element that represents an input, attribute, or action.
|
|
@@ -54,4 +54,14 @@ export type ChipProps = {
|
|
|
54
54
|
iconRightColor?: string;
|
|
55
55
|
|
|
56
56
|
itemContainerStyle?: ViewStyle;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Optional. Assign accessibility label to the chip for automated testing.
|
|
60
|
+
*/
|
|
61
|
+
accessibilityLabel?: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Optional. Accessibility state for the chip.
|
|
65
|
+
*/
|
|
66
|
+
accessibilityState?: AccessibilityState;
|
|
57
67
|
};
|