{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "statistic-share-of-total",
  "title": "Statistic Share Of Total",
  "description": "A ranked list of statistics where each row shows its share of the total as a number and a thin bar, sorted largest first with a cap and an Other row.",
  "registryDependencies": [
    "@tealmac/statistic"
  ],
  "files": [
    {
      "path": "registry/patterns/statistic-share-of-total/statistic-share-of-total.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Statistic } from \"@/components/ui/statistic\"\n\nexport interface ShareRow {\n  label: string\n  value: number\n}\n\nexport interface StatisticShareOfTotalProps {\n  rows: ShareRow[]\n  title: string\n  /** Show this many rows, group the rest as \"Other\". Default 5. */\n  top?: number\n  prefix?: string\n}\n\n/**\n * Top-N breakdowns: rows are sorted largest first, only the first `top` are\n * listed and the rest are summed into one \"Other\" row so the shares still add\n * up to 100%. Each row prints its value and its share as numbers; the thin bar\n * is decoration. The total is the headline statistic.\n */\nexport function StatisticShareOfTotal({\n  rows,\n  title,\n  top = 5,\n  prefix,\n}: StatisticShareOfTotalProps) {\n  const sorted = [...rows].sort((a, b) => b.value - a.value)\n  const total = sorted.reduce((a, r) => a + r.value, 0)\n  const head = sorted.slice(0, top)\n  const rest = sorted.slice(top)\n  const shown = rest.length\n    ? [\n        ...head,\n        { label: \"Other\", value: rest.reduce((a, r) => a + r.value, 0) },\n      ]\n    : head\n  const share = (v: number) => (total === 0 ? 0 : (v / total) * 100)\n\n  return (\n    <section aria-label={title} className=\"w-full max-w-md space-y-4\">\n      <Statistic title={title} value={total} prefix={prefix} />\n      <ol className=\"space-y-2.5\">\n        {shown.map((r) => (\n          <li key={r.label} className=\"space-y-1\">\n            <div className=\"flex items-baseline justify-between gap-3 text-sm\">\n              <span>{r.label}</span>\n              <span className=\"tabular-nums\">\n                {prefix}\n                {r.value.toLocaleString(\"en-US\")}\n                <span className=\"text-muted-foreground ms-2\">\n                  {share(r.value).toFixed(1)}%\n                </span>\n              </span>\n            </div>\n            <div\n              aria-hidden\n              className=\"bg-muted h-1.5 overflow-hidden rounded-full\"\n            >\n              <div\n                className=\"bg-primary h-full rounded-full\"\n                style={{ width: `${share(r.value)}%` }}\n              />\n            </div>\n          </li>\n        ))}\n      </ol>\n    </section>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}