@momo-kits/chip 0.73.3-beta.5 → 0.74.2-react-native.2

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 ADDED
@@ -0,0 +1,89 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {
3
+ ApplicationContext,
4
+ Icon,
5
+ Image,
6
+ Text,
7
+ Typography,
8
+ } from '@momo-kits/foundation';
9
+ import {TouchableOpacity, View} from 'react-native';
10
+ import styles from './styles';
11
+ import {ChipProps} from './types';
12
+
13
+ const Chip: FC<ChipProps> = ({
14
+ label = 'Label',
15
+ iconLeft,
16
+ iconRight,
17
+ selected = false,
18
+ style,
19
+ onPress,
20
+ size = 'large',
21
+ iconLeftColor,
22
+ iconRightColor,
23
+ }) => {
24
+ const {theme} = useContext(ApplicationContext);
25
+ const textColor = selected ? theme.colors.primary : theme.colors.text.default;
26
+ const backgroundColor = selected
27
+ ? theme.colors.background.tonal
28
+ : theme.colors.border.default;
29
+
30
+ let typo: Typography = 'label_default_medium';
31
+ let chipStyle = styles.chip;
32
+ let imageStyle = styles.image;
33
+ let iconSize = 20;
34
+ if (size === 'small') {
35
+ chipStyle = styles.smallChip;
36
+ imageStyle = styles.imageSmall;
37
+ iconSize = 16;
38
+ typo = 'label_s_medium';
39
+ }
40
+
41
+ const renderOverlay = () => {
42
+ return (
43
+ <View
44
+ style={[
45
+ styles.chipOverlay,
46
+ {
47
+ borderColor: theme.colors.secondary,
48
+ },
49
+ ]}
50
+ />
51
+ );
52
+ };
53
+
54
+ return (
55
+ <View style={[style, styles.wrapper]}>
56
+ <TouchableOpacity
57
+ onPress={onPress}
58
+ style={[
59
+ chipStyle,
60
+ {
61
+ backgroundColor,
62
+ },
63
+ ]}>
64
+ {!!iconLeft && (
65
+ <Image
66
+ source={{uri: iconLeft}}
67
+ tintColor={iconLeftColor}
68
+ style={imageStyle}
69
+ />
70
+ )}
71
+ <Text typography={typo} color={textColor}>
72
+ {label}
73
+ </Text>
74
+ {!!iconRight && (
75
+ <Icon
76
+ source={iconRight}
77
+ color={iconRightColor}
78
+ size={iconSize}
79
+ style={styles.icon}
80
+ />
81
+ )}
82
+ {selected && renderOverlay()}
83
+ </TouchableOpacity>
84
+ </View>
85
+ );
86
+ };
87
+
88
+ export {Chip};
89
+ export type {ChipProps};
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@momo-kits/chip",
3
- "version": "0.73.3-beta.5",
3
+ "version": "0.74.2-react-native.2",
4
4
  "private": false,
5
- "main": "index.js",
6
- "dependencies": {
7
- "prop-types": "^15.7.2",
8
- "react": "16.9.0"
9
- },
5
+ "main": "index.tsx",
10
6
  "peerDependencies": {
11
- "react": "16.9.0",
12
- "react-native": ">=0.55",
13
- "@momo-kits/core-v2": ">=0.0.4-beta"
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "*",
9
+ "react-native": "*",
10
+ "prop-types": "15.7.2"
11
+ },
12
+ "devDependencies": {
13
+ "@momo-platform/versions": "4.1.11"
14
14
  },
15
- "devDependencies": {},
16
- "license": "MoMo"
15
+ "license": "MoMo",
16
+ "dependencies": {}
17
17
  }
package/publish.sh CHANGED
@@ -26,4 +26,4 @@ cd ..
26
26
  rm -rf dist
27
27
 
28
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/chip new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/chip"}'
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/stepper new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/stepper"}'
package/styles.ts ADDED
@@ -0,0 +1,46 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {Radius, Spacing} from '@momo-kits/foundation';
3
+
4
+ export default StyleSheet.create({
5
+ chip: {
6
+ borderRadius: Radius.L,
7
+ paddingHorizontal: Spacing.S,
8
+ height: 32,
9
+ justifyContent: 'center',
10
+ alignItems: 'center',
11
+ flexDirection: 'row',
12
+ },
13
+ smallChip: {
14
+ borderRadius: Radius.L,
15
+ paddingHorizontal: Spacing.S,
16
+ height: 24,
17
+ justifyContent: 'center',
18
+ alignItems: 'center',
19
+ flexDirection: 'row',
20
+ },
21
+
22
+ chipOverlay: {
23
+ position: 'absolute',
24
+ top: 0,
25
+ bottom: 0,
26
+ left: 0,
27
+ right: 0,
28
+ zIndex: -1,
29
+ borderWidth: 2,
30
+ borderRadius: Radius.L,
31
+ },
32
+ image: {
33
+ width: 20,
34
+ height: 20,
35
+ marginRight: Spacing.XS,
36
+ },
37
+ imageSmall: {
38
+ width: 16,
39
+ height: 16,
40
+ marginRight: Spacing.XS,
41
+ },
42
+ icon: {
43
+ marginLeft: Spacing.XS,
44
+ },
45
+ wrapper: {flexDirection: 'row'},
46
+ });
package/types.ts ADDED
@@ -0,0 +1,55 @@
1
+ import {ViewStyle} from 'react-native';
2
+
3
+ /**
4
+ * Props for the Chip component. A Chip is a compact element that represents an input, attribute, or action.
5
+ */
6
+ export type ChipProps = {
7
+ /**
8
+ * The text to be displayed on the chip. This is typically a brief piece of information like a tag.
9
+ */
10
+ label: string;
11
+
12
+ /**
13
+ * Optional. The name of the icon to be displayed on the left side of the chip's label.
14
+ * If not provided, no icon is rendered on the left.
15
+ */
16
+ iconLeft?: string;
17
+
18
+ /**
19
+ * Optional. The name of the icon to be displayed on the right side of the chip's label.
20
+ * If not provided, no icon is rendered on the right.
21
+ */
22
+ iconRight?: string;
23
+
24
+ /**
25
+ * Optional. Indicates whether the chip is selected. A selected chip may have a different style or icon.
26
+ * Defaults to `false` if not provided.
27
+ */
28
+ selected?: boolean;
29
+
30
+ /**
31
+ * Optional. Custom styles to apply to the Chip component. Can be a single style or an array of styles.
32
+ */
33
+ style?: ViewStyle | ViewStyle[];
34
+
35
+ /**
36
+ * Optional. A callback function triggered when the chip is pressed. This makes the chip act as a touchable element.
37
+ */
38
+ onPress?: () => void;
39
+
40
+ /**
41
+ * Optional. Specifies the size of the chip, influencing its padding and font size. Can be 'small' or 'large'.
42
+ * If not provided, a standard size is used.
43
+ */
44
+ size?: 'small' | 'large';
45
+
46
+ /**
47
+ * Optional. Specifies the color of the left icon. If not provided, a default icon color may be used.
48
+ */
49
+ iconLeftColor?: string;
50
+
51
+ /**
52
+ * Optional. Specifies the color of the right icon. If not provided, a default icon color may be used.
53
+ */
54
+ iconRightColor?: string;
55
+ };
package/index.js DELETED
@@ -1,168 +0,0 @@
1
- import React from 'react';
2
- import {StyleSheet, View} from 'react-native';
3
- import {
4
- Colors,
5
- Image,
6
- Radius,
7
- Spacing,
8
- Text,
9
- TouchableOpacity,
10
- } from '@momo-kits/core-v2';
11
- import PropTypes from 'prop-types';
12
-
13
- const textSize = {
14
- default: {
15
- fontSize: 14,
16
- lineHeight: 20,
17
- },
18
- small: {
19
- fontSize: 12,
20
- lineHeight: 16,
21
- },
22
- };
23
-
24
- const imageSize = {
25
- default: {
26
- width: 20,
27
- height: 20,
28
- borderRadius: Radius.XS,
29
- marginRight: Spacing.XS,
30
- },
31
- small: {
32
- width: 16,
33
- height: 16,
34
- borderRadius: Radius.XS,
35
- marginRight: Spacing.XS,
36
- },
37
- };
38
-
39
- const chevronDown =
40
- 'https://img.mservice.com.vn/momo_app_v2/new_version/img/appx_icon/16_arrow_chevron_down.png';
41
- const remove = 'https://img.mservice.com.vn/app/img/kits/ic_close.png';
42
- const Chip = props => {
43
- const {
44
- image,
45
- title,
46
- size,
47
- onPress,
48
- active,
49
- style,
50
- onIconPress,
51
- type,
52
- whiteBackground,
53
- activeBackgroundColor,
54
- activeBorderColor,
55
- activeTextColor,
56
- } = props;
57
-
58
- const mapTextSize = textSize[size] || textSize.default;
59
- const mapImageSize = imageSize[size] || imageSize.default;
60
- const iconSource = type === 'removable' ? remove : chevronDown;
61
-
62
- const selectedStyle = {
63
- backgroundColor: activeBackgroundColor,
64
- };
65
-
66
- return (
67
- <TouchableOpacity
68
- style={[{alignSelf: 'baseline'}, style]}
69
- onPress={() => onPress?.(!active)}>
70
- <View
71
- style={[
72
- styles.container,
73
- whiteBackground && {backgroundColor: Colors.black_01},
74
- active && selectedStyle,
75
- ]}>
76
- {image && <Image source={image} style={[mapImageSize]} />}
77
- <Text.Label2
78
- weight="medium"
79
- style={[
80
- mapTextSize,
81
- {color: active ? activeTextColor : Colors.black_17},
82
- ]}>
83
- {title}
84
- </Text.Label2>
85
- {type !== 'default' && (
86
- <TouchableOpacity
87
- onPress={onIconPress}
88
- disabled={!onIconPress}
89
- style={styles.iconContainer}>
90
- <Image
91
- source={iconSource}
92
- style={[
93
- styles.icon,
94
- type === 'removable' && {tintColor: Colors.black_12},
95
- ]}
96
- />
97
- </TouchableOpacity>
98
- )}
99
- </View>
100
- {active && (
101
- <View
102
- style={[
103
- styles.background,
104
- {
105
- borderColor: activeBorderColor,
106
- },
107
- ]}
108
- />
109
- )}
110
- </TouchableOpacity>
111
- );
112
- };
113
-
114
- const styles = StyleSheet.create({
115
- container: {
116
- borderRadius: Radius.L,
117
- flexDirection: 'row',
118
- paddingVertical: Spacing.XS,
119
- paddingHorizontal: Spacing.S,
120
- justifyContent: 'center',
121
- alignItems: 'center',
122
- backgroundColor: Colors.black_04,
123
- },
124
- icon: {
125
- width: 16,
126
- height: 16,
127
- tintColor: Colors.black_17,
128
- },
129
- background: {
130
- position: 'absolute',
131
- top: 0,
132
- right: 0,
133
- bottom: 0,
134
- left: 0,
135
- borderRadius: Radius.L,
136
- borderWidth: 2,
137
- },
138
- iconContainer: {
139
- marginLeft: Spacing.XS,
140
- },
141
- });
142
-
143
- Chip.propTypes = {
144
- image: PropTypes.string,
145
- title: PropTypes.string,
146
- size: PropTypes.oneOf(['small', 'default']),
147
- onPress: PropTypes.func,
148
- active: PropTypes.bool,
149
- style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
150
- onIconPress: PropTypes.func,
151
- type: PropTypes.oneOf(['default', 'removable', 'action']),
152
- activeBackgroundColor: PropTypes.string,
153
- activeBorderColor: PropTypes.string,
154
- activeTextColor: PropTypes.string,
155
- whiteBackground: PropTypes.bool,
156
- };
157
-
158
- Chip.defaultProps = {
159
- size: 'default',
160
- type: 'default',
161
- active: false,
162
- activeBackgroundColor: Colors.pink_10,
163
- activeBorderColor: Colors.pink_06,
164
- activeTextColor: Colors.pink_03,
165
- whiteBackground: false,
166
- };
167
-
168
- export default Chip;