mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
feat(ui): ScorePill for every grade chip
Confidence levels, the weekly score gain, target bands and lab range flags were drawn by hand in two looks: a /15 wash without border in the mood boards, a /10 wash with a /40 border on the correlation and trend cards, and medium confidence was blue on one card and amber on the next. They now render through one ScorePill (rounded, xs, soft wash, tone success / info / warning / destructive / neutral, optional tabular figures) with one confidence scale. The target band keeps its own AA-tuned tokens in the shared anatomy. A structural test refuses a new hand-rolled grade chip.
This commit is contained in:
1 parent
ab3f21c58c
commit
ee2bc8019c
14 files changed
+278
-131
No files matched your search
@@ -1,20 +0,0 @@
|
||||
/**
|
||||
* v1.4.20 — shared confidence-band classnames.
|
||||
*
|
||||
* Both `<CorrelationCard>` and `<TrendAnnotation>` paint a discrete
|
||||
* "low / moderate / high" badge with byte-identical semantic utility
|
||||
* classes. Per-component i18n key maps stay local because the copy
|
||||
* differs (correlationRow.* vs trendAnnotation.*); only the classname
|
||||
* table is the load-bearing duplication.
|
||||
*/
|
||||
export type ConfidenceBand = "low" | "moderate" | "high";
|
||||
|
||||
export const CONFIDENCE_BADGE_CLASS: Record<ConfidenceBand, string> = {
|
||||
high: "border-success/40 bg-success/10 text-success",
|
||||
moderate: "border-warning/40 bg-warning/10 text-warning",
|
||||
// Neutral (non-status) tier. The former `*-dracula-comment/*` classes
|
||||
// had no generated utility (`--color-dracula-comment` was never in the
|
||||
// @theme block) and silently painted nothing; border/muted is the real
|
||||
// neutral vocabulary.
|
||||
low: "border-border bg-muted/50 text-muted-foreground",
|
||||
};
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { Activity, Sparkles } from "lucide-react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
||||
import { TileHeader } from "@/components/insights/tile-header";
|
||||
@@ -12,7 +11,7 @@ import { useTranslations } from "@/lib/i18n/context";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { CorrelationResult } from "@/lib/insights/correlations";
|
||||
import type { CoachScopeSource } from "@/lib/ai/coach/types";
|
||||
import { CONFIDENCE_BADGE_CLASS } from "./confidence-badge";
|
||||
import { CONFIDENCE_TONE, ScorePill } from "@/components/ui/score-pill";
|
||||
import { AskCoachAction } from "./ask-coach-action";
|
||||
import {
|
||||
PatternDismissButton,
|
||||
@@ -134,16 +133,12 @@ export function CorrelationCard({ result }: CorrelationCardProps) {
|
||||
title={title}
|
||||
right={
|
||||
result.status === "ok" ? (
|
||||
<Badge
|
||||
<ScorePill
|
||||
data-slot="correlation-card-confidence"
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"shrink-0 text-xs",
|
||||
CONFIDENCE_BADGE_CLASS[result.confidenceBand.label],
|
||||
)}
|
||||
tone={CONFIDENCE_TONE[result.confidenceBand.label]}
|
||||
>
|
||||
{t(CONFIDENCE_LABEL_KEY[result.confidenceBand.label])}
|
||||
</Badge>
|
||||
</ScorePill>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -42,6 +42,7 @@ import { useDateFormatPreference, useTranslations } from "@/lib/i18n/context";
|
||||
import { SCORE_PILLAR_LABEL_KEYS } from "@/lib/score-config/labels";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { InlineAction } from "@/components/ui/inline-action";
|
||||
import { ScorePill } from "@/components/ui/score-pill";
|
||||
|
||||
/**
|
||||
* The Health Score panel: the hero band's right-hand column.
|
||||
@@ -434,12 +435,13 @@ export function HealthScoreCard({
|
||||
</p>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
{report.delta != null && report.delta > 0 ? (
|
||||
<span
|
||||
<ScorePill
|
||||
tone="success"
|
||||
numeric
|
||||
data-slot="health-score-card-delta-chip"
|
||||
className="bg-success/15 text-success shrink-0 rounded-full px-2 py-0.5 text-xs font-semibold tabular-nums"
|
||||
>
|
||||
+{report.delta}
|
||||
</span>
|
||||
</ScorePill>
|
||||
) : null}
|
||||
{/* v1.42 — the way to the score's course over time. */}
|
||||
<InlineAction asChild tone="foreground">
|
||||
|
||||
@@ -4,8 +4,8 @@ import { ArrowDownRight, ArrowUpRight } from "lucide-react";
|
||||
|
||||
import { useFormatters, useTranslations } from "@/lib/i18n/context";
|
||||
import { moodTagIcon } from "@/components/mood/mood-tag-icons";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { MoodInfluenceConfidence } from "./mood-tag-influence";
|
||||
import { CONFIDENCE_TONE, ScorePill } from "@/components/ui/score-pill";
|
||||
|
||||
/**
|
||||
* v1.11.5 — "What's associated with your better days" board.
|
||||
@@ -54,16 +54,6 @@ const CONFIDENCE_KEY: Record<MoodInfluenceConfidence, string> = {
|
||||
high: "insights.mood.influence.confidenceHigh",
|
||||
};
|
||||
|
||||
// Confidence chips carry COLORED TEXT, so they ride the semantic feedback
|
||||
// tokens (`--info` / `--success`) — these carry the Alucard light-mode
|
||||
// overrides that clear AA on the white card. Raw `--dracula-*` stays bright
|
||||
// green/cyan in light mode and fails AA for text.
|
||||
const CONFIDENCE_CLASS: Record<MoodInfluenceConfidence, string> = {
|
||||
low: "bg-secondary text-muted-foreground",
|
||||
medium: "bg-info/15 text-info",
|
||||
high: "bg-success/15 text-success",
|
||||
};
|
||||
|
||||
export function MoodBetterDays({
|
||||
factors,
|
||||
}: {
|
||||
@@ -146,14 +136,9 @@ export function MoodBetterDays({
|
||||
>
|
||||
{effectText}
|
||||
</span>
|
||||
<span
|
||||
className={cn(
|
||||
"shrink-0 rounded-full px-2 py-0.5 text-xs font-medium",
|
||||
CONFIDENCE_CLASS[factor.confidence],
|
||||
)}
|
||||
>
|
||||
<ScorePill tone={CONFIDENCE_TONE[factor.confidence]}>
|
||||
{t(CONFIDENCE_KEY[factor.confidence])}
|
||||
</span>
|
||||
</ScorePill>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useFormatters, useTranslations } from "@/lib/i18n/context";
|
||||
import { moodTagIcon } from "@/components/mood/mood-tag-icons";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { CONFIDENCE_TONE, ScorePill } from "@/components/ui/score-pill";
|
||||
|
||||
/**
|
||||
* v1.11.5 — tag "Influence on Mood".
|
||||
@@ -44,16 +44,6 @@ const CONFIDENCE_KEY: Record<MoodInfluenceConfidence, string> = {
|
||||
high: "insights.mood.influence.confidenceHigh",
|
||||
};
|
||||
|
||||
// Confidence chips carry COLORED TEXT, so they ride the semantic feedback
|
||||
// tokens (`--info` / `--success`) — these carry the Alucard light-mode
|
||||
// overrides that clear AA on the white card. Raw `--dracula-*` stays bright
|
||||
// green/cyan in light mode and fails AA for text.
|
||||
const CONFIDENCE_CLASS: Record<MoodInfluenceConfidence, string> = {
|
||||
low: "bg-secondary text-muted-foreground",
|
||||
medium: "bg-info/15 text-info",
|
||||
high: "bg-success/15 text-success",
|
||||
};
|
||||
|
||||
// Semantic feedback tokens (not raw `--dracula-*`): the delta read-out is
|
||||
// COLORED TEXT, so it needs the Alucard light-mode override to clear AA.
|
||||
function deltaColor(delta: number): string {
|
||||
@@ -100,14 +90,9 @@ export function MoodTagInfluence({ rows }: { rows: MoodTagInfluenceRow[] }) {
|
||||
>
|
||||
{deltaText}
|
||||
</span>
|
||||
<span
|
||||
className={cn(
|
||||
"shrink-0 rounded-full px-2 py-0.5 text-xs font-medium",
|
||||
CONFIDENCE_CLASS[row.confidence],
|
||||
)}
|
||||
>
|
||||
<ScorePill tone={CONFIDENCE_TONE[row.confidence]}>
|
||||
{t(CONFIDENCE_KEY[row.confidence])}
|
||||
</span>
|
||||
</ScorePill>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{t("insights.mood.influence.detail", {
|
||||
|
||||
@@ -33,6 +33,7 @@ import { apiGet } from "@/lib/api/api-fetch";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import type { MeasurementType } from "@/generated/prisma/client";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ScorePill } from "@/components/ui/score-pill";
|
||||
|
||||
interface PersonalRecordRow {
|
||||
id: string;
|
||||
@@ -122,22 +123,16 @@ export function PersonalRecordBadge({
|
||||
if (!fresh) return null;
|
||||
|
||||
const pill = (
|
||||
<span
|
||||
<ScorePill
|
||||
tone="success"
|
||||
numeric
|
||||
data-slot="insights-pr-badge"
|
||||
data-metric-type={metricType}
|
||||
className={cn(
|
||||
// `--success` resolves to the AA-tuned green per theme: a deep
|
||||
// forest green on the light card (#14720a) and Dracula's neon
|
||||
// green on the dark card (#50fa7b). Both clear 4.5:1 against
|
||||
// their card background — the previous `text-success` on
|
||||
// `bg-success/10` measured ~2.6:1 in dark mode.
|
||||
"border-success/40 bg-success/15 text-success text-2xs inline-flex shrink-0 items-center rounded-full border px-1.5 py-0.5 leading-none font-semibold tracking-wide uppercase tabular-nums",
|
||||
className,
|
||||
)}
|
||||
className={cn("tracking-wide uppercase", className)}
|
||||
aria-label={t("insights.personalRecord.badge")}
|
||||
>
|
||||
{t("insights.personalRecord.badge")}
|
||||
</span>
|
||||
</ScorePill>
|
||||
);
|
||||
|
||||
if (!withTooltip) return pill;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { useMemo } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Sparkles } from "lucide-react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
@@ -17,8 +16,7 @@ import {
|
||||
TREND_SLOT_DESCRIPTOR_META,
|
||||
type TrendDescriptorPoint,
|
||||
} from "@/lib/insights/trend-descriptor";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { CONFIDENCE_BADGE_CLASS } from "./confidence-badge";
|
||||
import { CONFIDENCE_TONE, ScorePill } from "@/components/ui/score-pill";
|
||||
import { apiGet } from "@/lib/api/api-fetch";
|
||||
import { useUnitDisplay } from "@/hooks/use-unit-display";
|
||||
|
||||
@@ -192,13 +190,12 @@ export function TrendAnnotation({
|
||||
text={stripChartTokens(annotation)}
|
||||
>
|
||||
{confidence ? (
|
||||
<Badge
|
||||
<ScorePill
|
||||
data-slot="trend-annotation-confidence"
|
||||
variant="outline"
|
||||
className={cn("text-xs", CONFIDENCE_BADGE_CLASS[confidence])}
|
||||
tone={CONFIDENCE_TONE[confidence]}
|
||||
>
|
||||
{t(CONFIDENCE_LABEL_KEY[confidence])}
|
||||
</Badge>
|
||||
</ScorePill>
|
||||
) : null}
|
||||
</TrendCaptionCard>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user