{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric-card",
  "title": "Metric Card",
  "description": "KPI card with a label, a value and a delta.",
  "dependencies": [
    "class-variance-authority@^0.7.1",
    "lucide-react@^1.27.0"
  ],
  "registryDependencies": [
    "@pestoui/card",
    "@pestoui/icon-tile",
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/components/metric-card.tsx",
      "content": "import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { Minus, TrendingDown, TrendingUp } from \"lucide-react\"\n\nimport { Card, CardContent } from \"@/components/ui/card\"\nimport { IconTile } from \"@/components/icon-tile\"\nimport { cn } from \"@/lib/utils\"\n\n/* KPI tile. Composes Card so it inherits the system's card elevation and\n   spacing rhythm — the only thing this adds is the label / value / delta\n   hierarchy and an optional leading squircle. */\nconst metricCardVariants = cva(\"group/metric-card\", {\n  variants: {\n    align: {\n      start: \"text-left\",\n      center: \"text-center\",\n    },\n  },\n  defaultVariants: {\n    align: \"start\",\n  },\n})\n\n/* Trend is inferred from the sign of the delta — up reads success, down reads\n   destructive, and a flat delta stays muted so it never competes for attention. */\nconst metricDeltaVariants = cva(\n  \"inline-flex items-center gap-1 text-caption leading-none font-medium tabular-nums [&_svg]:size-4 [&_svg]:shrink-0\",\n  {\n    variants: {\n      trend: {\n        up: \"text-success\",\n        down: \"text-destructive\",\n        flat: \"text-muted-foreground\",\n      },\n    },\n    defaultVariants: {\n      trend: \"flat\",\n    },\n  }\n)\n\ntype MetricTrend = \"up\" | \"down\" | \"flat\"\n\nconst TREND_ICON: Record<MetricTrend, typeof TrendingUp> = {\n  up: TrendingUp,\n  down: TrendingDown,\n  flat: Minus,\n}\n\nconst TREND_LABEL: Record<MetricTrend, string> = {\n  up: \"Trending up\",\n  down: \"Trending down\",\n  flat: \"No change\",\n}\n\nfunction formatDelta(delta: number) {\n  const magnitude = Math.abs(delta)\n  const digits = Number.isInteger(magnitude) ? magnitude.toString() : magnitude.toFixed(1)\n  const sign = delta > 0 ? \"+\" : delta < 0 ? \"-\" : \"\"\n  return `${sign}${digits}%`\n}\n\ntype MetricCardProps = Omit<React.ComponentProps<typeof Card>, \"children\"> &\n  VariantProps<typeof metricCardVariants> & {\n    label: React.ReactNode\n    value: string | number\n    /** Percent change. Sign drives the trend colour and glyph. */\n    delta?: number\n    deltaLabel?: React.ReactNode\n    /** Rendered inside a leading squircle IconTile. */\n    icon?: React.ReactNode\n    /** Slot for a sparkline or any small chart. */\n    chart?: React.ReactNode\n  }\n\nfunction MetricCard({\n  label,\n  value,\n  delta,\n  deltaLabel,\n  icon,\n  chart,\n  align = \"start\",\n  className,\n  ...props\n}: MetricCardProps) {\n  const labelId = React.useId()\n  const hasDelta = typeof delta === \"number\" && Number.isFinite(delta)\n  const trend: MetricTrend = !hasDelta ? \"flat\" : delta > 0 ? \"up\" : delta < 0 ? \"down\" : \"flat\"\n  const TrendIcon = TREND_ICON[trend]\n\n  return (\n    <Card\n      data-slot=\"metric-card\"\n      data-align={align}\n      data-trend={hasDelta ? trend : undefined}\n      role=\"group\"\n      aria-labelledby={labelId}\n      size=\"sm\"\n      className={cn(metricCardVariants({ align }), className)}\n      {...props}\n    >\n      <CardContent>\n        <div className=\"flex items-center gap-3 group-data-[align=center]/metric-card:flex-col group-data-[align=center]/metric-card:gap-2.5\">\n          {icon ? (\n            <IconTile\n              data-slot=\"metric-card-icon\"\n              variant=\"soft\"\n              size=\"sm\"\n              aria-hidden=\"true\"\n              className=\"text-muted-foreground\"\n            >\n              {icon}\n            </IconTile>\n          ) : null}\n          <p\n            id={labelId}\n            data-slot=\"metric-card-label\"\n            className=\"min-w-0 text-caption leading-snug font-medium text-muted-foreground\"\n          >\n            {label}\n          </p>\n        </div>\n\n        {/* The number is the only thing on this tile that changes at runtime,\n            so it is the only thing that moves. Keying on the value remounts the\n            line, which restarts the enter every time it changes — the swap\n            spring lifts it into place out of a short blur instead of snapping to\n            a new figure. It plays on mount too, which reads as the tile\n            arriving; a KPI grid is three or four cards, not fifty rows, so that\n            stays a welcome and not a distraction. There is no matching exit —\n            the old figure is replaced rather than dismissed. */}\n        <p\n          key={String(value)}\n          data-slot=\"metric-card-value\"\n          className=\"mt-3 text-[1.875rem] leading-[1.1] font-semibold tracking-title tabular-nums text-foreground animate-in fade-in slide-in-from-bottom-2 blur-in-4 duration-spring-swap ease-spring-swap\"\n        >\n          {value}\n        </p>\n\n        {hasDelta || deltaLabel ? (\n          <div className=\"mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 group-data-[align=center]/metric-card:justify-center\">\n            {hasDelta ? (\n              <span\n                data-slot=\"metric-card-delta\"\n                className={cn(metricDeltaVariants({ trend }))}\n              >\n                <TrendIcon aria-hidden=\"true\" />\n                <span className=\"sr-only\">{TREND_LABEL[trend]}, </span>\n                {formatDelta(delta)}\n              </span>\n            ) : null}\n            {deltaLabel ? (\n              <span className=\"text-caption leading-none text-muted-foreground\">\n                {deltaLabel}\n              </span>\n            ) : null}\n          </div>\n        ) : null}\n      </CardContent>\n\n      {chart ? (\n        <CardContent>\n          <div\n            data-slot=\"metric-card-chart\"\n            className=\"[&>svg]:h-full [&>svg]:w-full\"\n          >\n            {chart}\n          </div>\n        </CardContent>\n      ) : null}\n    </Card>\n  )\n}\n\nexport { MetricCard, metricCardVariants, metricDeltaVariants }\nexport type { MetricCardProps, MetricTrend }\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}