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
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
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-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes } 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;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 20:06:50 +00:00
|
|
|
const keyExtractor = (item: IItemData) => item.value.toString();
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Chip = ({ item, onSelect, style, theme }: IChip) => (
|
2020-02-11 14:01:35 +00:00
|
|
|
<Touchable
|
|
|
|
key={item.value}
|
|
|
|
onPress={() => onSelect(item)}
|
2020-05-08 17:36:10 +00:00
|
|
|
style={[styles.chip, { backgroundColor: themes[theme].auxiliaryBackground }, style]}
|
2021-09-13 20:41:05 +00:00
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}>
|
2020-02-11 14:01:35 +00:00
|
|
|
<>
|
2020-03-30 19:50:27 +00:00
|
|
|
{item.imageUrl ? <FastImage style={styles.chipImage} source={{ uri: item.imageUrl }} /> : null}
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text numberOfLines={1} style={[styles.chipText, { color: themes[theme].titleText }]}>
|
|
|
|
{textParser([item.text])}
|
|
|
|
</Text>
|
2020-07-27 19:53:33 +00:00
|
|
|
<CustomIcon name='close' size={16} color={themes[theme].auxiliaryText} />
|
2020-02-11 14:01:35 +00:00
|
|
|
</>
|
|
|
|
</Touchable>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
Chip.propTypes = {};
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Chips = ({ items, onSelect, style, theme }: IChips) => (
|
2020-02-11 14:01:35 +00:00
|
|
|
<View style={styles.chips}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{items.map(item => (
|
|
|
|
<Chip key={keyExtractor(item)} item={item} onSelect={onSelect} style={style} theme={theme} />
|
|
|
|
))}
|
2020-02-11 14:01:35 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Chips;
|