{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "eval-score",
  "title": "Eval score",
  "description": "Evaluation score with a rolling number, a pass, borderline or fail badge that pops in against a threshold, a spring-filled bar and a criteria breakdown with per-criterion thresholds, as card, inline row or badge.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json",
    "https://goodui.dev/r/number-flow.json"
  ],
  "files": [
    {
      "path": "registry/components/ai/eval-score.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { Check, Minus, X } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { NumberFlow } from \"@/components/goodui/number-flow\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { spring } from \"@/lib/goodui-motion\"\n\n/*\n * Evaluation score for AI outputs: a rolling number, a pass/fail/borderline badge against a threshold, a\n * score bar that springs to its value and an optional criteria breakdown (bars with their own pass marks).\n * No radar chart: bars read faster and compare across runs.\n */\n\nconst CSS = `\n.pc-eval{--pc-eval-pass:oklch(0.53 0.13 155);--pc-eval-fail:oklch(0.56 0.21 27);--pc-eval-near:oklch(0.72 0.16 70)}\n.dark .pc-eval{--pc-eval-pass:oklch(0.7 0.16 155);--pc-eval-fail:oklch(0.68 0.2 25);--pc-eval-near:oklch(0.8 0.16 75)}\n.pc-eval[data-verdict=pass]{--pc-eval-c:var(--pc-eval-pass)}\n.pc-eval[data-verdict=fail]{--pc-eval-c:var(--pc-eval-fail)}\n.pc-eval[data-verdict=near]{--pc-eval-c:var(--pc-eval-near)}\n.pc-eval[data-verdict=none]{--pc-eval-c:var(--foreground)}\n.pc-eval-ink{color:color-mix(in oklab,var(--pc-eval-c) 75%,var(--foreground))}\n.pc-eval[data-verdict=near] .pc-eval-ink{color:color-mix(in oklab,var(--pc-eval-c) 58%,var(--foreground))}\n.pc-eval-tint{background:color-mix(in oklab,var(--pc-eval-c) 14%,transparent)}\n.pc-eval-fill{background:var(--pc-eval-c)}\n`\n\nexport type EvalCriterion = {\n  label: string\n  /** Same scale as the score (0..max). */\n  score: number\n  /** Overrides the main threshold for this criterion. */\n  threshold?: number\n  /** Short note shown under the label. */\n  note?: string\n}\n\nexport type EvalVerdict = \"pass\" | \"fail\" | \"near\" | \"none\"\n\nexport type EvalScoreLabels = {\n  pass: string\n  fail: string\n  near: string\n  score: string\n  criteria: string\n  outOf: (max: string) => string\n}\nconst DEFAULT_LABELS: EvalScoreLabels = { pass: \"Pass\", fail: \"Fail\", near: \"Borderline\", score: \"Score\", criteria: \"Breakdown\", outOf: (max) => `/ ${max}` }\n\nexport type EvalScoreProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  score: number\n  /** Top of the scale. */\n  max?: number\n  /** Minimum passing score. Omit for no verdict. */\n  threshold?: number\n  /** Scores within this distance under the threshold are \"borderline\" instead of a hard fail. */\n  margin?: number\n  label?: React.ReactNode\n  /** Per-criterion scores shown as bars under the main score. */\n  criteria?: EvalCriterion[]\n  /** card: score, badge, bar and breakdown. inline: number, badge and a thin bar on one line. badge: just the badge with the score. */\n  variant?: \"card\" | \"inline\" | \"badge\"\n  size?: \"sm\" | \"md\" | \"lg\"\n  /** Show the score as a percentage of max. */\n  percent?: boolean\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<EvalScoreLabels>\n}\n\nexport function verdictOf(score: number, threshold: number | undefined, margin: number): EvalVerdict {\n  if (threshold === undefined) return \"none\"\n  if (score >= threshold) return \"pass\"\n  if (score >= threshold - margin) return \"near\"\n  return \"fail\"\n}\n\nfunction Badge({ verdict, l, size, reduce, children }: { verdict: EvalVerdict; l: EvalScoreLabels; size: \"sm\" | \"md\" | \"lg\"; reduce: boolean; children?: React.ReactNode }) {\n  if (verdict === \"none\") return null\n  const Icon = verdict === \"pass\" ? Check : verdict === \"fail\" ? X : Minus\n  return (\n    <motion.span\n      key={verdict}\n      initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.6 }}\n      animate={{ opacity: 1, scale: 1 }}\n      transition={reduce ? { duration: 0 } : spring.play}\n      className={cn(\"pc-eval-tint pc-eval-ink inline-flex items-center gap-1 rounded-full font-semibold\", size === \"sm\" ? \"h-5 px-1.5 text-[11px]\" : size === \"lg\" ? \"h-7 px-2.5 text-sm\" : \"h-6 px-2 text-xs\")}\n    >\n      <Icon className={size === \"lg\" ? \"size-4\" : \"size-3\"} strokeWidth={3} aria-hidden=\"true\" />\n      {children}\n      {l[verdict]}\n    </motion.span>\n  )\n}\n\nfunction Bar({ value, max, verdict, thin, reduce, threshold }: { value: number; max: number; verdict: EvalVerdict; thin?: boolean; reduce: boolean; threshold?: number }) {\n  return (\n    <span className={cn(\"pc-eval relative block w-full overflow-hidden rounded-full bg-muted\", thin ? \"h-1.5\" : \"h-2\")} data-verdict={verdict} aria-hidden=\"true\">\n      <motion.span\n        className=\"pc-eval-fill absolute inset-y-0 start-0 w-full origin-left rounded-full rtl:origin-right\"\n        initial={{ scaleX: 0 }}\n        animate={{ scaleX: Math.max(0, Math.min(1, value / max)) }}\n        transition={reduce ? { duration: 0 } : spring.morph}\n      />\n      {threshold !== undefined && <span className=\"absolute inset-y-0 w-px bg-foreground/50\" style={{ insetInlineStart: `${(threshold / max) * 100}%` }} />}\n    </span>\n  )\n}\n\n/** Score with pass/fail badge, spring-filled bar and a criteria breakdown. */\nexport function EvalScore({ score, max = 100, threshold, margin = 5, label, criteria, variant = \"card\", size = \"md\", percent = false, labels, className, ...props }: EvalScoreProps) {\n  const l = useLabels(\"eval-score\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const verdict = verdictOf(score, threshold, margin)\n  const shown = percent ? Math.round((score / max) * 100) : score\n  const digits = Number.isInteger(shown) ? 0 : 1\n  const fmt = React.useMemo<Intl.NumberFormatOptions>(() => ({ maximumFractionDigits: digits }), [digits])\n  const srText = `${label ? `${label}: ` : \"\"}${l.score} ${shown}${percent ? \"%\" : ` ${l.outOf(String(max))}`}${verdict !== \"none\" ? `, ${l[verdict]}` : \"\"}`\n\n  if (variant === \"badge\") {\n    return (\n      <span className={cn(\"pc-eval inline-flex items-center gap-1.5\", className)} data-verdict={verdict} {...props}>\n        <style href=\"pc-eval-score\" precedence=\"default\">\n          {CSS}\n        </style>\n        <span className=\"sr-only\">{srText}</span>\n        <span aria-hidden=\"true\" className=\"contents\">\n          <Badge verdict={verdict} l={l} size={size} reduce={reduce}>\n            <NumberFlow value={shown} format={fmt} suffix={percent ? \"%\" : \"\"} className=\"tabular-nums\" />\n            <span className=\"opacity-60\">·</span>\n          </Badge>\n          {verdict === \"none\" && (\n            <span className={cn(\"font-semibold tabular-nums\", size === \"sm\" ? \"text-xs\" : \"text-sm\")}>\n              <NumberFlow value={shown} format={fmt} suffix={percent ? \"%\" : \"\"} />\n            </span>\n          )}\n        </span>\n      </span>\n    )\n  }\n\n  if (variant === \"inline\") {\n    return (\n      <div className={cn(\"pc-eval flex items-center gap-3\", className)} data-verdict={verdict} {...props}>\n        <style href=\"pc-eval-score\" precedence=\"default\">\n          {CSS}\n        </style>\n        <span className=\"sr-only\">{srText}</span>\n        <div aria-hidden=\"true\" className=\"contents\">\n          {label && <span className={cn(\"min-w-0 truncate\", size === \"sm\" ? \"text-xs\" : \"text-sm\")}>{label}</span>}\n          <span className=\"min-w-16 flex-1\">\n            <Bar value={score} max={max} verdict={verdict} thin reduce={reduce} threshold={threshold} />\n          </span>\n          <span className={cn(\"pc-eval-ink shrink-0 font-semibold tabular-nums\", size === \"sm\" ? \"text-xs\" : \"text-sm\")}>\n            <NumberFlow value={shown} format={fmt} suffix={percent ? \"%\" : \"\"} />\n          </span>\n          <Badge verdict={verdict} l={l} size={size === \"lg\" ? \"md\" : \"sm\"} reduce={reduce} />\n        </div>\n      </div>\n    )\n  }\n\n  return (\n    <div className={cn(\"pc-eval rounded-xl border bg-card p-4 text-card-foreground\", className)} data-verdict={verdict} {...props}>\n      <style href=\"pc-eval-score\" precedence=\"default\">\n        {CSS}\n      </style>\n      <span className=\"sr-only\">{srText}</span>\n      <div aria-hidden=\"true\">\n        <div className=\"flex items-start justify-between gap-3\">\n          <div className=\"min-w-0\">\n            {label && <div className=\"truncate text-sm font-medium\">{label}</div>}\n            <div className=\"mt-1 flex items-baseline gap-1.5\">\n              <span className={cn(\"pc-eval-ink font-semibold tracking-tight tabular-nums\", size === \"sm\" ? \"text-2xl\" : size === \"lg\" ? \"text-5xl\" : \"text-4xl\")}>\n                <NumberFlow value={shown} format={fmt} suffix={percent ? \"%\" : \"\"} />\n              </span>\n              {!percent && <span className=\"text-sm text-muted-foreground\">{l.outOf(String(max))}</span>}\n            </div>\n          </div>\n          <Badge verdict={verdict} l={l} size={size} reduce={reduce} />\n        </div>\n        <div className=\"mt-3\">\n          <Bar value={score} max={max} verdict={verdict} reduce={reduce} threshold={threshold} />\n        </div>\n        {criteria && criteria.length > 0 && (\n          <div className=\"mt-4\">\n            <div className=\"mb-2 text-[11px] font-medium tracking-wide text-muted-foreground uppercase\">{l.criteria}</div>\n            <ul className=\"flex flex-col gap-2.5\">\n              {criteria.map((c, i) => {\n                const t = c.threshold ?? threshold\n                const v = verdictOf(c.score, t, margin)\n                return (\n                  <motion.li\n                    key={c.label}\n                    initial={reduce ? false : { opacity: 0, x: -6 }}\n                    animate={{ opacity: 1, x: 0 }}\n                    transition={reduce ? { duration: 0 } : { delay: 0.08 + i * 0.06, ...spring.ui }}\n                    className=\"pc-eval grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1\"\n                    data-verdict={v}\n                  >\n                    <span className=\"flex min-w-0 items-center gap-2 text-sm\">\n                      <span className={cn(\"grid size-4 shrink-0 place-items-center rounded-full\", v === \"none\" ? \"bg-muted\" : \"pc-eval-tint pc-eval-ink\")}>\n                        {v === \"pass\" ? <Check className=\"size-2.5\" strokeWidth={3.5} /> : v === \"fail\" ? <X className=\"size-2.5\" strokeWidth={3.5} /> : v === \"near\" ? <Minus className=\"size-2.5\" strokeWidth={3.5} /> : null}\n                      </span>\n                      <span className=\"truncate\">{c.label}</span>\n                    </span>\n                    <span className=\"pc-eval-ink text-sm font-semibold tabular-nums\">{Number.isInteger(c.score) ? c.score : c.score.toFixed(1)}</span>\n                    <span className=\"col-span-2\">\n                      <Bar value={c.score} max={max} verdict={v} thin reduce={reduce} threshold={t} />\n                    </span>\n                    {c.note && <span className=\"col-span-2 -mt-0.5 text-xs text-muted-foreground\">{c.note}</span>}\n                  </motion.li>\n                )\n              })}\n            </ul>\n          </div>\n        )}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/eval-score.tsx"
    }
  ],
  "categories": [
    "components",
    "ai"
  ],
  "type": "registry:component"
}
