{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric-list-02",
  "description": "Metrics grouped into sections, each with a header and a count of how many improved.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/metric-list.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/metric-list/metric-list-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type Metric,\n  MetricList,\n  MetricRow,\n  getMetricChange,\n} from '@/registry/components/dashboardblocks/metric-list'\nimport { useId } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface MetricSection {\n  key: string\n  label: string\n  metrics: Metric[]\n}\n\ninterface MetricList2Props extends BlockStateProps {\n  /** Follows the previous value in each change, such as `in August`. */\n  comparison?: string\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  sections?: MetricSection[]\n  title: string\n}\n\nconst exampleProps: MetricList2Props = {\n  comparison: 'in August',\n  description: 'September against August.',\n  sections: [\n    {\n      key: 'acquisition',\n      label: 'Acquisition',\n      metrics: [\n        {\n          format: 'compact',\n          key: 'visitors',\n          label: 'Visitors',\n          previous: 96_410,\n          value: 104_870,\n        },\n        {\n          format: 'number',\n          key: 'signups',\n          label: 'Sign-ups',\n          previous: 3_912,\n          value: 4_286,\n        },\n        {\n          format: 'currency',\n          goodDirection: 'down',\n          key: 'cac',\n          label: 'Cost per acquisition',\n          previous: 41.2,\n          value: 38.9,\n        },\n      ],\n    },\n    {\n      key: 'engagement',\n      label: 'Engagement',\n      metrics: [\n        {\n          format: 'compact',\n          key: 'dau',\n          label: 'Daily active users',\n          previous: 12_840,\n          value: 13_310,\n        },\n        {\n          changeType: 'points',\n          format: 'percent',\n          key: 'stickiness',\n          label: 'DAU / MAU',\n          previous: 31.4,\n          value: 29.8,\n        },\n        {\n          format: 'duration',\n          key: 'session',\n          label: 'Avg session',\n          previous: 402,\n          value: 431,\n        },\n        {\n          changeType: 'points',\n          format: 'percent',\n          key: 'retention',\n          label: 'Week 4 retention',\n          previous: 38.2,\n          value: 38.2,\n        },\n      ],\n    },\n    {\n      key: 'revenue',\n      label: 'Revenue',\n      metrics: [\n        {\n          format: 'currency-compact',\n          key: 'mrr',\n          label: 'MRR',\n          previous: 184_300,\n          value: 196_750,\n        },\n        { format: 'currency', key: 'arpa', label: 'ARPA', previous: 62.1, value: 63.4 },\n        {\n          changeType: 'points',\n          format: 'percent',\n          goodDirection: 'down',\n          key: 'churn',\n          label: 'Revenue churn',\n          previous: 2.1,\n          value: 2.6,\n        },\n      ],\n    },\n  ],\n  title: 'Monthly metrics',\n}\n\nconst MetricList2 = (props: MetricList2Props) => {\n  const { comparison, description, sections = [], errorMessage, status, title } = props\n  const id = useId()\n  const isBetter = (metric: Metric) => {\n    const change = getMetricChange(metric) ?? 0\n    return metric.goodDirection === 'down' ? change < 0 : change > 0\n  }\n  const total = sections.reduce((sum, section) => sum + section.metrics.length, 0)\n  const improving = sections.reduce(\n    (sum, section) => sum + section.metrics.filter(isBetter).length,\n    0,\n  )\n  const state = getBlockState(\n    status,\n    sections.flatMap((section) => section.metrics),\n  )\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>\n                  {description}{' '}\n                  <span className='tabular-nums'>\n                    {improving} of {total}\n                  </span>{' '}\n                  metrics improved.\n                </p>\n              </BlockReady>\n            </header>\n            <BlockStateRows className='border-t' rows={6} />\n            {!state &&\n              sections.map((section) => {\n                const headingId = `${id}-${section.key}`\n                const better = section.metrics.filter(isBetter).length\n                return (\n                  <section\n                    key={section.key}\n                    aria-labelledby={headingId}\n                    className='flex flex-col border-t pt-3'\n                  >\n                    <div className='flex items-baseline justify-between gap-3'>\n                      <h3 id={headingId} className='text-sm font-medium'>\n                        {section.label}\n                      </h3>\n                      <p className='text-muted-foreground text-xs tabular-nums'>\n                        {better} of {section.metrics.length} improved\n                      </p>\n                    </div>\n                    <MetricList>\n                      {section.metrics.map((metric) => (\n                        <MetricRow\n                          key={metric.key}\n                          comparison={comparison}\n                          metric={metric}\n                          showSparkline={false}\n                        />\n                      ))}\n                    </MetricList>\n                  </section>\n                )\n              })}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { MetricList2, exampleProps as metricList2ExampleProps, type MetricList2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/metric-list/metric-list-02.tsx"
    }
  ],
  "meta": {
    "shows": "Metrics grouped into sections, each with a header and a count of how many improved.",
    "size": "half",
    "usedWith": [
      "metric-list-01",
      "stat-group-01",
      "comparison-01"
    ],
    "component": "MetricList2",
    "props": "{ comparison?: string; description: string; sections?: { key: string; label: string; metrics: { changeType?: \"percent\" | \"points\"; format?: \"number\" | \"compact\" | \"currency\" | \"currency-compact\" | \"percent\" | \"duration\" | \"milliseconds\" | (value: number) => string; goodDirection?: \"up\" | \"down\"; history?: number[]; key: string; label: string; previous?: number; value: number }[] }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
