{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric-list-01",
  "description": "A list of metrics with their change and a 14-day sparkline each.",
  "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-01.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 { formatDate } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface MetricList1Props extends BlockStateProps {\n  /** Follows the previous value in each change, such as `the 14 days before`. */\n  comparison: string\n  /** Names each point of the histories, oldest first. */\n  labels?: string[]\n  /** Leave out, or pass none, to show the empty state. */\n  metrics?: Metric[]\n  period: string\n  title: string\n}\n\nconst exampleHistory = (end: number, slope: number, wobble: number, phase = 0) =>\n  Array.from({ length: 14 }, (_, day) =>\n    Number((end - (13 - day) * slope + Math.sin(day / 1.4 + phase) * wobble).toFixed(2)),\n  )\n\nconst exampleProps: MetricList1Props = {\n  comparison: 'the 14 days before',\n  labels: Array.from({ length: 14 }, (_, day) =>\n    formatDate(new Date(Date.UTC(2026, 8, 12 + day)), 'day'),\n  ),\n  metrics: [\n    {\n      format: 'compact',\n      history: exampleHistory(1_910, 22, 140),\n      key: 'visitors',\n      label: 'Visitors',\n      previous: 21_640,\n      value: 24_318,\n    },\n    {\n      format: 'compact',\n      history: exampleHistory(1_240, 6, 90, 1),\n      key: 'signups',\n      label: 'Sign-ups',\n      previous: 16_820,\n      value: 17_402,\n    },\n    {\n      changeType: 'points',\n      format: 'percent',\n      history: exampleHistory(3.4, 0.03, 0.12, 2),\n      key: 'conversion',\n      label: 'Conversion rate',\n      previous: 3.1,\n      value: 3.4,\n    },\n    {\n      format: 'duration',\n      history: exampleHistory(188, -1.1, 8, 3),\n      key: 'session',\n      label: 'Avg session',\n      previous: 201,\n      value: 188,\n    },\n    {\n      format: 'currency',\n      history: exampleHistory(37.6, 0.18, 0.7, 4),\n      key: 'aov',\n      label: 'Avg order value',\n      previous: 35.45,\n      value: 37.55,\n    },\n    {\n      changeType: 'points',\n      format: 'percent',\n      goodDirection: 'down',\n      history: exampleHistory(40.5, -0.25, 1, 1),\n      key: 'bounce',\n      label: 'Bounce rate',\n      previous: 44,\n      value: 41,\n    },\n    {\n      format: 'milliseconds',\n      goodDirection: 'down',\n      history: exampleHistory(412, 3, 14, 5),\n      key: 'latency',\n      label: 'p95 page load',\n      previous: 384,\n      value: 412,\n    },\n  ],\n  period: 'last 14 days',\n  title: 'Key metrics',\n}\n\nconst MetricList1 = (props: MetricList1Props) => {\n  const { comparison, labels, metrics = [], period, errorMessage, status, title } = props\n  const state = getBlockState(status, metrics)\n  const improved = metrics.filter((metric) => {\n    const change = getMetricChange(metric) ?? 0\n    return metric.goodDirection === 'down' ? change < 0 : change > 0\n  }).length\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                  <span className='tabular-nums'>\n                    {improved} of {metrics.length}\n                  </span>{' '}\n                  improved in the {period}, against {comparison}.\n                </p>\n              </BlockReady>\n            </header>\n            <BlockStateRows className='border-t' rows={6} />\n            {!state && (\n              <MetricList className='border-t'>\n                {metrics.map((metric) => (\n                  <MetricRow\n                    key={metric.key}\n                    comparison={comparison}\n                    labels={labels}\n                    metric={metric}\n                    period={period}\n                  />\n                ))}\n              </MetricList>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { MetricList1, exampleProps as metricList1ExampleProps, type MetricList1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/metric-list/metric-list-01.tsx"
    }
  ],
  "meta": {
    "shows": "A list of metrics with their change and a 14-day sparkline each.",
    "size": "half",
    "usedWith": [
      "stat-group-02",
      "metric-list-02",
      "chart-panel-01"
    ],
    "component": "MetricList1",
    "props": "{ comparison: string; labels?: 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 }[]; period: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
