2023-11-22 07:03:57 -07:00
|
|
|
import React, {FunctionComponent} from 'react';
|
2023-10-07 15:14:09 -06:00
|
|
|
|
|
|
|
import {
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TextStyle,
|
|
|
|
TouchableOpacity,
|
|
|
|
View,
|
|
|
|
} from 'react-native';
|
2023-11-22 07:03:57 -07:00
|
|
|
import {ResizeMode} from 'react-native-video';
|
|
|
|
|
|
|
|
export type MultiValueControlPropType = number | string | ResizeMode;
|
2023-10-07 15:14:09 -06:00
|
|
|
|
|
|
|
/*
|
2023-11-22 07:03:57 -07:00
|
|
|
* MultiValueControl displays a list clickable text view
|
|
|
|
*/
|
2023-10-07 15:14:09 -06:00
|
|
|
|
2023-10-26 00:46:04 -06:00
|
|
|
interface MultiValueControlType<T> {
|
2023-10-07 15:14:09 -06:00
|
|
|
// a list a string or number to be displayed
|
2023-11-22 07:03:57 -07:00
|
|
|
values: Array<T>;
|
2023-10-07 15:14:09 -06:00
|
|
|
// The selected value in values
|
2023-11-22 07:03:57 -07:00
|
|
|
selected?: T;
|
2023-10-07 15:14:09 -06:00
|
|
|
// callback to press onPress
|
2023-11-22 07:03:57 -07:00
|
|
|
onPress: (arg: MultiValueControlPropType) => void;
|
2023-10-07 15:14:09 -06:00
|
|
|
}
|
|
|
|
|
2023-11-22 07:03:57 -07:00
|
|
|
const MultiValueControl: FunctionComponent<
|
|
|
|
MultiValueControlType<MultiValueControlPropType>
|
|
|
|
> = ({values, selected, onPress}) => {
|
2023-10-07 15:14:09 -06:00
|
|
|
const selectedStyle: TextStyle = StyleSheet.flatten([
|
|
|
|
styles.option,
|
|
|
|
{fontWeight: 'bold'},
|
|
|
|
]);
|
|
|
|
|
|
|
|
const unselectedStyle: TextStyle = StyleSheet.flatten([
|
|
|
|
styles.option,
|
|
|
|
{fontWeight: 'normal'},
|
|
|
|
]);
|
|
|
|
|
2023-11-22 07:03:57 -07:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
{values.map((value: MultiValueControlPropType) => {
|
|
|
|
const _style = value === selected ? selectedStyle : unselectedStyle;
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
key={value}
|
|
|
|
onPress={() => {
|
|
|
|
onPress?.(value);
|
|
|
|
}}>
|
2023-10-07 15:14:09 -06:00
|
|
|
<Text style={_style}>{value}</Text>
|
2023-11-22 07:03:57 -07:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
2023-10-07 15:14:09 -06:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
option: {
|
|
|
|
alignSelf: 'center',
|
|
|
|
fontSize: 11,
|
|
|
|
color: 'white',
|
|
|
|
paddingLeft: 2,
|
|
|
|
paddingRight: 2,
|
|
|
|
lineHeight: 12,
|
|
|
|
},
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default MultiValueControl;
|