2020-02-11 14:01:35 +00:00
|
|
|
import React from 'react';
|
2020-03-30 19:50:27 +00:00
|
|
|
import { Text, View } from 'react-native';
|
2020-02-11 14:01:35 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2022-05-31 16:08:18 +00:00
|
|
|
import FastImage from 'react-native-fast-image';
|
2020-02-11 14:01:35 +00:00
|
|
|
|
|
|
|
import { textParser } from '../utils';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../../CustomIcon';
|
2020-02-11 14:01:35 +00:00
|
|
|
import styles from './styles';
|
2022-03-29 20:06:50 +00:00
|
|
|
import { IItemData } from '.';
|
2022-07-13 19:31:58 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IChip {
|
2022-03-29 20:06:50 +00:00
|
|
|
item: IItemData;
|
|
|
|
onSelect: (item: IItemData) => void;
|
2021-09-13 20:41:05 +00:00
|
|
|
style?: object;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IChips {
|
2022-03-29 20:06:50 +00:00
|
|
|
items: IItemData[];
|
|
|
|
onSelect: (item: IItemData) => void;
|
2021-09-13 20:41:05 +00:00
|
|
|
style?: object;
|
|
|
|
}
|
|
|
|
|
2022-03-29 20:06:50 +00:00
|
|
|
const keyExtractor = (item: IItemData) => item.value.toString();
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2022-07-13 19:31:58 +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]}
|
2022-08-08 21:02:08 +00:00
|
|
|
background={Touchable.Ripple(colors.bannerBackground)}
|
2023-08-03 19:37:14 +00:00
|
|
|
testID={`multi-select-chip-${item.value}`}
|
2022-08-08 21:02:08 +00:00
|
|
|
>
|
2022-07-13 19:31:58 +00:00
|
|
|
<>
|
|
|
|
{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>
|
|
|
|
);
|
|
|
|
};
|
2021-09-13 20:41:05 +00:00
|
|
|
Chip.propTypes = {};
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2022-07-13 19:31:58 +00:00
|
|
|
const Chips = ({ items, onSelect, style }: IChips) => (
|
2020-02-11 14:01:35 +00:00
|
|
|
<View style={styles.chips}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{items.map(item => (
|
2022-07-13 19:31:58 +00:00
|
|
|
<Chip key={keyExtractor(item)} item={item} onSelect={onSelect} style={style} />
|
2021-09-13 20:41:05 +00:00
|
|
|
))}
|
2020-02-11 14:01:35 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Chips;
|