mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
v1.4 foundation: UI guidelines, primitives, AI test fix, autofill hardening (#122)
* docs(ui): add UI guidelines as single source of truth + shadcn MCP server - `docs/ui-guidelines.md` lays out Dracula tokens, spacing, typography, component picks (button/input/dialog/sheet decision tree), layout rules (settings split target, dashboard one-row), accessibility baseline (WCAG 2.1 AA + axe-core in CI), the autofill / honeypot pattern for measurement forms, and a reusable "Test button" UX for every integration. New components in v1.4 reference this doc. - `.mcp.json` wires the official `shadcn` MCP server so the design system can be browsed and components installed without leaving the editor. - Adds `@vitest/coverage-v8` to dev dependencies — `pnpm test --coverage` now reports real per-file coverage (the v1.4 cycle uses this to lift critical-path coverage). Co-Authored-By: Marc-André Bombeck <noreply@anthropic.com> * fix(settings/ai): connection-test honours the unsaved provider selection Changing the AI provider in /settings, then clicking "Verbindung testen" without saving first, used to silently run the test against the *saved* provider instead — so the result felt unrelated to what the user had on screen. This often surfaced as a confusing OK / failure depending on whichever provider had previously been persisted. The test endpoint now accepts an optional JSON body that mirrors the form fields (provider, model, baseUrl, anthropicKey, localKey). When present, the server resolves a transient provider from those values — falling back to the persisted, encrypted credentials per field, so a user with a stored Anthropic key can swap models in the dropdown without re-typing the key. Plaintext keys never persist; the existing SSRF guard for the Local provider's base URL is reused, the existing rate limit (5/min) and the V3 error-leak shielding stay in place. Empty body keeps the previous behaviour for any other caller. Tests cover the new override path (provider forwarded, unknown provider rejected with 422, empty body uses persisted config, config errors surface the resolver's status). Whitespace in `src/app/settings/page.tsx` is reformatted by Prettier as a side-effect; logic touches only the AI section. Co-Authored-By: Marc-André Bombeck <noreply@anthropic.com> * feat(ui): add Skeleton and EmptyState primitives Two pieces every page in v1.4 needs and the codebase didn't have: - `<Skeleton>` — a presentation `<div>` with the standard pulse animation, `aria-hidden`, and `motion-reduce:animate-none`. Used to shape the page while data loads instead of dropping a spinner. The visible layout no longer jumps when the first measurement arrives. - `<EmptyState>` — the shape every list, tile, and chart panel reaches for when it has no data: optional icon, title, description, primary action; `card` (default) and `plain` variants; `default`/`compact` density. Lives inside an `aria-live="polite"` region so screen readers announce the message and its action. Tests cover screen-reader semantics, prettier-merged class names, density/variant switches. These two land first because the v1.4 pages — the split settings sections, the new dashboard hero, the redesigned admin status grid — all assume the primitives exist. The patterns are documented in `docs/ui-guidelines.md` §4.1–4.2. Co-Authored-By: Marc-André Bombeck <noreply@anthropic.com> * fix(ui): block password-manager autofill on health-data inputs by default Browsers and password managers were happily autofilling the user's account credentials into measurement, medication, mood, and AI-token fields whenever those forms didn't explicitly set `autoComplete`. The codebase had zero `autoComplete` attributes across the data-entry surfaces, so this happened often enough to be both a UX papercut (account password landing in a "Notiz" field) and a real privacy issue (secrets persisting through CSV/JSON export). The base `<Input>` primitive now: - Defaults `autoComplete` to `"off"` when the caller doesn't supply a value. - Adds `data-lpignore="true"` and `data-1p-ignore="true"` whenever autoComplete resolves to `"off"`, so LastPass and 1Password skip the field too. - Keeps the password manager active for any form that already passes a semantic `autoComplete` (`"username"`, `"email"`, `"current-password"`, `"new-password"`) — the existing login, register, and AI-key inputs continue to work unchanged. Tests cover the three meaningful states (default off, explicit semantic value, login-flow `username`). Co-Authored-By: Marc-André Bombeck <noreply@anthropic.com> --------- Co-authored-by: Marc-André Bombeck <noreply@anthropic.com>
This commit is contained in:
1 parent
98a57eb786
commit
359d4d19cc
14 files changed
+1589
-392
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { EmptyState } from "../empty-state";
|
||||
|
||||
describe("<EmptyState>", () => {
|
||||
it("renders title, description, and action inside a polite live region", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<EmptyState
|
||||
title="Noch keine Messungen"
|
||||
description="Lege deine erste Messung an."
|
||||
action={<button type="button">Messung anlegen</button>}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("Noch keine Messungen");
|
||||
expect(html).toContain("Lege deine erste Messung an.");
|
||||
expect(html).toContain("Messung anlegen");
|
||||
expect(html).toContain('role="status"');
|
||||
expect(html).toContain('aria-live="polite"');
|
||||
});
|
||||
|
||||
it("hides the decorative icon from assistive tech", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<EmptyState icon={<svg data-testid="icon" />} title="leer" />,
|
||||
);
|
||||
// The icon's wrapper carries aria-hidden so the icon doesn't
|
||||
// double-announce alongside the title.
|
||||
expect(html).toMatch(/aria-hidden="true"[^>]*>[^<]*<svg/);
|
||||
});
|
||||
|
||||
it("compact variant tightens spacing", () => {
|
||||
const def = renderToStaticMarkup(<EmptyState title="default" />);
|
||||
const compact = renderToStaticMarkup(
|
||||
<EmptyState title="compact" size="compact" />,
|
||||
);
|
||||
expect(def).toContain("py-8");
|
||||
expect(compact).toContain("py-4");
|
||||
expect(compact).not.toContain("py-8");
|
||||
});
|
||||
|
||||
it("plain variant drops the dashed wrapper", () => {
|
||||
const card = renderToStaticMarkup(<EmptyState title="x" />);
|
||||
const plain = renderToStaticMarkup(
|
||||
<EmptyState title="x" variant="plain" />,
|
||||
);
|
||||
expect(card).toContain("border-dashed");
|
||||
expect(plain).not.toContain("border-dashed");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { Input } from "../input";
|
||||
|
||||
describe("<Input>", () => {
|
||||
it("defaults autoComplete to off and tells password managers to skip", () => {
|
||||
const html = renderToStaticMarkup(<Input id="weight" />);
|
||||
expect(html).toContain('autoComplete="off"');
|
||||
expect(html).toContain('data-lpignore="true"');
|
||||
expect(html).toContain('data-1p-ignore="true"');
|
||||
});
|
||||
|
||||
it("respects an explicit autoComplete value and drops the ignore attrs", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<Input id="email" type="email" autoComplete="email" />,
|
||||
);
|
||||
expect(html).toContain('autoComplete="email"');
|
||||
expect(html).not.toContain('data-lpignore="true"');
|
||||
expect(html).not.toContain('data-1p-ignore="true"');
|
||||
});
|
||||
|
||||
it("explicit autoComplete=username keeps password manager active for login flows", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<Input id="username" autoComplete="username" />,
|
||||
);
|
||||
expect(html).toContain('autoComplete="username"');
|
||||
expect(html).not.toContain("lpignore");
|
||||
expect(html).not.toContain("1p-ignore");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { Skeleton } from "../skeleton";
|
||||
|
||||
describe("<Skeleton>", () => {
|
||||
it("renders a presentation node so screen readers skip it", () => {
|
||||
const html = renderToStaticMarkup(<Skeleton className="h-4 w-32" />);
|
||||
expect(html).toContain('role="presentation"');
|
||||
expect(html).toContain('aria-hidden="true"');
|
||||
});
|
||||
|
||||
it("preserves caller classes alongside the pulse animation", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<Skeleton className="h-8 rounded-full" />,
|
||||
);
|
||||
// The pulse class drives the visual shimmer; honour reduce-motion.
|
||||
expect(html).toContain("animate-pulse");
|
||||
expect(html).toContain("motion-reduce:animate-none");
|
||||
// Caller's classes should survive the merge.
|
||||
expect(html).toContain("h-8");
|
||||
expect(html).toContain("rounded-full");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,118 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* Reusable empty-state for lists, tiles, and chart panels that have no
|
||||
* data yet. Always pair an icon, a one-sentence explanation, and a
|
||||
* single primary action. Mounts inside the same container the loaded
|
||||
* UI uses so the layout does not shift on first data.
|
||||
*
|
||||
* Pattern (per `docs/ui-guidelines.md` §4.2):
|
||||
*
|
||||
* <EmptyState
|
||||
* icon={<Plus className="size-6" />}
|
||||
* title={t("empty.measurements.title")}
|
||||
* description={t("empty.measurements.description")}
|
||||
* action={<Button>{t("empty.measurements.add")}</Button>}
|
||||
* />
|
||||
*/
|
||||
export interface EmptyStateProps extends Omit<
|
||||
React.HTMLAttributes<HTMLDivElement>,
|
||||
"title"
|
||||
> {
|
||||
icon?: React.ReactNode;
|
||||
title: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
action?: React.ReactNode;
|
||||
/**
|
||||
* `"card"` (default) wraps the empty-state in a bordered surface so
|
||||
* it sits visually inside a list/tile.
|
||||
* `"plain"` renders inline without the wrapper — for use inside
|
||||
* chart panels that already have their own card.
|
||||
*/
|
||||
variant?: "card" | "plain";
|
||||
/**
|
||||
* Compact density for use inside tiles or table-row empty rows.
|
||||
*/
|
||||
size?: "default" | "compact";
|
||||
}
|
||||
|
||||
function EmptyState({
|
||||
icon,
|
||||
title,
|
||||
description,
|
||||
action,
|
||||
variant = "card",
|
||||
size = "default",
|
||||
className,
|
||||
...props
|
||||
}: EmptyStateProps) {
|
||||
const inner = (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col items-center justify-center text-center",
|
||||
size === "compact" ? "gap-2 py-4" : "gap-3 py-8",
|
||||
)}
|
||||
>
|
||||
{icon ? (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"text-muted-foreground bg-muted/60 flex items-center justify-center rounded-full",
|
||||
size === "compact" ? "size-8 p-1.5" : "size-12 p-2.5",
|
||||
)}
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="space-y-1">
|
||||
<p
|
||||
className={cn(
|
||||
"font-medium",
|
||||
size === "compact" ? "text-sm" : "text-base",
|
||||
)}
|
||||
>
|
||||
{title}
|
||||
</p>
|
||||
{description ? (
|
||||
<p className="text-muted-foreground max-w-xs text-sm">
|
||||
{description}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
{action ? <div className="mt-1">{action}</div> : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
if (variant === "plain") {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-state"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className={cn("w-full", className)}
|
||||
{...props}
|
||||
>
|
||||
{inner}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-state"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className={cn(
|
||||
"border-border bg-card rounded-lg border border-dashed",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{inner}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export { EmptyState };
|
||||
@@ -2,11 +2,40 @@ import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
/**
|
||||
* Base input primitive.
|
||||
*
|
||||
* v1.4 hardening: defaults `autoComplete` to `"off"` and tells
|
||||
* LastPass / 1Password to skip the field when the caller does not
|
||||
* opt in to a semantic autocomplete value. HealthLog is a health-data
|
||||
* app — letting browsers / password managers autofill measurement,
|
||||
* medication, mood, and AI-token inputs with the user's last-saved
|
||||
* email or account password is at best confusing and at worst leaks
|
||||
* credentials into a free-text field that gets persisted server-side.
|
||||
*
|
||||
* Auth and profile forms (login, register, change-email) keep working
|
||||
* because they already pass an explicit `autoComplete` value —
|
||||
* `"username"`, `"email"`, `"current-password"`, `"new-password"`. When
|
||||
* `autoComplete` is anything other than `"off"`, the LastPass /
|
||||
* 1Password ignore attrs are dropped so password managers fill the
|
||||
* field normally.
|
||||
*/
|
||||
function Input({
|
||||
className,
|
||||
type,
|
||||
autoComplete,
|
||||
...props
|
||||
}: React.ComponentProps<"input">) {
|
||||
const resolvedAutoComplete = autoComplete ?? "off";
|
||||
const skipAutofill = resolvedAutoComplete === "off";
|
||||
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
autoComplete={resolvedAutoComplete}
|
||||
data-lpignore={skipAutofill ? "true" : undefined}
|
||||
data-1p-ignore={skipAutofill ? "true" : undefined}
|
||||
className={cn(
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* Pulsing placeholder used while data is loading. Wrap text-equivalent
|
||||
* shapes so the page does not jump when real content arrives. Honours
|
||||
* `prefers-reduced-motion` automatically because Tailwind's
|
||||
* `animate-pulse` is disabled by `motion-reduce:animate-none`.
|
||||
*
|
||||
* Pattern: render the same layout the loaded UI will render, with each
|
||||
* dynamic block replaced by a `<Skeleton className="h-X w-Y" />`.
|
||||
*/
|
||||
function Skeleton({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="skeleton"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"bg-muted/60 animate-pulse rounded-md motion-reduce:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Skeleton };
|
||||
Reference in new issue
Block a user