mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
- Resurface the selected hero score rings on the Today hero: the Settings picker's selection and drag order render again as a calm ring cluster beneath the health ring, each ring in its wellness hue, flat-painted, and linking to its existing detail surface (score anatomy pages, medications). The health ring now opens the Insights overview like its cluster siblings. Empty selection keeps the hero exactly as before. - Per-metric identity accents on the daily rail via the existing --tile-* hue vocabulary: a soft inset edge (stress for tension windows, strain for ECG pointers, primary for dose and coach cards); the same mark ties the ECG cross-link and the intraday pulse card shell to their rail siblings. Utility items (sync, preventive care) stay accent-less. - Quiet "reached" treatment for the milestone card: a soft success halo over the theme card plus a one-shot spring reveal on --ring-spring, with its reduced-motion fallback beside the keyframes. - The Today hero carries the one sanctioned atmosphere wash (a faint primary mix over the card in the wellness-tile pattern); the loading skeleton shares it so the swap changes content, never the surface. - Skeleton primitive upgraded from the whole-block pulse to a single soft shimmer sweep, reduced-motion guarded in globals.css; dependent test assertions repointed. - Ring link / dose-tally aria strings restored in all six locales.
185 lines
6.1 KiB
TypeScript
185 lines
6.1 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* P1 — `PriorityCard`, the ONE card behind every "worth a look" rail item.
|
|
*
|
|
* It renders a `PriorityItem` and never fetches. Every later consumer reuses
|
|
* it verbatim: the Today rail (S2), a coach check-in (S3), a milestone
|
|
* celebration (S12), a new-ECG pointer (S10), a tension window (S11). A new
|
|
* rail type is a new `kind` on the item + a server builder — never a new
|
|
* component (§1.2 P1).
|
|
*
|
|
* Design: composed ENTIRELY from shipped primitives — `Card` (compact
|
|
* density) + `TileHeader` (size `sm`, foreground icon) + `ProseBlocks` for the
|
|
* grounded one-liner, semantic-token status wash only, no raw palette colour
|
|
* (the `no-raw-palette-color` rule errors), no markdown. The Lucide glyph is
|
|
* derived from `kind` so the wire DTO stays serialisable (the icon lives with
|
|
* the renderer, the closed enum with the model). The `animate-insight-in`
|
|
* reveal carries its own reduced-motion fallback in `globals.css`.
|
|
*/
|
|
import Link from "next/link";
|
|
import {
|
|
Activity,
|
|
Award,
|
|
CalendarClock,
|
|
HeartPulse,
|
|
MessageCircle,
|
|
Pill,
|
|
RefreshCw,
|
|
type LucideIcon,
|
|
} from "lucide-react";
|
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { TileHeader } from "@/components/insights/tile-header";
|
|
import { ProseBlocks } from "@/components/insights/prose-blocks";
|
|
import { Button, buttonVariants } from "@/components/ui/button";
|
|
import { useTranslations } from "@/lib/i18n/context";
|
|
import { cn } from "@/lib/utils";
|
|
import type {
|
|
PriorityItem,
|
|
PriorityItemAction,
|
|
PriorityItemKind,
|
|
PriorityItemStatus,
|
|
} from "@/lib/daily/priority-item";
|
|
|
|
/** Deterministic glyph per kind — the icon the serialisable item cannot hold. */
|
|
const KIND_ICON: Record<PriorityItemKind, LucideIcon> = {
|
|
dose_window: Pill,
|
|
preventive_care: CalendarClock,
|
|
sync_issue: RefreshCw,
|
|
coach_checkin: MessageCircle,
|
|
milestone: Award,
|
|
ecg_new_recording: HeartPulse,
|
|
tension_window: Activity,
|
|
};
|
|
|
|
/**
|
|
* Status wash — a subtle semantic-token tint carrying MEANING, not decoration
|
|
* (the `recommendation-card` pattern). Static classes so Tailwind sees them.
|
|
*/
|
|
const STATUS_WASH: Record<PriorityItemStatus, string> = {
|
|
success: "bg-success/10 border-success/25",
|
|
warning: "bg-warning/10 border-warning/25",
|
|
info: "bg-info/10 border-info/25",
|
|
destructive: "bg-destructive/10 border-destructive/25",
|
|
};
|
|
|
|
/**
|
|
* v1.29.0 cohesion — per-kind metric identity, drawn from the SAME `--tile-*`
|
|
* hue vocabulary the wellness tiles paint (plus `--primary` for the med and
|
|
* coach families, the tone every medication / coach surface in Insights
|
|
* already carries). Rendered as the `.metric-accent` inset edge — a quiet
|
|
* identity mark, never a fill — so a pulse card, an ECG card, and a dose card
|
|
* each read as their metric family while staying one card system.
|
|
*
|
|
* Deliberately partial: `preventive_care` and `sync_issue` are utility items
|
|
* with no metric family, and `milestone` belongs to the celebration layer
|
|
* (`.milestone-reached`, `--success`) rather than to one metric — those three
|
|
* stay accent-less. Values are token references only (`var(--…)`), the
|
|
* `RingTile` / `TILE_HUE` pattern.
|
|
*/
|
|
const KIND_HUE: Partial<Record<PriorityItemKind, string>> = {
|
|
dose_window: "var(--primary)",
|
|
coach_checkin: "var(--primary)",
|
|
ecg_new_recording: "var(--tile-strain)",
|
|
tension_window: "var(--tile-stress)",
|
|
};
|
|
|
|
export interface PriorityCardProps {
|
|
item: PriorityItem;
|
|
/**
|
|
* Tap handler for non-navigation actions. Receives the action's stable
|
|
* `intent` token. Navigation actions (those carrying an `href`) render as
|
|
* links and do not call this.
|
|
*/
|
|
onAction?: (intent: string) => void;
|
|
className?: string;
|
|
}
|
|
|
|
/** Tap-target floor per P1: `min-h-11` on touch, `min-h-9` on pointer. */
|
|
const ACTION_SIZE = "min-h-11 sm:min-h-9";
|
|
|
|
export function PriorityCard({ item, onAction, className }: PriorityCardProps) {
|
|
const { t } = useTranslations();
|
|
const Icon = KIND_ICON[item.kind];
|
|
const actions = item.actions.slice(0, 3);
|
|
const hue = KIND_HUE[item.kind];
|
|
// S12 — the quiet "reached" moment: the milestone card swaps the generic
|
|
// fade-in for the `.milestone-reached` treatment (a soft `--success` halo
|
|
// over the theme card + a one-shot spring reveal on `--ring-spring`;
|
|
// reduced-motion fallback lives beside the keyframes in globals.css). The
|
|
// halo's background wins over the status wash's flat `bg-success/10`
|
|
// (unlayered CSS beats utilities); the wash keeps the success border.
|
|
const isMilestone = item.kind === "milestone";
|
|
|
|
return (
|
|
<Card
|
|
data-slot="priority-card"
|
|
data-kind={item.kind}
|
|
className={cn(
|
|
isMilestone ? "milestone-reached" : "animate-insight-in",
|
|
"gap-2 py-3 md:gap-2 md:py-4",
|
|
item.status ? STATUS_WASH[item.status] : null,
|
|
hue ? "metric-accent" : null,
|
|
className,
|
|
)}
|
|
style={hue ? ({ "--tile-hue": hue } as React.CSSProperties) : undefined}
|
|
>
|
|
<CardContent className="flex flex-col gap-2">
|
|
<TileHeader icon={Icon} title={item.title} size="sm" />
|
|
{item.body ? (
|
|
<div className="text-foreground text-sm">
|
|
<ProseBlocks text={item.body} strip={false} linkify={false} />
|
|
</div>
|
|
) : null}
|
|
{actions.length > 0 ? (
|
|
<div className="flex flex-wrap items-center gap-2 pt-1">
|
|
{actions.map((action) => (
|
|
<ActionButton
|
|
key={action.intent}
|
|
action={action}
|
|
label={t(action.labelKey)}
|
|
onAction={onAction}
|
|
/>
|
|
))}
|
|
</div>
|
|
) : null}
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
function ActionButton({
|
|
action,
|
|
label,
|
|
onAction,
|
|
}: {
|
|
action: PriorityItemAction;
|
|
label: string;
|
|
onAction?: (intent: string) => void;
|
|
}) {
|
|
if (action.href) {
|
|
return (
|
|
<Link
|
|
href={action.href}
|
|
className={cn(
|
|
buttonVariants({ variant: "outline", size: "sm" }),
|
|
ACTION_SIZE,
|
|
)}
|
|
>
|
|
{label}
|
|
</Link>
|
|
);
|
|
}
|
|
return (
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className={ACTION_SIZE}
|
|
onClick={() => onAction?.(action.intent)}
|
|
>
|
|
{label}
|
|
</Button>
|
|
);
|
|
}
|