Skip to content

Commit eb7a195

Browse files
committed
Update Chip icon props
1 parent 58c761e commit eb7a195

File tree

3 files changed

+70
-36
lines changed

3 files changed

+70
-36
lines changed

demo/src/screens/componentScreens/ChipScreen.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,26 @@ export default class ChipScreen extends Component {
4848
'Icon',
4949
<Chip
5050
iconSource={checkmark}
51-
iconColor={Colors.black}
5251
iconStyle={{width: 24, height: 24}}
52+
iconProps={{tintColor: Colors.black}}
5353
/>
5454
)}
5555
{this.renderExample(
56-
'label + icon',
56+
'Left icon',
5757
<Chip
5858
label={'Chip'}
5959
iconSource={checkmark}
6060
iconStyle={{width: 24, height: 24}}
61-
iconColor={Colors.black}
61+
iconProps={{tintColor: Colors.black}}
62+
/>
63+
)}
64+
{this.renderExample(
65+
'Right icon',
66+
<Chip
67+
label={'Chip'}
68+
rightIconSource={checkmark}
69+
iconStyle={{width: 24, height: 24}}
70+
iconProps={{tintColor: Colors.black}}
6271
/>
6372
)}
6473
{this.renderExample(
@@ -101,17 +110,16 @@ export default class ChipScreen extends Component {
101110
</Text>
102111
<View center row>
103112
<Chip
104-
iconSource={checkmark}
105113
label={'Chip'}
106114
labelStyle={{color: Colors.green20}}
107-
iconColor={Colors.green20}
115+
iconSource={checkmark}
116+
iconProps={{tintColor: Colors.green20}}
108117
containerStyle={{borderColor: Colors.green20}}
109118
/>
110119
<Chip
111120
iconSource={checkmark}
112121
label={'Chip'}
113122
labelStyle={{color: Colors.white}}
114-
iconColor={Colors.white}
115123
containerStyle={{borderColor: Colors.green20, backgroundColor: Colors.green20, marginLeft: Spacings.s3}}
116124
/>
117125
<Chip

generatedTypes/components/chip/index.d.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { StyleProp, ViewStyle, ViewProps, TouchableOpacityProps, ImageStyle, TextStyle, ImageSourcePropType } from 'react-native';
2+
import { StyleProp, ViewStyle, ViewProps, TouchableOpacityProps, ImageStyle, ImageProps, TextStyle, ImageSourcePropType } from 'react-native';
33
import { BadgeProps } from 'typings';
44
import { AvatarPropTypes } from '../avatar';
55
export declare type ChipPropTypes = ViewProps & TouchableOpacityProps & {
@@ -55,17 +55,21 @@ export declare type ChipPropTypes = ViewProps & TouchableOpacityProps & {
5555
*/
5656
avatarProps?: AvatarPropTypes;
5757
/**
58-
* Icon's source
59-
*/
60-
iconSource?: ImageSourcePropType;
61-
/**
62-
* Icon's color
58+
* Additional icon props
6359
*/
64-
iconColor?: string;
60+
iconProps?: ImageProps;
6561
/**
6662
* Icon style
6763
*/
6864
iconStyle?: StyleProp<ImageStyle>;
65+
/**
66+
* Icon's source
67+
*/
68+
iconSource?: ImageSourcePropType;
69+
/**
70+
* Icon's source
71+
*/
72+
rightIconSource?: ImageSourcePropType;
6973
/**
7074
* Adds a dismiss button and serves as its callback
7175
*/
@@ -140,17 +144,21 @@ declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps &
140144
*/
141145
avatarProps?: AvatarPropTypes | undefined;
142146
/**
143-
* Icon's source
144-
*/
145-
iconSource?: number | import("react-native").ImageURISource | import("react-native").ImageURISource[] | undefined;
146-
/**
147-
* Icon's color
147+
* Additional icon props
148148
*/
149-
iconColor?: string | undefined;
149+
iconProps?: ImageProps | undefined;
150150
/**
151151
* Icon style
152152
*/
153153
iconStyle?: StyleProp<ImageStyle>;
154+
/**
155+
* Icon's source
156+
*/
157+
iconSource?: number | import("react-native").ImageURISource | import("react-native").ImageURISource[] | undefined;
158+
/**
159+
* Icon's source
160+
*/
161+
rightIconSource?: number | import("react-native").ImageURISource | import("react-native").ImageURISource[] | undefined;
154162
/**
155163
* Adds a dismiss button and serves as its callback
156164
*/

src/components/chip/index.tsx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import React, {useCallback} from 'react';
3-
import {StyleSheet, StyleProp, ViewStyle, ViewProps, TouchableOpacityProps, ImageStyle, TextStyle, ImageSourcePropType} from 'react-native';
3+
import {StyleSheet, StyleProp, ViewStyle, ViewProps, TouchableOpacityProps, ImageStyle, ImageProps, TextStyle, ImageSourcePropType} from 'react-native';
44
import {BadgeProps} from 'typings';
55
// @ts-ignore
66
import Assets from '../../assets';
@@ -72,20 +72,28 @@ export type ChipPropTypes = ViewProps & TouchableOpacityProps & {
7272
*/
7373
avatarProps?: AvatarPropTypes;
7474

75-
//ICON
75+
//ICON GENERAL
7676
/**
77-
* Icon's source
77+
* Additional icon props
7878
*/
79-
iconSource?: ImageSourcePropType;
80-
/**
81-
* Icon's color
82-
*/
83-
iconColor?: string;
79+
iconProps?: ImageProps
8480
/**
8581
* Icon style
8682
*/
8783
iconStyle?: StyleProp<ImageStyle>;
8884

85+
//LEFT ICON
86+
/**
87+
* Icon's source
88+
*/
89+
iconSource?: ImageSourcePropType;
90+
91+
//RIGHT ICON
92+
/**
93+
* Icon's source
94+
*/
95+
rightIconSource?: ImageSourcePropType;
96+
8997
//DISMISS ('x' button)
9098
/**
9199
* Adds a dismiss button and serves as its callback
@@ -126,9 +134,10 @@ const Chip: React.FC<ChipPropTypes> = ({
126134
dismissIcon,
127135
dismissIconStyle,
128136
dismissContainerStyle,
129-
iconColor,
137+
iconProps,
130138
iconSource,
131139
iconStyle,
140+
rightIconSource,
132141
label,
133142
labelStyle,
134143
onPress,
@@ -139,17 +148,19 @@ const Chip: React.FC<ChipPropTypes> = ({
139148
...others
140149
}) => {
141150

142-
const renderIcon = useCallback(() => {
151+
const renderIcon = useCallback((iconPosition) => {
152+
const isLeftIcon = iconPosition === 'left'
153+
143154
return (
144155
<Image
145156
// @ts-ignore
146-
source={iconSource}
147-
tintColor={iconColor}
148-
style={[iconStyle, getMargins('iconSource')]}
157+
source={isLeftIcon ? iconSource : rightIconSource}
149158
testID={`${testID}.icon`}
159+
{...iconProps}
160+
style={[getMargins('iconSource'), iconStyle]}
150161
/>
151162
);
152-
}, [iconColor, iconSource, iconStyle]);
163+
}, [iconSource, rightIconSource, iconStyle, iconProps]);
153164

154165

155166
const renderBadge = useCallback(() => {
@@ -229,7 +240,13 @@ const Chip: React.FC<ChipPropTypes> = ({
229240
if (iconSource) {
230241
return {
231242
marginLeft: 2,
232-
marginRight: Spacings.s2
243+
marginRight: Spacings.s3
244+
};
245+
}
246+
if (rightIconSource) {
247+
return {
248+
marginLeft: Spacings.s3,
249+
marginRight: 2
233250
};
234251
}
235252
if (onDismiss) {
@@ -254,7 +271,7 @@ const Chip: React.FC<ChipPropTypes> = ({
254271
};
255272
}
256273
}
257-
}, [avatarProps, badgeProps, iconSource, onDismiss]);
274+
}, [avatarProps, badgeProps, iconSource, rightIconSource, onDismiss]);
258275

259276
const getContainerSize = useCallback(() => {
260277
const width = useSizeAsMinimum ? 'minWidth' : 'width';
@@ -282,8 +299,9 @@ const Chip: React.FC<ChipPropTypes> = ({
282299
{...others}
283300
>
284301
{avatarProps && renderAvatar()}
285-
{iconSource && renderIcon()}
302+
{iconSource && renderIcon('left')}
286303
{label && renderLabel()}
304+
{rightIconSource && renderIcon('right')}
287305
{badgeProps && renderBadge()}
288306
{onDismiss && renderOnDismiss()}
289307
</Container>

0 commit comments

Comments
 (0)