@momo-kits/chip 0.75.1-beta.3 → 0.75.1-beta.8

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,90 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {
3
+ ApplicationContext,
4
+ Colors,
5
+ Icon,
6
+ Image,
7
+ Text,
8
+ Typography,
9
+ } from '@momo-kits/foundation';
10
+ import {TouchableOpacity, View} from 'react-native';
11
+ import styles from './styles';
12
+ import {ChipProps} from './types';
13
+
14
+ const Chip: FC<ChipProps> = ({
15
+ label = 'Label',
16
+ iconLeft,
17
+ iconRight,
18
+ selected = false,
19
+ style,
20
+ onPress,
21
+ size = 'large',
22
+ iconLeftColor,
23
+ iconRightColor,
24
+ }) => {
25
+ const {theme} = useContext(ApplicationContext);
26
+ const textColor = selected ? theme.colors.primary : theme.colors.text.default;
27
+ const backgroundColor = selected
28
+ ? theme.colors.background.tonal
29
+ : theme.colors.border.default;
30
+
31
+ let typo: Typography = 'label_default';
32
+ let chipStyle = styles.chip;
33
+ let imageStyle = styles.image;
34
+ let iconSize = 20;
35
+ if (size === 'small') {
36
+ chipStyle = styles.smallChip;
37
+ imageStyle = styles.imageSmall;
38
+ iconSize = 16;
39
+ typo = 'label_s';
40
+ }
41
+
42
+ const renderOverlay = () => {
43
+ return (
44
+ <View
45
+ style={[
46
+ styles.chipOverlay,
47
+ {
48
+ borderColor: Colors.pink_06,
49
+ },
50
+ ]}
51
+ />
52
+ );
53
+ };
54
+
55
+ return (
56
+ <View style={[style, styles.wrapper]}>
57
+ <TouchableOpacity
58
+ onPress={onPress}
59
+ style={[
60
+ chipStyle,
61
+ {
62
+ backgroundColor,
63
+ },
64
+ ]}>
65
+ {!!iconLeft && (
66
+ <Image
67
+ source={{uri: iconLeft}}
68
+ tintColor={iconLeftColor}
69
+ style={imageStyle}
70
+ />
71
+ )}
72
+ <Text typography={typo} color={textColor}>
73
+ {label}
74
+ </Text>
75
+ {!!iconRight && (
76
+ <Icon
77
+ source={iconRight}
78
+ color={iconRightColor}
79
+ size={iconSize}
80
+ style={styles.icon}
81
+ />
82
+ )}
83
+ {selected && renderOverlay()}
84
+ </TouchableOpacity>
85
+ </View>
86
+ );
87
+ };
88
+
89
+ export default Chip;
90
+ export type {ChipProps};
package/package.json CHANGED
@@ -1,16 +1,14 @@
1
1
  {
2
2
  "name": "@momo-kits/chip",
3
- "version": "0.75.1-beta.3",
3
+ "version": "0.75.1-beta.8",
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",
6
+ "dependencies": {},
10
7
  "peerDependencies": {
8
+ "@momo-kits/core-v2": ">=0.0.5-beta",
9
+ "prop-types": "^15.7.2",
11
10
  "react": "16.9.0",
12
- "react-native": ">=0.55",
13
- "@momo-kits/core-v2": ">=0.0.4-beta"
11
+ "react-native": ">=0.55"
14
12
  },
15
13
  "devDependencies": {},
16
14
  "license": "MoMo"
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,13 @@
1
+ import {ViewStyle} from 'react-native';
2
+
3
+ export type ChipProps = {
4
+ label: string;
5
+ iconLeft?: string;
6
+ iconRight?: string;
7
+ selected?: boolean;
8
+ style?: ViewStyle | ViewStyle[];
9
+ onPress?: () => void;
10
+ size?: 'small' | 'large';
11
+ iconLeftColor?: string;
12
+ iconRightColor?: string;
13
+ };
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;