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
|
|
|
|
2024-06-30 18:37:27 +02:00
|
|
|
export type ProductAttributeChangeFunc = (key: string, newValue: string) => any;
|
|
|
|
export type ProductAttributeDeleteFunc = (key: string) => any;
|
|
|
|
export type ChangeAttributeFunction = (oldKey : string, newKey : string) => any;
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-06-30 18:37:27 +02:00
|
|
|
export type ProductAttributeProps = {
|
|
|
|
attributeKey: string,
|
|
|
|
attributeValue: string,
|
|
|
|
onChangeAttributeKey?: ChangeAttributeFunction,
|
|
|
|
onChangeAttribute?: ProductAttributeChangeFunc,
|
|
|
|
onDelete?: ProductAttributeChangeFunc,
|
|
|
|
};
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-06-30 18:37:27 +02:00
|
|
|
export const ProductAttributeEditor = ({ attributeKey, attributeValue, onDelete, onChangeAttributeKey, onChangeAttribute }: ProductAttributeProps) => {
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-06-30 18:37:27 +02:00
|
|
|
const doChangeKey = (e: any) => {
|
|
|
|
onChangeAttributeKey && onChangeAttributeKey(attributeKey, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
const doChangeValue = (e: any) => {
|
|
|
|
onChangeAttribute && onChangeAttribute(attributeKey, e);
|
2024-06-27 23:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View>
|
2024-06-29 15:09:22 +02:00
|
|
|
<View style={styles.productAttributeRow}>
|
|
|
|
<TextInput
|
2024-06-30 18:37:27 +02:00
|
|
|
defaultValue={attributeKey}
|
|
|
|
onChangeText={doChangeKey}
|
|
|
|
style={styles.value}
|
|
|
|
aria-label="Edit Key"
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
defaultValue={attributeValue}
|
|
|
|
onChangeText={doChangeValue}
|
2024-06-29 15:09:22 +02:00
|
|
|
style={styles.value}
|
|
|
|
aria-label="Edit Value" />
|
2024-06-27 23:31:59 +02:00
|
|
|
<TouchableHighlight
|
2024-06-30 18:37:27 +02:00
|
|
|
onPress={() => onDelete && onDelete(attributeKey, attributeValue)}
|
2024-06-29 15:09:22 +02:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-06-29 15:09:22 +02:00
|
|
|
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
|
|
|
});
|