PliWould/components/ProductTile.tsx

55 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>>>;
type StyleSpec = {
highlight?: MyStyle,
text?: MyStyle,
image?: MyStyle,
}
2024-06-27 23:31:59 +02:00
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
}
const FALLBACK_IMAGE = "";
export function ProductTile ({product, onProductSelected, isActive} : ProductTileProps) {
const k = isActive ? "active" : "default";
2024-06-27 23:31:59 +02:00
return (
2024-07-01 04:49:41 +02:00
<TouchableHighlight
style={styles[k].highlight}
2024-07-01 04:49:41 +02:00
onPress={() => onProductSelected && onProductSelected(product)}>
<Text style={styles[k].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 = {
active: StyleSheet.create({
highlight: {
padding: 10,
margin: 2,
color: "lightblue",
},
text: {
}
}),
default: StyleSheet.create({
highlight: {
padding: 10,
margin: 2,
backgroundColor: "lightgrey",
},
text: {
}
}),
}