mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
feat(profile): enter and show height in the selected unit
Height is a profile column, not a MeasurementType, so the display transform that carries the metric/imperial preference across every reading surface never reached it. Add the adapter that closes the gap. With imperial selected both entry surfaces render a feet + inches pair instead of a centimetres box; with metric selected the field is what it was. The adapter converts to canonical centimetres at the entry boundary, so storage, the wire, the Zod bound, and every consumer of the value stay unchanged. Imperial entry quantises to whole inches, which map to centimetres without a remainder, so save-then-reopen returns the typed pair. The offered feet window rounds inward against the canonical 50-300 window so a height the fields allow is never refused on save. The unit select shares the Settings card with the height field, so a flip re-expresses the in-flight draft through the new branch rather than stranding an empty field.
This commit is contained in:
1 parent
d0d880d4ba
commit
1b41126fb3
10 files changed
+417
-37
No files matched your search
@@ -0,0 +1,113 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* v1.32.30 — the height entry control, shared by the onboarding baseline
|
||||
* step and the Settings profile card.
|
||||
*
|
||||
* The two surfaces own their own label (they sit in different i18n
|
||||
* namespaces and different card shells), but the control below is the
|
||||
* one place that decides what a height field looks like under a
|
||||
* preference. Metric renders the single centimetres box the app has
|
||||
* always rendered; imperial renders the feet + inches pair, because a
|
||||
* single decimal-inches box is not how anyone states a height.
|
||||
*
|
||||
* The first input always carries the bare `idPrefix`, so a surrounding
|
||||
* `<Label htmlFor={idPrefix}>` resolves on both branches. Every limit
|
||||
* comes from the adapter, which rounds them inward against the server's
|
||||
* canonical window — see `src/lib/profile/height-unit-display.ts`.
|
||||
*/
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import type {
|
||||
HeightDraft,
|
||||
HeightUnitAdapter,
|
||||
} from "@/lib/profile/height-unit-display";
|
||||
|
||||
interface HeightFieldControlProps {
|
||||
/** Id of the first input; the inches box appends `-inches`. */
|
||||
idPrefix: string;
|
||||
adapter: HeightUnitAdapter;
|
||||
value: HeightDraft;
|
||||
onChange: (next: HeightDraft) => void;
|
||||
autoComplete?: string;
|
||||
enterKeyHint?: "next";
|
||||
}
|
||||
|
||||
export function HeightFieldControl({
|
||||
idPrefix,
|
||||
adapter,
|
||||
value,
|
||||
onChange,
|
||||
autoComplete,
|
||||
enterKeyHint,
|
||||
}: HeightFieldControlProps) {
|
||||
const { t } = useTranslations();
|
||||
const { bounds } = adapter;
|
||||
|
||||
if (!adapter.usesFeetInches) {
|
||||
return (
|
||||
<Input
|
||||
id={idPrefix}
|
||||
type="number"
|
||||
inputMode="decimal"
|
||||
enterKeyHint={enterKeyHint}
|
||||
value={value.cm}
|
||||
onChange={(e) => onChange({ ...value, cm: e.target.value })}
|
||||
placeholder="175"
|
||||
min={bounds.cm.min}
|
||||
max={bounds.cm.max}
|
||||
step={0.1}
|
||||
autoComplete={autoComplete}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
id={idPrefix}
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
enterKeyHint={enterKeyHint}
|
||||
value={value.feet}
|
||||
onChange={(e) => onChange({ ...value, feet: e.target.value })}
|
||||
placeholder="5"
|
||||
min={bounds.feet.min}
|
||||
max={bounds.feet.max}
|
||||
step={1}
|
||||
autoComplete={autoComplete}
|
||||
aria-label={t("common.heightFeet")}
|
||||
/>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="text-muted-foreground shrink-0 text-xs"
|
||||
>
|
||||
{t("common.feet")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
id={`${idPrefix}-inches`}
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
enterKeyHint={enterKeyHint}
|
||||
value={value.inches}
|
||||
onChange={(e) => onChange({ ...value, inches: e.target.value })}
|
||||
placeholder="9"
|
||||
min={bounds.inches.min}
|
||||
max={bounds.inches.max}
|
||||
step={1}
|
||||
autoComplete={autoComplete}
|
||||
aria-label={t("common.heightInches")}
|
||||
/>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="text-muted-foreground shrink-0 text-xs"
|
||||
>
|
||||
{t("common.inches")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user