mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
Merge remote-tracking branch 'origin/main' into wip/v140-H
This commit is contained in:
commit
db9618ee7b
54 files changed
+2531
-531
No files matched your search
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* The cycle sheet's "add a custom symptom" popover offers the same icon
|
||||
* picker as the symptoms feature, and must look and behave the same: 44 px
|
||||
* targets on a phone, 36 px from `sm`, a translated name per icon.
|
||||
*
|
||||
* The popover portals and portals do not render server-side, so it is
|
||||
* replaced by pass-through wrappers; what is measured is the picker inside.
|
||||
*
|
||||
* Mutation check (run, seen red): put the cycle sheet's own inline picker
|
||||
* back (`size-7`, `aria-label={name}`) → this test goes red.
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { ReactNode } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
vi.mock("@/components/ui/popover", () => ({
|
||||
Popover: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
PopoverTrigger: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
PopoverContent: ({ children }: { children: ReactNode }) => (
|
||||
<div>{children}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("../use-cycle", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../use-cycle")>()),
|
||||
useCreateCustomSymptom: () => ({
|
||||
mutateAsync: vi.fn(),
|
||||
reset: vi.fn(),
|
||||
isPending: false,
|
||||
isError: false,
|
||||
error: null,
|
||||
}),
|
||||
}));
|
||||
|
||||
import { CUSTOM_SYMPTOM_ICON_ALLOWLIST } from "@/lib/cycle/custom-symptoms-shared";
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { AddSymptomChip } from "../log-day-sheet";
|
||||
|
||||
describe("cycle custom-symptom icon picker", () => {
|
||||
it("has 44 px targets on a phone and translated icon names", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="de">
|
||||
<AddSymptomChip onCreated={() => {}} />
|
||||
</I18nProvider>,
|
||||
);
|
||||
const buttons = html.match(/<button[^>]*role="radio"[^>]*>/g) ?? [];
|
||||
expect(buttons).toHaveLength(CUSTOM_SYMPTOM_ICON_ALLOWLIST.length);
|
||||
for (const button of buttons) {
|
||||
expect(button).toContain("size-11");
|
||||
expect(button).toContain("sm:size-9");
|
||||
expect(button).not.toMatch(/\bsize-7\b/);
|
||||
}
|
||||
expect(html).toContain('aria-label="Herzschlag"');
|
||||
expect(html).not.toContain('aria-label="HeartPulse"');
|
||||
});
|
||||
});
|
||||
@@ -48,7 +48,7 @@ import { useTranslations } from "@/lib/i18n/context";
|
||||
import { useUnitDisplay } from "@/hooks/use-unit-display";
|
||||
import { resolveIntlLocale } from "@/lib/format-locale";
|
||||
import type { Locale } from "@/lib/i18n/config";
|
||||
import { CUSTOM_SYMPTOM_ICON_ALLOWLIST } from "@/lib/cycle/custom-symptoms-shared";
|
||||
import { SymptomIconPicker } from "@/components/symptoms/symptom-icon-picker";
|
||||
import { FieldInfo } from "./field-info";
|
||||
import { CYCLE_SYMPTOM_CATALOG } from "./symptom-catalog";
|
||||
import { FLOW_HUE, PHASE_HUE } from "./phase-tokens";
|
||||
@@ -1519,7 +1519,11 @@ export function SymptomRow({
|
||||
* label + icon popover to mint a new custom symptom. Same height and shape as
|
||||
* a symptom row so it reads as part of the list, not a foreign button.
|
||||
*/
|
||||
function AddSymptomChip({ onCreated }: { onCreated: (key: string) => void }) {
|
||||
export function AddSymptomChip({
|
||||
onCreated,
|
||||
}: {
|
||||
onCreated: (key: string) => void;
|
||||
}) {
|
||||
const { t } = useTranslations();
|
||||
const create = useCreateCustomSymptom();
|
||||
const [openForm, setOpenForm] = useState(false);
|
||||
@@ -1594,34 +1598,11 @@ function AddSymptomChip({ onCreated }: { onCreated: (key: string) => void }) {
|
||||
<p className="text-xs font-medium">
|
||||
{t("cycle.symptom.custom.icon")}
|
||||
</p>
|
||||
<div
|
||||
className="flex flex-wrap gap-1.5"
|
||||
role="radiogroup"
|
||||
aria-label={t("cycle.symptom.custom.icon")}
|
||||
>
|
||||
{CUSTOM_SYMPTOM_ICON_ALLOWLIST.map((name) => {
|
||||
const IconC = customIcon(name);
|
||||
const selected = icon === name;
|
||||
return (
|
||||
<button
|
||||
key={name}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
aria-label={name}
|
||||
onClick={() => setIcon(name)}
|
||||
className={cn(
|
||||
"focus-visible:ring-ring/50 grid size-7 place-items-center rounded-md border transition-colors focus-visible:ring-2 focus-visible:outline-none",
|
||||
selected
|
||||
? "border-primary bg-primary/10 text-primary"
|
||||
: "border-border text-muted-foreground hover:bg-accent",
|
||||
)}
|
||||
>
|
||||
<IconC className="size-4" aria-hidden="true" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<SymptomIconPicker
|
||||
value={icon}
|
||||
onChange={setIcon}
|
||||
label={t("cycle.symptom.custom.icon")}
|
||||
/>
|
||||
</div>
|
||||
{limitReached ? (
|
||||
<p className="text-destructive text-sm" role="alert">
|
||||
|
||||
@@ -15,7 +15,10 @@ import {
|
||||
unitSkippedAnalytes,
|
||||
} from "../ocr-review-dialog";
|
||||
|
||||
const hookState = vi.hoisted(() => ({ extractPending: false }));
|
||||
const hookState = vi.hoisted(() => ({
|
||||
extractPending: false,
|
||||
runPhase: "idle" as "idle" | "running" | "waitingForWorker",
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/responsive-sheet", () => ({
|
||||
ResponsiveSheet: ({
|
||||
@@ -37,6 +40,7 @@ vi.mock("@/components/ui/responsive-sheet", () => ({
|
||||
vi.mock("../use-ocr-extract", () => ({
|
||||
useOcrExtract: () => ({
|
||||
isPending: hookState.extractPending,
|
||||
runPhase: hookState.runPhase,
|
||||
mutate: vi.fn(),
|
||||
reset: vi.fn(),
|
||||
}),
|
||||
@@ -174,6 +178,35 @@ describe("<OcrReviewDialog> document-reading consent", () => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* A lab scan's proposed rows live only in its run: nothing is stored until
|
||||
* the person confirms them here. So the waiting line must not promise that
|
||||
* the page can be left (the result would be lost, and a second scan costs
|
||||
* another rate slot). Mutation check: swap `aiRuns.backgroundScan` for
|
||||
* `aiRuns.backgroundDocument` in the dialog → both cases go red.
|
||||
*/
|
||||
describe("<OcrReviewDialog> background read", () => {
|
||||
afterEach(() => {
|
||||
hookState.extractPending = false;
|
||||
hookState.runPhase = "idle";
|
||||
});
|
||||
|
||||
it.each([
|
||||
["en", "With a slow model", "leave this page"],
|
||||
["de", "Mit einem langsamen Modell", "Seite verlassen"],
|
||||
] as const)(
|
||||
"(%s) says it reads in the background, never that the page can be left",
|
||||
(locale, expected, forbidden) => {
|
||||
hookState.extractPending = true;
|
||||
hookState.runPhase = "running";
|
||||
const html = render(locale);
|
||||
expect(html).toContain('data-slot="ocr-run-phase"');
|
||||
expect(html).toContain(expected);
|
||||
expect(html).not.toContain(forbidden);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("extractErrorMessage", () => {
|
||||
const t = (key: string) => key;
|
||||
const refusal = (errorCode: string, status = 403) =>
|
||||
|
||||
@@ -7,13 +7,16 @@
|
||||
* - drop the `resolvedAt === null` filter on the episodes → "offers no
|
||||
* episode selector when every episode is resolved" goes red;
|
||||
* - render the add chip unconditionally → "a delegate who may log but not
|
||||
* manage gets no add chip" goes red.
|
||||
* manage gets no add chip" goes red;
|
||||
* - drop the `definitions.isError` branch → "a failed read shows the error
|
||||
* row, not the empty hint" goes red (the empty hint renders instead).
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
const state = vi.hoisted(() => ({
|
||||
canManage: true,
|
||||
definitionsFailed: false,
|
||||
episodes: [] as Array<{
|
||||
id: string;
|
||||
label: string;
|
||||
@@ -34,30 +37,42 @@ vi.mock("@/components/illness/use-illness", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("../use-symptoms", () => ({
|
||||
useSymptomDefinitions: () => ({
|
||||
isLoading: false,
|
||||
data: {
|
||||
limit: 8,
|
||||
definitions: [
|
||||
{
|
||||
id: "d1",
|
||||
label: "Aura",
|
||||
icon: "Zap",
|
||||
sortOrder: 0,
|
||||
isActive: true,
|
||||
recent: { count30d: 0, maxIntensity30d: null, lastOccurredAt: null },
|
||||
useSymptomDefinitions: () =>
|
||||
state.definitionsFailed
|
||||
? { isLoading: false, isError: true, data: undefined, refetch: vi.fn() }
|
||||
: {
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
data: {
|
||||
limit: 8,
|
||||
definitions: [
|
||||
{
|
||||
id: "d1",
|
||||
label: "Aura",
|
||||
icon: "Zap",
|
||||
sortOrder: 0,
|
||||
isActive: true,
|
||||
recent: {
|
||||
count30d: 0,
|
||||
maxIntensity30d: null,
|
||||
lastOccurredAt: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "d2",
|
||||
label: "Headache",
|
||||
icon: "Brain",
|
||||
sortOrder: 1,
|
||||
isActive: true,
|
||||
recent: {
|
||||
count30d: 0,
|
||||
maxIntensity30d: null,
|
||||
lastOccurredAt: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "d2",
|
||||
label: "Headache",
|
||||
icon: "Brain",
|
||||
sortOrder: 1,
|
||||
isActive: true,
|
||||
recent: { count30d: 0, maxIntensity30d: null, lastOccurredAt: null },
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
useLogSymptomEvent: () => ({ mutateAsync: vi.fn(), isPending: false }),
|
||||
useCreateSymptomDefinition: () => ({
|
||||
mutateAsync: vi.fn(),
|
||||
@@ -111,4 +126,19 @@ describe("<SymptomEntryForm>", () => {
|
||||
];
|
||||
expect(render()).not.toContain("-episode");
|
||||
});
|
||||
|
||||
it("a failed read shows the error row, not the empty hint", () => {
|
||||
state.canManage = true;
|
||||
state.episodes = [];
|
||||
state.definitionsFailed = true;
|
||||
try {
|
||||
const html = render();
|
||||
expect(html).toContain('data-slot="query-error-row"');
|
||||
expect(html).toContain("load your symptoms");
|
||||
expect(html).not.toContain("first symptom");
|
||||
expect(html).not.toContain('data-testid="symptom-add-chip"');
|
||||
} finally {
|
||||
state.definitionsFailed = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Both symptom icon pickers (the add chip's popover and the edit sheet) share
|
||||
* one shape: 44 px targets on a phone, 36 px from `sm`, and a translated
|
||||
* accessible name per icon rather than the raw Lucide component name.
|
||||
*
|
||||
* The popover and the sheet portal, and portals do not render server-side,
|
||||
* so both are replaced by pass-through wrappers that render their children
|
||||
* inline; what is measured is the picker inside them.
|
||||
*
|
||||
* Mutation checks (each run, each seen red):
|
||||
* - put `size-7` back on the add chip's icon buttons → "the add chip's
|
||||
* icon targets" goes red;
|
||||
* - put `aria-label={name}` back on either picker → the label assertions
|
||||
* go red ("HeartPulse" is a raw name, "Heartbeat" its English label).
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { ReactNode } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
vi.mock("@/components/ui/popover", () => ({
|
||||
Popover: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
PopoverTrigger: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
PopoverContent: ({ children }: { children: ReactNode }) => (
|
||||
<div>{children}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/responsive-sheet", () => ({
|
||||
ResponsiveSheet: ({
|
||||
children,
|
||||
footer,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
footer?: ReactNode;
|
||||
}) => (
|
||||
<div>
|
||||
{children}
|
||||
{footer}
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("../use-symptoms", () => {
|
||||
const mutation = {
|
||||
mutateAsync: vi.fn(),
|
||||
reset: vi.fn(),
|
||||
isPending: false,
|
||||
isError: false,
|
||||
error: null,
|
||||
};
|
||||
return {
|
||||
useCreateSymptomDefinition: () => mutation,
|
||||
useUpdateSymptomDefinition: () => mutation,
|
||||
useUpdateSymptomEvent: () => mutation,
|
||||
};
|
||||
});
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { SYMPTOM_ICON_ALLOWLIST } from "@/lib/symptoms/shared";
|
||||
import { AddSymptomChip } from "../add-symptom-chip";
|
||||
import { EditSymptomDefinitionSheet } from "../symptom-edit-sheets";
|
||||
|
||||
function iconButtons(html: string): string[] {
|
||||
return html.match(/<button[^>]*role="radio"[^>]*>/g) ?? [];
|
||||
}
|
||||
|
||||
function assertPicker(html: string) {
|
||||
const buttons = iconButtons(html);
|
||||
expect(buttons).toHaveLength(SYMPTOM_ICON_ALLOWLIST.length);
|
||||
for (const button of buttons) {
|
||||
expect(button).toContain("size-11");
|
||||
expect(button).toContain("sm:size-9");
|
||||
expect(button).not.toMatch(/\bsize-7\b/);
|
||||
}
|
||||
expect(html).toContain('aria-label="Heartbeat"');
|
||||
expect(html).toContain('aria-label="Low battery"');
|
||||
expect(html).not.toContain('aria-label="HeartPulse"');
|
||||
expect(html).not.toContain('aria-label="BatteryLow"');
|
||||
}
|
||||
|
||||
describe("symptom icon pickers", () => {
|
||||
it("the add chip's icon targets are 44 px on a phone, with translated names", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<AddSymptomChip onCreated={() => {}} />
|
||||
</I18nProvider>,
|
||||
);
|
||||
assertPicker(html);
|
||||
});
|
||||
|
||||
it("the edit sheet's picker matches, with translated names", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<EditSymptomDefinitionSheet
|
||||
definition={{
|
||||
id: "d1",
|
||||
label: "Aura",
|
||||
icon: "Zap",
|
||||
sortOrder: 0,
|
||||
isActive: true,
|
||||
recent: {
|
||||
count30d: 0,
|
||||
maxIntensity30d: null,
|
||||
lastOccurredAt: null,
|
||||
},
|
||||
}}
|
||||
onClose={() => {}}
|
||||
/>
|
||||
</I18nProvider>,
|
||||
);
|
||||
assertPicker(html);
|
||||
});
|
||||
|
||||
it("every allowlisted icon has a label in the English bundle", async () => {
|
||||
const en = (await import("../../../../messages/en.json")).default as {
|
||||
symptoms: { icons: Record<string, string> };
|
||||
};
|
||||
for (const name of SYMPTOM_ICON_ALLOWLIST) {
|
||||
expect(en.symptoms.icons[name], name).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -19,10 +19,8 @@ import {
|
||||
} from "@/components/ui/popover";
|
||||
import { ApiError } from "@/lib/api/api-fetch";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { SYMPTOM_ICON_ALLOWLIST } from "@/lib/symptoms/shared";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import { symptomIcon } from "./symptom-icons";
|
||||
import { SymptomIconPicker } from "./symptom-icon-picker";
|
||||
import { useCreateSymptomDefinition } from "./use-symptoms";
|
||||
|
||||
export function AddSymptomChip({
|
||||
@@ -101,34 +99,11 @@ export function AddSymptomChip({
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<p className="text-xs font-medium">{t("symptoms.iconLabel")}</p>
|
||||
<div
|
||||
className="flex flex-wrap gap-1.5"
|
||||
role="radiogroup"
|
||||
aria-label={t("symptoms.iconLabel")}
|
||||
>
|
||||
{SYMPTOM_ICON_ALLOWLIST.map((name) => {
|
||||
const IconC = symptomIcon(name);
|
||||
const selected = icon === name;
|
||||
return (
|
||||
<button
|
||||
key={name}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
aria-label={name}
|
||||
onClick={() => setIcon(name)}
|
||||
className={cn(
|
||||
"focus-visible:ring-ring/50 grid size-7 place-items-center rounded-md border transition-colors focus-visible:ring-2 focus-visible:outline-none",
|
||||
selected
|
||||
? "border-primary bg-primary/10 text-primary"
|
||||
: "border-border text-muted-foreground hover:bg-accent",
|
||||
)}
|
||||
>
|
||||
<IconC className="size-4" aria-hidden="true" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<SymptomIconPicker
|
||||
value={icon}
|
||||
onChange={setIcon}
|
||||
label={t("symptoms.iconLabel")}
|
||||
/>
|
||||
</div>
|
||||
{create.isError ? (
|
||||
<p className="text-destructive text-sm" role="alert">
|
||||
|
||||
@@ -18,15 +18,13 @@ import { SliderField } from "@/components/ui/slider";
|
||||
import { localizedApiError } from "@/lib/api/localized-error";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import {
|
||||
SYMPTOM_ICON_ALLOWLIST,
|
||||
SYMPTOM_INTENSITY_MAX,
|
||||
SYMPTOM_INTENSITY_MIN,
|
||||
type SymptomDefinitionDTO,
|
||||
type SymptomEventDTO,
|
||||
} from "@/lib/symptoms/shared";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import { symptomIcon } from "./symptom-icons";
|
||||
import { SymptomIconPicker } from "./symptom-icon-picker";
|
||||
import {
|
||||
useUpdateSymptomDefinition,
|
||||
useUpdateSymptomEvent,
|
||||
@@ -227,34 +225,11 @@ export function EditSymptomDefinitionSheet({
|
||||
</FieldGroup>
|
||||
<div className="space-y-2">
|
||||
<Label>{t("symptoms.iconLabel")}</Label>
|
||||
<div
|
||||
className="flex flex-wrap gap-1.5"
|
||||
role="radiogroup"
|
||||
aria-label={t("symptoms.iconLabel")}
|
||||
>
|
||||
{SYMPTOM_ICON_ALLOWLIST.map((name) => {
|
||||
const IconC = symptomIcon(name);
|
||||
const selected = icon === name;
|
||||
return (
|
||||
<button
|
||||
key={name}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
aria-label={name}
|
||||
onClick={() => setIcon(name)}
|
||||
className={cn(
|
||||
"focus-visible:ring-ring/50 grid size-11 place-items-center rounded-md border transition-colors focus-visible:ring-2 focus-visible:outline-none sm:size-9",
|
||||
selected
|
||||
? "border-primary bg-primary/10 text-primary"
|
||||
: "border-border text-muted-foreground hover:bg-accent",
|
||||
)}
|
||||
>
|
||||
<IconC className="size-4" aria-hidden="true" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<SymptomIconPicker
|
||||
value={icon}
|
||||
onChange={setIcon}
|
||||
label={t("symptoms.iconLabel")}
|
||||
/>
|
||||
</div>
|
||||
{error ? (
|
||||
<p role="alert" className="text-destructive text-sm">
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
import { FieldGroup } from "@/components/ui/field-group";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { QueryErrorRow } from "@/components/ui/query-error-row";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -210,59 +211,70 @@ export function SymptomEntryForm({
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<Label id={symptomGroupId}>{t("symptoms.entry.symptom")}</Label>
|
||||
<div
|
||||
role="radiogroup"
|
||||
aria-labelledby={symptomGroupId}
|
||||
aria-describedby={
|
||||
symptomError ? `${symptomGroupId}-error` : undefined
|
||||
}
|
||||
className="flex flex-wrap gap-2"
|
||||
>
|
||||
{list.map((definition) => {
|
||||
const selected = definitionId === definition.id;
|
||||
return (
|
||||
<button
|
||||
key={definition.id}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
data-testid="symptom-chip"
|
||||
onClick={() => {
|
||||
setDefinitionId(selected ? null : definition.id);
|
||||
setSymptomError(null);
|
||||
}}
|
||||
className={cn(
|
||||
"focus-visible:ring-ring/50 inline-flex min-h-11 items-center gap-2 rounded-full border px-3 py-1.5 text-sm transition-colors focus-visible:ring-2 focus-visible:outline-none sm:min-h-8",
|
||||
selected
|
||||
? "border-primary bg-primary/10 text-foreground"
|
||||
: "border-border text-foreground hover:bg-accent",
|
||||
)}
|
||||
>
|
||||
<SymptomIcon name={definition.icon} className="size-4" />
|
||||
{definition.label ?? t("symptoms.unreadableLabel")}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{canDefine && !atLimit ? (
|
||||
<AddSymptomChip
|
||||
onCreated={(id) => {
|
||||
setDefinitionId(id);
|
||||
setSymptomError(null);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
{list.length === 0 && !definitions.isLoading ? (
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{canDefine
|
||||
? t("symptoms.entry.emptyHint")
|
||||
: t("symptoms.entry.emptyHintNoManage")}
|
||||
</p>
|
||||
) : atLimit && canDefine ? (
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{t("symptoms.entry.limitHint", { limit })}
|
||||
</p>
|
||||
) : null}
|
||||
{definitions.isError ? (
|
||||
// A failed read is not an empty list: the empty hint would invite
|
||||
// the person to define a symptom they may already have.
|
||||
<QueryErrorRow
|
||||
message={t("symptoms.section.loadError")}
|
||||
onRetry={() => void definitions.refetch()}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
role="radiogroup"
|
||||
aria-labelledby={symptomGroupId}
|
||||
aria-describedby={
|
||||
symptomError ? `${symptomGroupId}-error` : undefined
|
||||
}
|
||||
className="flex flex-wrap gap-2"
|
||||
>
|
||||
{list.map((definition) => {
|
||||
const selected = definitionId === definition.id;
|
||||
return (
|
||||
<button
|
||||
key={definition.id}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
data-testid="symptom-chip"
|
||||
onClick={() => {
|
||||
setDefinitionId(selected ? null : definition.id);
|
||||
setSymptomError(null);
|
||||
}}
|
||||
className={cn(
|
||||
"focus-visible:ring-ring/50 inline-flex min-h-11 items-center gap-2 rounded-full border px-3 py-1.5 text-sm transition-colors focus-visible:ring-2 focus-visible:outline-none sm:min-h-8",
|
||||
selected
|
||||
? "border-primary bg-primary/10 text-foreground"
|
||||
: "border-border text-foreground hover:bg-accent",
|
||||
)}
|
||||
>
|
||||
<SymptomIcon name={definition.icon} className="size-4" />
|
||||
{definition.label ?? t("symptoms.unreadableLabel")}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{canDefine && !atLimit ? (
|
||||
<AddSymptomChip
|
||||
onCreated={(id) => {
|
||||
setDefinitionId(id);
|
||||
setSymptomError(null);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
{list.length === 0 && !definitions.isLoading ? (
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{canDefine
|
||||
? t("symptoms.entry.emptyHint")
|
||||
: t("symptoms.entry.emptyHintNoManage")}
|
||||
</p>
|
||||
) : atLimit && canDefine ? (
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{t("symptoms.entry.limitHint", { limit })}
|
||||
</p>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
{symptomError ? (
|
||||
<p
|
||||
id={`${symptomGroupId}-error`}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* The icon picker a person-named symptom is given an icon with. One source for
|
||||
* the three places that offer it (the symptoms add chip, the symptom edit
|
||||
* sheet, and the cycle sheet's custom-symptom popover), which all draw from
|
||||
* the same allowlist: 44 px targets on a phone, 36 px from `sm`, and each icon
|
||||
* named in the reader's language rather than by its Lucide component name.
|
||||
*/
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { SYMPTOM_ICON_ALLOWLIST } from "@/lib/symptoms/shared";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import { symptomIcon } from "./symptom-icons";
|
||||
|
||||
export function SymptomIconPicker({
|
||||
value,
|
||||
onChange,
|
||||
label,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (name: string) => void;
|
||||
/** The radiogroup's accessible name (the visible field label). */
|
||||
label: string;
|
||||
}) {
|
||||
const { t } = useTranslations();
|
||||
return (
|
||||
<div
|
||||
className="flex flex-wrap gap-1.5"
|
||||
role="radiogroup"
|
||||
aria-label={label}
|
||||
>
|
||||
{SYMPTOM_ICON_ALLOWLIST.map((name) => {
|
||||
const IconC = symptomIcon(name);
|
||||
const selected = value === name;
|
||||
return (
|
||||
<button
|
||||
key={name}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
aria-label={t(`symptoms.icons.${name}`)}
|
||||
onClick={() => onChange(name)}
|
||||
className={cn(
|
||||
"focus-visible:ring-ring/50 grid size-11 place-items-center rounded-md border transition-colors focus-visible:ring-2 focus-visible:outline-none sm:size-9",
|
||||
selected
|
||||
? "border-primary bg-primary/10 text-primary"
|
||||
: "border-border text-muted-foreground hover:bg-accent",
|
||||
)}
|
||||
>
|
||||
<IconC className="size-4" aria-hidden="true" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user