2024-08-19 16:08:54 +02:00
|
|
|
import { Product, priceDisplay, pricePerUnitDisplay } from "@/lib/product";
|
|
|
|
import { LinearGradient } from "expo-linear-gradient";
|
|
|
|
import {
|
|
|
|
ImageBackground,
|
|
|
|
Pressable,
|
|
|
|
StyleProp,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
|
|
|
ViewStyle,
|
|
|
|
} from "react-native";
|
2024-06-27 23:31:59 +02:00
|
|
|
import { AnimatedStyle } from "react-native-reanimated";
|
|
|
|
|
2024-08-19 16:08:54 +02:00
|
|
|
export type OnProductSelectedFunc = (product: Product) => any;
|
2024-06-27 23:31:59 +02:00
|
|
|
|
|
|
|
type MyStyle = StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
|
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
type StyleSpec = {
|
2024-08-19 16:08:54 +02:00
|
|
|
highlight?: MyStyle;
|
|
|
|
text?: MyStyle;
|
|
|
|
image?: MyStyle;
|
|
|
|
};
|
2024-07-01 21:23:45 +02:00
|
|
|
|
2024-06-27 23:31:59 +02:00
|
|
|
export type ProductTileProps = {
|
2024-08-19 16:08:54 +02:00
|
|
|
product: Product;
|
|
|
|
onProductSelected?: OnProductSelectedFunc;
|
|
|
|
isActive: boolean;
|
|
|
|
};
|
2024-06-27 23:31:59 +02:00
|
|
|
|
|
|
|
const FALLBACK_IMAGE = "";
|
|
|
|
|
2024-08-19 16:08:54 +02:00
|
|
|
export function ProductTile({
|
|
|
|
product,
|
|
|
|
onProductSelected,
|
|
|
|
isActive,
|
|
|
|
}: ProductTileProps) {
|
|
|
|
const k = isActive ? "active" : "default";
|
|
|
|
|
|
|
|
const BLUE_HILIGHT = "#caceff";
|
|
|
|
const BLUE = "#8b9cff";
|
|
|
|
const GRAY_HILIGHT = "#ffffff";
|
|
|
|
const GRAY = "#b1b1b1";
|
2024-07-31 19:01:45 +02:00
|
|
|
|
2024-08-19 16:08:54 +02:00
|
|
|
const activeColors = [BLUE_HILIGHT, BLUE, BLUE, BLUE];
|
|
|
|
const inactiveColors = [GRAY_HILIGHT, GRAY, GRAY, GRAY];
|
2024-07-01 04:49:41 +02:00
|
|
|
|
2024-08-19 16:08:54 +02:00
|
|
|
const priceDisplay = pricePerUnitDisplay(product);
|
|
|
|
return (
|
|
|
|
<LinearGradient
|
|
|
|
colors={isActive ? activeColors : inactiveColors}
|
|
|
|
style={styles.gradientButton}
|
|
|
|
>
|
|
|
|
<Pressable
|
|
|
|
style={styles.button}
|
|
|
|
aria-label={`product ${product.id}`}
|
|
|
|
onPress={() => onProductSelected && onProductSelected(product)}
|
|
|
|
>
|
|
|
|
<Text style={styles.text}>
|
|
|
|
{product.attributes?.name || `Product ${product.id}`} ({priceDisplay})
|
|
|
|
</Text>
|
|
|
|
</Pressable>
|
|
|
|
</LinearGradient>
|
|
|
|
);
|
2024-06-27 23:31:59 +02:00
|
|
|
}
|
|
|
|
|
2024-08-19 16:08:54 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
gradientButton: {
|
|
|
|
borderRadius: 10,
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: "gray",
|
|
|
|
borderStyle: "solid",
|
|
|
|
margin: 1,
|
|
|
|
width: 300,
|
|
|
|
marginVertical: 10,
|
|
|
|
marginHorizontal: 10,
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
paddingVertical: 30,
|
|
|
|
paddingHorizontal: 40,
|
|
|
|
}
|
|
|
|
});
|