2024-07-01 04:49:41 +02:00
|
|
|
import { MeasurementInput } from "./MeasurementInput";
|
|
|
|
import { area_t, dimensions_t } from "@/lib/product";
|
|
|
|
import { useState } from "react";
|
2024-07-01 21:23:45 +02:00
|
|
|
import { StyleSheet, 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-01 04:49:41 +02:00
|
|
|
}
|
|
|
|
|
2024-07-01 17:05:24 +02:00
|
|
|
export function AreaInput({onMeasurementSet, lengthLabel, widthLabel, defaultValue} : 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-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-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-01 04:49:41 +02:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)
|
2024-07-01 21:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
areaInputWrapper: {
|
|
|
|
flexDirection: "row"
|
|
|
|
}
|
|
|
|
})
|