PliWould/components/ProductTile.tsx

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-06-27 23:31:59 +02:00
import { Product } from "@/lib/product"
2024-07-01 04:49:41 +02:00
import { ImageBackground, StyleProp, StyleSheet, Text, TouchableHighlight, View, ViewStyle } from "react-native";
2024-06-27 23:31:59 +02:00
import { AnimatedStyle } from "react-native-reanimated";
export type OnProductSelectedFunc = (product : Product) => any;
type MyStyle = StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
export type ProductTileProps = {
product: (Product),
onProductSelected?: OnProductSelectedFunc,
2024-07-01 04:49:41 +02:00
isActive: boolean,
2024-06-27 23:31:59 +02:00
style?: {
2024-07-01 04:49:41 +02:00
default?: {
highlight?: MyStyle,
text?: MyStyle,
image?: MyStyle,
}
active?: {
highlight?: MyStyle,
text?: MyStyle,
image?: MyStyle,
}
2024-06-27 23:31:59 +02:00
}
}
const FALLBACK_IMAGE = "";
2024-07-01 04:49:41 +02:00
export function ProductTile ({product, onProductSelected, isActive, style} : ProductTileProps) {
const _style = (isActive ? style?.active : style?.default) || {};
2024-06-27 23:31:59 +02:00
return (
2024-07-01 04:49:41 +02:00
<TouchableHighlight
style={_style.highlight || styles.highlight}
onPress={() => onProductSelected && onProductSelected(product)}>
2024-07-01 17:05:24 +02:00
<Text style={_style.text || styles.text}>{product.attributes.name || `Product ${product.id}`} ({product.pricePerUnitDisplay})</Text>
2024-07-01 04:49:41 +02:00
</TouchableHighlight>
2024-06-27 23:31:59 +02:00
);
}
const styles = StyleSheet.create({
2024-07-01 04:49:41 +02:00
highlight: {
},
2024-06-27 23:31:59 +02:00
image: {
},
text: {
},
tile: {
2024-06-27 23:31:59 +02:00
},
})