Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ Add custom elements to Chip #1298

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 49 additions & 54 deletions demo/src/screens/componentScreens/ChipScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {Alert} from 'react-native';
import {Chip, Colors, Spacings, Text, Typography, View, Dialog, WheelPickerDialog} from 'react-native-ui-lib';
import {Chip, Colors, Spacings, Text, Typography, View, Dialog, WheelPickerDialog, Image} from 'react-native-ui-lib';

const avatarImage = {
uri: 'https://randomuser.me/api/portraits/women/24.jpg'
};
const checkmark = require('../../assets/icons/check-small.png');
const chevron = require('../../assets/icons/chevronDown.png');

const bell = require('../../assets/icons/bell.png');

export default class ChipScreen extends Component {

colors = [
{value: Colors.red10, label: 'Red'},
{value: Colors.blue10, label: 'Blue'},
Expand All @@ -31,7 +30,7 @@ export default class ChipScreen extends Component {

openDialog = () => {
this.toggleDialog(true);
}
};

closeDialog = () => {
this.toggleDialog(false);
Expand Down Expand Up @@ -73,13 +72,7 @@ export default class ChipScreen extends Component {
const {showDialog} = this.state;

return (
<Dialog
migrate
visible={showDialog}
useSafeArea
bottom
onDismiss={this.closeDialog}
>
<Dialog migrate visible={showDialog} useSafeArea bottom onDismiss={this.closeDialog}>
{this.renderContent()}
</Dialog>
);
Expand All @@ -104,59 +97,34 @@ export default class ChipScreen extends Component {
<Text marginB-10 text70BO>
Default
</Text>
{this.renderExample(
'Label',
<Chip label={'Chip'}/>
)}
{this.renderExample(
'Label + onPress',
<Chip label={'Chip'} onPress={() => Alert.alert('onPress')}/>
)}
{this.renderExample(
'Label + onDismiss',
{this.renderExample('Label', <Chip label={'Chip'}/>)}
{this.renderExample('Label + onPress', <Chip label={'Chip'} onPress={() => Alert.alert('onPress')}/>)}
{this.renderExample('Label + onDismiss',
<Chip
label={'Chip'}
iconColor={Colors.black}
onDismiss={() => Alert.alert('onDismiss')}
onPress={() => Alert.alert('onPress')}
dismissIconStyle={{width: 10, height: 10}}
/>
)}
{this.renderExample(
'Icon',
<Chip
iconSource={checkmark}
iconStyle={{width: 24, height: 24}}
iconProps={{tintColor: Colors.black}}
/>
)}
{this.renderExample(
'Left icon',
/>)}
{this.renderExample('Icon',
<Chip iconSource={checkmark} iconStyle={{width: 24, height: 24}} iconProps={{tintColor: Colors.black}}/>)}
{this.renderExample('Left icon',
<Chip
label={'Chip'}
iconSource={checkmark}
iconStyle={{width: 24, height: 24}}
iconProps={{tintColor: Colors.black}}
/>
)}
{this.renderExample(
'Right icon + onPress + dynamic label',
/>)}
{this.renderExample('Right icon + onPress + dynamic label',
<Chip
label={this.state.selectedValue}
rightIconSource={chevron}
iconStyle={{margin: 8}}
onPress={this.openDialog}
/>
)}
{this.renderExample(
'Label + Avatar',
<Chip
label={'Chip'}
avatarProps={{source: avatarImage, size: 20}}
/>
)}
{this.renderExample(
'Label + Counter',
/>)}
{this.renderExample('Label + Avatar', <Chip label={'Chip'} avatarProps={{source: avatarImage, size: 20}}/>)}
{this.renderExample('Label + Counter',
<Chip
label={'Chip'}
labelStyle={{
Expand All @@ -170,18 +138,15 @@ export default class ChipScreen extends Component {
color: Colors.grey20
}
}}
/>
)}
{this.renderExample(
'Label + Badge',
/>)}
{this.renderExample('Label + Badge',
<Chip
label={'Chip'}
badgeProps={{
label: '4',
backgroundColor: 'red'
}}
/>
)}
/>)}

<Text marginT-20 marginB-10 text70BO>
Custom
Expand Down Expand Up @@ -234,6 +199,36 @@ export default class ChipScreen extends Component {
}}
/>
</View>
<View center row marginT-10>
<Chip
rightElement={<Image tintColor={Colors.yellow30} source={bell} width={24} height={24}/>}
label={'Chip'}
/>
<Chip
marginL-s3
rightElement={<Image tintColor={Colors.green20} source={bell} width={20} height={20}/>}
leftElement={<Image tintColor={Colors.green20} source={bell} width={20} height={20}/>}
label={'Chip'}
/>
<Chip
marginL-s3
leftElement={
<View center row marginL-s1>
<Image tintColor={Colors.blue30} source={bell}/>
<Image tintColor={Colors.blue30} source={bell} width={20} height={20}/>
<Image tintColor={Colors.blue30} source={bell} width={24} height={24}/>
</View>
}
label={'Chip'}
/>
<Chip
marginL-s3
paddingR-s2
rightIconSource={chevron}
rightElement={<Image tintColor={Colors.red30} source={bell} width={20} height={20}/>}
label={'Chip'}
/>
</View>
</View>
);
}
Expand Down
16 changes: 16 additions & 0 deletions generatedTypes/components/chip/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export declare type ChipProps = ViewProps & TouchableOpacityProps & {
* Right icon's source
*/
rightIconSource?: ImageSourcePropType;
/**
* Left custom element
*/
leftElement?: JSX.Element;
/**
* Right custom element
*/
rightElement?: JSX.Element;
/**
* Adds a dismiss button and serves as its callback
*/
Expand Down Expand Up @@ -170,6 +178,14 @@ declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps &
* Right icon's source
*/
rightIconSource?: number | import("react-native").ImageURISource | import("react-native").ImageURISource[] | undefined;
/**
* Left custom element
*/
leftElement?: JSX.Element | undefined;
/**
* Right custom element
*/
rightElement?: JSX.Element | undefined;
/**
* Adds a dismiss button and serves as its callback
*/
Expand Down
27 changes: 24 additions & 3 deletions src/components/chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {useCallback} from 'react';
import {StyleSheet, StyleProp, ViewStyle, ViewProps, ImageStyle, TextStyle, ImageSourcePropType} from 'react-native';
import Assets from '../../assets';
import {asBaseComponent} from '../../commons/new';
import {BorderRadiuses, Spacings} from '../../style';
import {BorderRadiuses, Spacings} from 'style';
import Avatar, {AvatarProps} from '../avatar';
import Badge, {BadgeProps, BADGE_SIZES} from '../badge';
import Image, {ImageProps} from '../image';
Expand Down Expand Up @@ -94,6 +94,18 @@ export type ChipProps = ViewProps & TouchableOpacityProps & {
*/
rightIconSource?: ImageSourcePropType;

//LEFT ELEMENT
/**
* Left custom element
*/
leftElement?: JSX.Element;

//RIGHT ELEMENT
/**
* Right custom element
*/
rightElement?: JSX.Element;

//DISMISS ('x' button)
/**
* Adds a dismiss button and serves as its callback
Expand Down Expand Up @@ -142,6 +154,8 @@ const Chip = ({
iconSource,
iconStyle,
rightIconSource,
leftElement,
rightElement,
label,
labelStyle,
onPress,
Expand Down Expand Up @@ -241,13 +255,18 @@ const Chip = ({
marginRight: Spacings.s1
};
}
if (iconSource) {
if (rightElement && leftElement) {
return {
marginHorizontally: 2
};
}
if (iconSource || leftElement) {
return {
marginLeft: 2,
marginRight: Spacings.s3
};
}
if (rightIconSource) {
if (rightIconSource || rightElement) {
return {
marginLeft: Spacings.s3,
marginRight: 2
Expand Down Expand Up @@ -304,7 +323,9 @@ const Chip = ({
>
{avatarProps && renderAvatar()}
{iconSource && renderIcon('left')}
{leftElement}
{label && renderLabel()}
{rightElement}
{rightIconSource && renderIcon('right')}
{badgeProps && renderBadge()}
{onDismiss && renderOnDismiss()}
Expand Down