From 7726adf8a35b9ab879381147ad84bd9b7e4ff270 Mon Sep 17 00:00:00 2001 From: Daniel Dunn Date: Thu, 3 Apr 2025 05:48:01 -0600 Subject: [PATCH] More units UI work --- src/components/input/NumericInputWithUnit.tsx | 34 +++++++++++++------ .../data/material_electrical_properties.ts | 14 ++++---- src/datatables/data/wire_gauge.ts | 24 ++++++------- .../generic-calc/data/wire_voltage_drop.ts | 2 +- src/pages/tools/number/generic-calc/index.tsx | 4 +++ 5 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/components/input/NumericInputWithUnit.tsx b/src/components/input/NumericInputWithUnit.tsx index 34077ee..9e6f97d 100644 --- a/src/components/input/NumericInputWithUnit.tsx +++ b/src/components/input/NumericInputWithUnit.tsx @@ -19,6 +19,8 @@ const siPrefixes: { [key: string]: number } = { export default function NumericInputWithUnit(props: { value: { value: number; unit: string }; + disabled?: boolean; + disableChangingUnit?: boolean; onOwnChange: (value: { value: number; unit: string }, ...baseProps) => void; defaultPrefix?: string; }) { @@ -31,6 +33,10 @@ export default function NumericInputWithUnit(props: { try { const kind = Qty(props.value.unit).kind(); const units = Qty.getUnits(kind); + if (!units.includes(props.value.unit)) { + units.push(props.value.unit); + } + setUnitOptions(units); } catch (error) { console.error('Invalid unit kind', error); @@ -102,9 +108,10 @@ export default function NumericInputWithUnit(props: { alignItems="center" style={{ minWidth: '20rem' }} > - + - - + ); diff --git a/src/datatables/data/material_electrical_properties.ts b/src/datatables/data/material_electrical_properties.ts index 912d016..246bfd9 100644 --- a/src/datatables/data/material_electrical_properties.ts +++ b/src/datatables/data/material_electrical_properties.ts @@ -1,14 +1,12 @@ export default { title: 'Material Electrical Properties', - columns: [ - { - resistivity_20c: { - title: 'Resistivity at 20°C', - type: 'number', - unit: 'Ω/m' - } + columns: { + resistivity_20c: { + title: 'Resistivity at 20°C', + type: 'number', + unit: 'Ω/m' } - ], + }, data: { Copper: { resistivity_20c: 1.68e-8 diff --git a/src/datatables/data/wire_gauge.ts b/src/datatables/data/wire_gauge.ts index 52e4536..13bbfa7 100644 --- a/src/datatables/data/wire_gauge.ts +++ b/src/datatables/data/wire_gauge.ts @@ -2,20 +2,18 @@ import type { DataTable } from '../types'; const data: DataTable = { title: 'American Wire Gauge', - columns: [ - { - diameter: { - title: 'Diameter', - type: 'number', - unit: 'mm' - }, - area: { - title: 'Area', - type: 'number', - unit: 'mm^2' - } + columns: { + diameter: { + title: 'Diameter', + type: 'number', + unit: 'mm' + }, + area: { + title: 'Area', + type: 'number', + unit: 'mm2' } - ], + }, data: { '0000 AWG': { diameter: 11.684 }, '000 AWG': { diameter: 10.405 }, diff --git a/src/pages/tools/number/generic-calc/data/wire_voltage_drop.ts b/src/pages/tools/number/generic-calc/data/wire_voltage_drop.ts index fabe807..2609b02 100644 --- a/src/pages/tools/number/generic-calc/data/wire_voltage_drop.ts +++ b/src/pages/tools/number/generic-calc/data/wire_voltage_drop.ts @@ -45,7 +45,7 @@ const voltagedropinwire: GenericCalcType = { { name: 'A', title: 'Wire Area', - unit: 'mm', + unit: 'mm2', default: 1 }, diff --git a/src/pages/tools/number/generic-calc/index.tsx b/src/pages/tools/number/generic-calc/index.tsx index 707d04a..1a559e2 100644 --- a/src/pages/tools/number/generic-calc/index.tsx +++ b/src/pages/tools/number/generic-calc/index.tsx @@ -252,6 +252,10 @@ export default async function makeTool( values.outputVariable === variable.name || valsBoundToPreset[variable.name] !== undefined } + disableChangingUnit={ + values.outputVariable === variable.name || + valsBoundToPreset[variable.name] !== undefined + } onOwnChange={(val) => updateVarField( variable.name,