Files
HealthLog/src/components/onboarding/choice-chip.tsx
T
Marc-André Bombeck ec82ad3a93 Carry the setup answers into the checklist, Settings and the module pages
The getting-started checklist reads the answers: a visit named within a
month adds a "prepare the visit" row that is done once one is on the
calendar, and the data-source row names the wearable that was chosen.
Its per-browser state moves to one module so the done screen, the skip
and Settings write the same keys.

Settings → Account gains the two ways back in: "Set up again" through
the restart route, which resets the ledger, keeps the answers as
prefill and touches no module; and "Show the checklist again", which
forgets what this browser hid.

A page whose module is off now answers with the shared notice and the
one action that helps, in one place for every module page: the shell
maps the route to the module through the navigation model's own gate,
so a page and its nav entry cannot disagree about which switch they
follow. And the tour's two dead stops get their anchors on the
integrations and health-record group headings.
2026-09-10 15:41:06 +02:00

83 lines
2.3 KiB
TypeScript

"use client";
import type { LucideIcon } from "lucide-react";
import { cn } from "@/lib/utils";
/**
* One answer chip of a setup question: a real radio or checkbox inside a
* label, so the browser owns selection, grouping and keyboard movement
* (arrow keys across a radio group, space on a checkbox), and the chip is
* only the paint.
*
* The input is visually hidden and the label carries the focus ring through
* `has-[:focus-visible]`, because a hidden control with no visible focus is
* how a keyboard user loses their place in a chip grid — the five-step
* wizard's picker had exactly that gap.
*/
export function ChoiceChip({
name,
value,
kind,
checked,
onChange,
label,
hint,
Icon,
}: {
name: string;
value: string;
kind: "single" | "multi";
checked: boolean;
onChange: (value: string) => void;
label: string;
hint?: string;
Icon?: LucideIcon;
}) {
return (
<label
className={cn(
"border-border bg-card flex min-h-11 cursor-pointer items-center gap-3 rounded-lg border p-3 text-left transition-colors duration-150 ease-out motion-reduce:transition-none",
"hover:border-primary/50",
"has-[:focus-visible]:ring-ring has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-offset-2",
checked && "border-primary bg-primary/5",
)}
data-slot="onboarding-choice"
data-value={value}
data-checked={checked}
>
<input
type={kind === "single" ? "radio" : "checkbox"}
name={name}
value={value}
checked={checked}
onChange={() => onChange(value)}
className="sr-only"
/>
{Icon ? (
<span
aria-hidden="true"
className={cn(
"flex size-9 shrink-0 items-center justify-center rounded-full transition-colors",
checked
? "bg-primary text-primary-foreground"
: "bg-muted text-muted-foreground",
)}
>
<Icon className="size-4" />
</span>
) : null}
<span className="min-w-0 flex-1">
<span className="text-foreground block text-sm leading-tight font-medium">
{label}
</span>
{hint ? (
<span className="text-muted-foreground mt-0.5 block text-xs">
{hint}
</span>
) : null}
</span>
</label>
);
}