PliWould/components/MeasurementUnitInput.tsx

51 lines
1.1 KiB
TypeScript

import { dimensions_t, length_t } from "@/lib/dimensions";
import { Length } from "convert";
import { MeasurementInput, MeasurementInputProps } from "./MeasurementInput";
import UnitChooser, {
UnitChooserPropsBase,
} from "./UnitChooser";
import { StyleSheet, View } from "react-native";
export type MeasurementUnitInputProps = MeasurementInputProps &
UnitChooserPropsBase & {
defaultValue: number;
unitChoices?: Length[];
};
export default function MeasurementUnitInput({
onValueSet,
onUnitSet,
defaultValue,
unitChoices,
defaultUnit,
label,
units,
}: MeasurementUnitInputProps) {
return (
<View style={unitChoices ? styles.inputRow : styles.inputCol}>
<MeasurementInput
onValueSet={onValueSet}
defaultValue={defaultValue}
label={label}
units={units}
/>
{unitChoices && (
<UnitChooser
defaultUnit={defaultUnit}
choices={unitChoices}
onUnitSet={onUnitSet}
/>
)}
</View>
);
}
const styles = StyleSheet.create({
inputRow: {
flexDirection: "row",
},
inputCol: {
}
})