PliWould/components/ProductAttributeEditor.tsx

55 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-06-27 23:31:59 +02:00
import { Product } from "@/lib/product";
import Ionicons from "@expo/vector-icons/Ionicons";
import React from "react";
2024-06-28 04:00:29 +02:00
import { useState } from "react";
import { StyleSheet, Text, TextInput, TouchableHighlight, View } from "react-native";
2024-06-27 23:31:59 +02:00
export type ProductAttributeChangeFunc = (product_id: string, key: string, newValue: string) => any;
export type ProductAttributeDeleteFunc = (product_id: string, key: string) => any;
2024-06-28 04:00:29 +02:00
export type ProductAttributeProps = { product: Product, attributeKey: string, attributeValue: string, onChange?: ProductAttributeChangeFunc, onDelete?: ProductAttributeChangeFunc, };
2024-06-27 23:31:59 +02:00
export const ProductAttributeEditor = ({ product, attributeKey: key, attributeValue: value, onDelete, onChange }: ProductAttributeProps) => {
2024-06-27 23:31:59 +02:00
const [doEdit, setDoEdit] = useState(true);
const [newValue, setNewValue] = useState(value);
2024-06-28 04:00:29 +02:00
const doChange = (e: any) => {
setNewValue(e);
onChange && onChange(product.id, key, e);
2024-06-27 23:31:59 +02:00
}
return (
<View>
<View style={styles.productAttributeRow}>
<Text style={styles.key}>{key}</Text>
<TextInput
value={newValue}
onChangeText={doChange}
style={styles.value}
aria-label="Edit Value" />
2024-06-27 23:31:59 +02:00
<TouchableHighlight
onPress={() => onDelete && onDelete(product.id, key, value)}
aria-label="Delete Attribute"
style={{ backgroundColor: "darkred", borderRadius: 5, margin: 5, padding: 5, }}>
<Ionicons name="trash-bin-outline" size={30} color={"white"} />
2024-06-27 23:31:59 +02:00
</TouchableHighlight>
</View>
</View>
)
}
const styles = StyleSheet.create({
productAttributeRow: {
flexDirection: "row",
},
key: {
flex: 1,
},
value: {
flex: 1,
borderWidth: 1,
borderColor: "grey",
borderStyle: "solid",
padding: 10
}
2024-06-27 23:31:59 +02:00
});