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>>>;
|
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
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 = "";
|
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
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
|
2024-07-01 21:23:45 +02:00
|
|
|
style={styles[k].highlight}
|
2024-07-01 04:49:41 +02:00
|
|
|
onPress={() => onProductSelected && onProductSelected(product)}>
|
2024-07-01 21:23:45 +02:00
|
|
|
<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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-01 21:23:45 +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: {
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
}
|