Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import DebouncedInput from "@/ahuora-design-system/ui/debounced-input";
import {
PropertyInfoRead,
PropertyValueRead,
} from "@/api/apiStore.gen";
import { round_to_sf_dp } from "@/functions/roundNumber";
import { useMemo } from "react";
import { UnitsDropdown } from "./UnitsDropdown";
export interface NumericArgWithUnitProps {
property: PropertyInfoRead;
displayName?: string;
onUpdateValue: (value: string) => void;
onUpdateUnit: (unit: string) => void;
values: PropertyValueRead;
property_val_key: string;
}
// Simple numeric argument field: label + input + units (no DoF controls, no formulas, no units)
export function NumericArgWithUnit(props: NumericArgWithUnitProps) {
const displayName = props.displayName ?? props.property.displayName;
const fixed = ![undefined, null, ""].includes(props.values.value);
const roundedValue = useMemo(() => {
Iif (!fixed) return "";
const parsedValue = parseFloat(props.values.value as any);
return round_to_sf_dp(parsedValue);
}, [props.values.value]);
return (
<div className="w-full p-2 border rounded-lg my-1 bg-muted">
<div className="flex flex-row justify-between items-center">
<div className="flex items-center gap-1">
<p>{displayName}</p>
</div>
</div>
<div className="flex flex-col ap-2">
<div className="flex flex-row gap-2 h-full items-end">
<div className="flex flex-col w-full">
<DebouncedInput
onUpdate={(val) => props.onUpdateValue(val as string)}
value={roundedValue}
type="number"
style={{ width: "100%" }}
isFixed={fixed}
placeholder={"Enter a value..."}
aria-label={`inputField-${displayName}`}
className="bg-transparent"
/>
</div>
{props.property.displayName !== "Compounds" && (
<UnitsDropdown property={props.property} onUpdate={props.onUpdateUnit} />
)}
</div>
</div>
</div>
);
}
|