2024-07-01 04:49:41 +02:00
|
|
|
import { MeasurementInput } from "./MeasurementInput";
|
2024-08-15 23:07:19 +02:00
|
|
|
import { area_t, dimensions_t } from "@/lib/dimensions";
|
2024-07-02 17:34:23 +02:00
|
|
|
import { Length } from "convert";
|
2024-07-01 04:49:41 +02:00
|
|
|
import { useState } from "react";
|
2024-07-02 17:34:23 +02:00
|
|
|
import { StyleSheet, Text, View } from "react-native";
|
2024-08-15 23:07:19 +02:00
|
|
|
import MeasurementUnitInput from "./MeasurementUnitInput";
|
|
|
|
import { useAppDispatch, useAppSelector } from "@/app/store";
|
|
|
|
import { selectPlywoodCalc } from "@/features/product/productSlice";
|
2024-07-01 04:49:41 +02:00
|
|
|
|
|
|
|
export type AreaInputProps = {
|
|
|
|
onMeasurementSet?: (area : dimensions_t) => any,
|
2024-07-01 17:05:24 +02:00
|
|
|
defaultValue?: area_t,
|
|
|
|
lengthLabel?: string,
|
|
|
|
widthLabel?: string,
|
2024-07-02 17:34:23 +02:00
|
|
|
units?: Length,
|
2024-07-01 04:49:41 +02:00
|
|
|
}
|
|
|
|
|
2024-07-02 17:34:23 +02:00
|
|
|
export function AreaInput({onMeasurementSet, lengthLabel, widthLabel, defaultValue, units} : AreaInputProps) {
|
2024-07-01 04:49:41 +02:00
|
|
|
|
2024-08-15 23:07:19 +02:00
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
defaultValue = defaultValue || {l: 0, w: 0, u: "ft"}
|
2024-07-02 17:34:23 +02:00
|
|
|
units = units || "ft"
|
2024-07-01 17:05:24 +02:00
|
|
|
|
|
|
|
const [area, setArea] = useState(defaultValue)
|
2024-07-01 04:49:41 +02:00
|
|
|
|
2024-08-15 23:07:19 +02:00
|
|
|
function doOnLengthSet(l: number) {
|
|
|
|
const a : area_t = { ...area, l };
|
|
|
|
setArea(a);
|
|
|
|
onMeasurementSet && onMeasurementSet(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
function doOnLengthUnitSet(u: Length) {
|
|
|
|
const a : area_t = { ...area, u };
|
|
|
|
setArea(a);
|
|
|
|
onMeasurementSet && onMeasurementSet(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
function doOnWidthSet(l: number) {
|
|
|
|
const a : area_t = { ...area, l };
|
|
|
|
setArea(a);
|
|
|
|
onMeasurementSet && onMeasurementSet(a);
|
2024-07-01 04:49:41 +02:00
|
|
|
}
|
|
|
|
|
2024-08-15 23:07:19 +02:00
|
|
|
function doOnWidthUnitSet(u: Length) {
|
|
|
|
const a : area_t = { ...area, u };
|
|
|
|
setArea(a);
|
|
|
|
onMeasurementSet && onMeasurementSet(a);
|
2024-07-01 04:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-07-01 21:23:45 +02:00
|
|
|
<View style={styles.areaInputWrapper}>
|
2024-08-15 23:07:19 +02:00
|
|
|
<MeasurementUnitInput
|
|
|
|
label="Length"
|
|
|
|
defaultValue={0}
|
|
|
|
defaultUnit={units}
|
2024-07-01 04:49:41 +02:00
|
|
|
onValueSet={doOnLengthSet}
|
2024-08-15 23:07:19 +02:00
|
|
|
onUnitSet={doOnLengthUnitSet}
|
|
|
|
aria-label="length"
|
|
|
|
/>
|
2024-07-02 17:34:23 +02:00
|
|
|
<Text style={{fontSize: 30,}} > x </Text>
|
2024-08-15 23:07:19 +02:00
|
|
|
<MeasurementUnitInput
|
|
|
|
label="Width"
|
|
|
|
defaultValue={0}
|
|
|
|
defaultUnit={units}
|
2024-07-01 04:49:41 +02:00
|
|
|
onValueSet={doOnWidthSet}
|
2024-08-15 23:07:19 +02:00
|
|
|
onUnitSet={doOnWidthUnitSet}
|
|
|
|
aria-label="width"
|
|
|
|
/>
|
2024-07-01 04:49:41 +02:00
|
|
|
</View>
|
|
|
|
)
|
2024-07-01 21:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
areaInputWrapper: {
|
2024-07-02 17:34:23 +02:00
|
|
|
flexDirection: "row",
|
|
|
|
verticalAlign: "middle",
|
2024-07-01 21:23:45 +02:00
|
|
|
}
|
|
|
|
})
|