2024-07-01 04:49:41 +02:00
|
|
|
import { MeasurementInput } from "./MeasurementInput";
|
|
|
|
import { area_t, dimensions_t } from "@/lib/product";
|
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-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-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
|
|
|
|
|
|
|
function doOnLengthSet(measurement : dimensions_t) {
|
|
|
|
setArea({
|
|
|
|
...area,
|
|
|
|
l: measurement.l
|
|
|
|
});
|
2024-07-01 17:05:24 +02:00
|
|
|
onMeasurementSet && onMeasurementSet({
|
|
|
|
...area,
|
|
|
|
l: measurement.l
|
|
|
|
});
|
2024-07-01 04:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function doOnWidthSet(measurement : dimensions_t) {
|
|
|
|
setArea({
|
|
|
|
...area,
|
|
|
|
w: measurement.l
|
|
|
|
});
|
2024-07-01 17:05:24 +02:00
|
|
|
onMeasurementSet && onMeasurementSet({
|
|
|
|
...area,
|
|
|
|
w: measurement.l
|
|
|
|
});
|
2024-07-01 04:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-07-01 21:23:45 +02:00
|
|
|
<View style={styles.areaInputWrapper}>
|
2024-07-01 04:49:41 +02:00
|
|
|
<MeasurementInput
|
2024-07-01 21:23:45 +02:00
|
|
|
defaultValue={{l: area.l, u: area.u}}
|
2024-07-01 04:49:41 +02:00
|
|
|
onValueSet={doOnLengthSet}
|
2024-07-01 17:05:24 +02:00
|
|
|
label={lengthLabel}
|
2024-07-02 17:34:23 +02:00
|
|
|
units={units}
|
2024-07-01 04:49:41 +02:00
|
|
|
/>
|
2024-07-02 17:34:23 +02:00
|
|
|
<Text style={{fontSize: 30,}} > x </Text>
|
2024-07-01 04:49:41 +02:00
|
|
|
<MeasurementInput
|
2024-07-01 21:23:45 +02:00
|
|
|
defaultValue={{l: area.w, u: area.u}}
|
2024-07-01 04:49:41 +02:00
|
|
|
onValueSet={doOnWidthSet}
|
2024-07-01 17:05:24 +02:00
|
|
|
label={widthLabel}
|
2024-07-02 17:34:23 +02:00
|
|
|
units={units}
|
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
|
|
|
}
|
|
|
|
})
|