Rocket.Chat.ReactNative/app/containers/UIKit/MultiSelect/Chips.tsx

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-02-11 14:01:35 +00:00
import React from 'react';
import { Text, View } from 'react-native';
2020-02-11 14:01:35 +00:00
import Touchable from 'react-native-platform-touchable';
import FastImage from 'react-native-fast-image';
2020-02-11 14:01:35 +00:00
import { textParser } from '../utils';
import { CustomIcon } from '../../CustomIcon';
2020-02-11 14:01:35 +00:00
import styles from './styles';
import { IItemData } from '.';
import { useTheme } from '../../../theme';
2020-02-11 14:01:35 +00:00
interface IChip {
item: IItemData;
onSelect: (item: IItemData) => void;
style?: object;
}
interface IChips {
items: IItemData[];
onSelect: (item: IItemData) => void;
style?: object;
}
const keyExtractor = (item: IItemData) => item.value.toString();
2020-02-11 14:01:35 +00:00
const Chip = ({ item, onSelect, style }: IChip) => {
const { colors } = useTheme();
return (
<Touchable
key={item.value}
onPress={() => onSelect(item)}
style={[styles.chip, { backgroundColor: colors.auxiliaryBackground }, style]}
background={Touchable.Ripple(colors.bannerBackground)}
testID={`multi-select-chip-${item.value}`}
>
<>
{item.imageUrl ? <FastImage style={styles.chipImage} source={{ uri: item.imageUrl }} /> : null}
<Text numberOfLines={1} style={[styles.chipText, { color: colors.titleText }]}>
{textParser([item.text])}
</Text>
<CustomIcon name='close' size={16} color={colors.auxiliaryText} />
</>
</Touchable>
);
};
Chip.propTypes = {};
2020-02-11 14:01:35 +00:00
const Chips = ({ items, onSelect, style }: IChips) => (
2020-02-11 14:01:35 +00:00
<View style={styles.chips}>
{items.map(item => (
<Chip key={keyExtractor(item)} item={item} onSelect={onSelect} style={style} />
))}
2020-02-11 14:01:35 +00:00
</View>
);
export default Chips;