{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric-list-03",
  "description": "Metrics against their targets, each with a bar, a tick at the target and a status.",
  "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-03.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  MetricTargetBar,\n  MetricTargetKey,\n  TargetStatusLabel,\n  formatMetricValue,\n  getTargetStatus,\n} from '@/registry/components/dashboardblocks/metric-list'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface TargetMetric extends Omit<Metric, 'history' | 'previous'> {\n  domain?: [number, number]\n  /** A floor when `goodDirection` is `up` (the default), a ceiling when it is `down`. */\n  target: number\n  tolerance?: number\n}\n\ninterface MetricList3Props extends BlockStateProps {\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  metrics?: TargetMetric[]\n  title: string\n}\n\nconst exampleProps: MetricList3Props = {\n  description: 'Q3 so far, against the targets set in July.',\n  metrics: [\n    {\n      format: 'percent',\n      key: 'activation',\n      label: 'Activation rate',\n      target: 40,\n      value: 38.4,\n    },\n    {\n      format: 'percent',\n      key: 'trial',\n      label: 'Trial to paid',\n      target: 18,\n      value: 21.3,\n    },\n    {\n      domain: [-100, 100],\n      key: 'nps',\n      label: 'NPS',\n      target: 50,\n      value: 44,\n    },\n    {\n      format: 'percent',\n      goodDirection: 'down',\n      key: 'churn',\n      label: 'Logo churn',\n      target: 2,\n      value: 2.4,\n    },\n    {\n      format: 'milliseconds',\n      goodDirection: 'down',\n      key: 'latency',\n      label: 'p95 API latency',\n      target: 500,\n      value: 412,\n    },\n    {\n      domain: [99, 100],\n      format: 'percent',\n      key: 'uptime',\n      label: 'Uptime',\n      target: 99.9,\n      value: 99.97,\n    },\n  ],\n  title: 'Targets',\n}\n\nconst MetricList3 = (props: MetricList3Props) => {\n  const { description, metrics = [], errorMessage, status, title } = props\n  const state = getBlockState(status, metrics)\n  const statuses = metrics.map((metric) => getTargetStatus(metric))\n  const met = statuses.filter((status) => status === 'met').length\n\n  const missed = statuses.filter((status) => status === 'missed').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                  {description}{' '}\n                  <span className='tabular-nums'>\n                    {met} of {metrics.length}\n                  </span>{' '}\n                  on target\n                  {missed > 0 && (\n                    <>\n                      , <span className='tabular-nums'>{missed}</span> off it\n                    </>\n                  )}\n                  .\n                </p>\n              </BlockReady>\n            </header>\n            <BlockStateRows\n              className='border-t data-[slot=block-state-rows]:border-b'\n              rows={5}\n            />\n            {!state && (\n              <MetricList className='border-y'>\n                {metrics.map((metric, index) => {\n                  const floor = (metric.goodDirection ?? 'up') === 'up'\n                  return (\n                    <li\n                      key={metric.key}\n                      className='grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-2 py-2.5 @xl:grid-cols-[minmax(0,1fr)_minmax(5rem,8rem)_6.5rem_6.5rem] @xl:gap-x-4'\n                    >\n                      <span className='col-start-1 row-start-1 text-sm'>\n                        {metric.label}\n                      </span>\n                      <MetricTargetBar\n                        className='col-span-2 row-start-2 @xl:col-span-1 @xl:col-start-2 @xl:row-start-1'\n                        domain={metric.domain}\n                        target={metric.target}\n                        value={metric.value}\n                      />\n                      <p className='col-span-2 row-start-3 flex items-baseline gap-1.5 text-xs whitespace-nowrap tabular-nums @xl:col-span-1 @xl:col-start-3 @xl:row-start-1 @xl:flex-col @xl:items-end @xl:gap-0'>\n                        <span className='text-sm font-medium'>\n                          {formatMetricValue(metric, metric.value)}\n                        </span>\n                        <span className='text-muted-foreground'>\n                          Target <span aria-hidden>{floor ? '≥' : '≤'}</span>\n                          <span className='sr-only'>\n                            {floor ? 'at least' : 'at most'}\n                          </span>{' '}\n                          {formatMetricValue(metric, metric.target)}\n                        </span>\n                      </p>\n                      <TargetStatusLabel\n                        className='col-start-2 row-start-1 justify-self-end text-xs @xl:col-start-4'\n                        status={statuses[index]}\n                      />\n                    </li>\n                  )\n                })}\n              </MetricList>\n            )}\n            {state !== 'empty' && state !== 'error' && <MetricTargetKey />}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { MetricList3, exampleProps as metricList3ExampleProps, type MetricList3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/metric-list/metric-list-03.tsx"
    }
  ],
  "meta": {
    "shows": "Metrics against their targets, each with a bar, a tick at the target and a status.",
    "size": "half",
    "usedWith": [
      "goals-02",
      "gauge-02",
      "metric-list-01"
    ],
    "component": "MetricList3",
    "props": "{ description: string; metrics?: { domain?: [number, number]; target: number; tolerance?: number; format?: \"number\" | \"compact\" | \"currency\" | \"currency-compact\" | \"percent\" | \"duration\" | \"milliseconds\" | (value: number) => string; value: number; changeType?: \"percent\" | \"points\"; goodDirection?: \"up\" | \"down\"; key: string; label: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
