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 | 179258x 20747x 20747x 20746x 20746x 20746x 20746x 20746x 20746x 13x 41492x 20746x 20725x 20725x 165994x 20726x 145076x | import SelectInput from "@/ahuora-design-system/inputs/SelectInput";
import { PropertyInfoRead } from "@/api/apiStore.gen";
import {
GetUnitDisplay,
GetUnitSet,
} from "../../../../../../data/UnitsLibrary";
export function UnitsDropdown({
property,
onUpdate,
disabled = false,
}: {
property: PropertyInfoRead;
onUpdate: (unit: string) => void;
disabled?: boolean;
}) {
const unitType = property.unitType;
const unitSet = GetUnitSet(unitType);
const fallbackUnitLabel = GetUnitDisplay(unitSet, property.unit ?? "");
const selectedUnit = property.unit || unitSet[0]?.value || fallbackUnitLabel;
const selectedUnitLabel = GetUnitDisplay(unitSet, selectedUnit);
const unitOptions =
unitSet.length > 0
? unitSet
: [
{
label: selectedUnitLabel,
value: selectedUnit,
},
];
const handleUnitChange = (unit: string) => {
onUpdate(unit);
};
if (unitType === "dimensionless") {
return null;
}
return (
<SelectInput
data={unitOptions.map((unit) => {
return {
label: unit.label,
value: unit.value,
};
})}
value={selectedUnit}
handleChange={handleUnitChange}
disabled={disabled}
ariaLabel={`${property.displayName}-unit`}
/>
);
}
|