PliWould/components/ProductTile.tsx

85 lines
1.9 KiB
TypeScript
Raw Normal View History

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";
export type OnProductSelectedFunc = (product: Product) => any;
2024-06-27 23:31:59 +02:00
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;
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";
const BLUE_HILIGHT = "#caceff";
const BLUE = "#8b9cff";
const GRAY_HILIGHT = "#ffffff";
const GRAY = "#b1b1b1";
const activeColors = [BLUE_HILIGHT, BLUE, BLUE, BLUE];
const inactiveColors = [GRAY_HILIGHT, GRAY, GRAY, GRAY];
2024-07-01 04:49:41 +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
}
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,
}
});