{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table-02",
  "description": "Revenue by product, each with a bar scaled to the top product and its share of the total.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/table.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/data-table/data-table-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  DataTable,\n  DataTableBar,\n  DataTableBody,\n  DataTableCell,\n  DataTableHead,\n  DataTableHeader,\n  DataTableRow,\n  DataTableStateRows,\n} from '@/registry/components/dashboardblocks/table'\nimport {\n  formatCurrency,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\n\ninterface ProductRow {\n  category: string\n  name: string\n  revenue: number\n  units: number\n}\n\ninterface DataTable2Props extends BlockStateProps {\n  /** Defaults to a sentence with the total and the top product's share. */\n  description?: string\n  /** Follows the total in the default description. */\n  period?: string\n  /** Leave out, or pass none, to show the empty state. */\n  rows?: ProductRow[]\n  title: string\n}\n\nconst exampleProps: DataTable2Props = {\n  period: 'in the last 30 days',\n  rows: [\n    { category: 'Displays', name: 'Studio Display 27\"', revenue: 48_920, units: 112 },\n    { category: 'Audio', name: 'Wireless headphones', revenue: 41_370, units: 287 },\n    { category: 'Furniture', name: 'Ergonomic chair', revenue: 36_540, units: 84 },\n    { category: 'Accessories', name: 'Mechanical keyboard', revenue: 21_480, units: 179 },\n    { category: 'Accessories', name: 'USB-C dock', revenue: 12_960, units: 144 },\n    { category: 'Audio', name: 'Desk speakers', revenue: 8_730, units: 97 },\n  ],\n  title: 'Revenue by product',\n}\n\nconst share = (value: number, total: number) =>\n  formatPercent(total > 0 ? value / total : 0, { maximumFractionDigits: 0 })\n\nconst DataTable2 = (props: DataTable2Props) => {\n  const { period, rows = [], errorMessage, status, title } = props\n  const sorted = [...rows].sort((a, b) => b.revenue - a.revenue)\n  const total = rows.reduce((sum, row) => sum + row.revenue, 0)\n  const top = sorted[0]\n  const {\n    description = top\n      ? `${formatCurrency(total)} from ${rows.length} products${period ? ` ${period}` : ''}; ${top.name} brings in ${share(top.revenue, total)}.`\n      : `No sales${period ? ` ${period}` : ''}.`,\n  } = props\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={getBlockState(status, rows)}>\n      <section className='@container/data-table 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'>{description}</p>\n          </BlockReady>\n        </header>\n        <DataTable caption={`${title}: ${description}`}>\n          <DataTableHeader>\n            <DataTableRow>\n              <DataTableHead>Product</DataTableHead>\n              <DataTableHead align='end'>Units</DataTableHead>\n              <DataTableHead className='w-2/5'>Revenue</DataTableHead>\n              <DataTableHead align='end'>Share</DataTableHead>\n            </DataTableRow>\n          </DataTableHeader>\n          <DataTableBody>\n            <DataTableStateRows colSpan={4} rows={6} />\n            {!status &&\n              sorted.map((row) => (\n                <DataTableRow key={row.name}>\n                  <DataTableCell primary>\n                    <span className='block'>{row.name}</span>\n                    <span className='text-muted-foreground block text-xs font-normal'>\n                      {row.category}\n                    </span>\n                  </DataTableCell>\n                  <DataTableCell align='end'>{formatNumber(row.units)}</DataTableCell>\n                  <DataTableCell>\n                    <span className='flex w-full items-center gap-3'>\n                      <DataTableBar max={top?.revenue ?? 0} value={row.revenue} />\n                      <span className='w-16 shrink-0 text-right tabular-nums'>\n                        {formatCurrency(row.revenue)}\n                      </span>\n                    </span>\n                  </DataTableCell>\n                  <DataTableCell align='end' className='text-muted-foreground'>\n                    {share(row.revenue, total)}\n                  </DataTableCell>\n                </DataTableRow>\n              ))}\n          </DataTableBody>\n        </DataTable>\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { DataTable2, exampleProps as dataTable2ExampleProps, type DataTable2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/data-table/data-table-02.tsx"
    }
  ],
  "meta": {
    "shows": "Revenue by product, each with a bar scaled to the top product and its share of the total.",
    "size": "full",
    "usedWith": [
      "chart-panel-01",
      "breakdown-01",
      "leaderboard-01"
    ],
    "component": "DataTable2",
    "props": "{ description?: string; period?: string; rows?: { category: string; name: string; revenue: number; units: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
