{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table-01",
  "description": "A table of rows with sortable column headers.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/data-table.json",
    "https://www.dashboardblocks.com/r/radix/format.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/data-table/data-table-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  createDataTableColumnHelper,\n  DataTableContent,\n  useDataTable,\n} from '@/registry/components/dashboardblocks/data-table'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\ninterface PageRow {\n  bounceRate: number\n  /** Average time on page, in seconds. */\n  duration: number\n  path: string\n  views: number\n  visitors: number\n}\n\ninterface DataTable1Props extends BlockStateProps {\n  /** Defaults to a sentence counting page views and the top page's share. */\n  description?: string\n  /** Follows the page view count in the default description. */\n  period?: string\n  /** Leave out, or pass none, to show the empty state. */\n  rows?: PageRow[]\n  title: string\n}\n\nconst exampleProps: DataTable1Props = {\n  period: 'in the last 30 days',\n  rows: [\n    { bounceRate: 38, duration: 102, path: '/', views: 61_240, visitors: 18_420 },\n    { bounceRate: 29, duration: 148, path: '/pricing', views: 21_860, visitors: 9_312 },\n    {\n      bounceRate: 22,\n      duration: 263,\n      path: '/docs/getting-started',\n      views: 19_470,\n      visitors: 7_845,\n    },\n    {\n      bounceRate: 61,\n      duration: 71,\n      path: '/blog/launch-week',\n      views: 8_930,\n      visitors: 5_127,\n    },\n    {\n      bounceRate: 34,\n      duration: 184,\n      path: '/docs/components',\n      views: 12_310,\n      visitors: 4_906,\n    },\n    { bounceRate: 47, duration: 95, path: '/changelog', views: 6_120, visitors: 3_284 },\n    { bounceRate: 18, duration: 52, path: '/signup', views: 4_410, visitors: 2_971 },\n  ],\n  title: 'Top pages',\n}\n\nconst formatDuration = (seconds: number) =>\n  `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, '0')}s`\n\nconst summarize = (rows: PageRow[], period?: string) => {\n  const views = rows.reduce((sum, row) => sum + row.views, 0)\n  const top = rows.reduce<PageRow | undefined>(\n    (best, row) => (best && best.views >= row.views ? best : row),\n    undefined,\n  )\n  if (!top || views === 0) return `No page views${period ? ` ${period}` : ''}.`\n  return `${formatNumber(views)} page views${period ? ` ${period}` : ''}; the top page, ${top.path}, gets ${formatPercent(top.views / views, { maximumFractionDigits: 0 })} of them.`\n}\n\nconst noRows: PageRow[] = []\n\nconst columnHelper = createDataTableColumnHelper<PageRow>()\n\nconst columns = columnHelper.columns([\n  columnHelper.accessor('path', {\n    header: 'Page',\n    meta: { primary: true, truncate: true },\n  }),\n  columnHelper.accessor('visitors', {\n    cell: ({ getValue }) => formatNumber(getValue()),\n    header: 'Visitors',\n    meta: { align: 'end' },\n  }),\n  columnHelper.accessor('views', {\n    cell: ({ getValue }) => formatNumber(getValue()),\n    header: 'Views',\n    meta: { align: 'end' },\n  }),\n  columnHelper.accessor('bounceRate', {\n    cell: ({ getValue }) => formatPercent(getValue() / 100, { maximumFractionDigits: 0 }),\n    header: 'Bounce rate',\n    meta: { align: 'end' },\n  }),\n  columnHelper.accessor('duration', {\n    cell: ({ getValue }) => formatDuration(getValue()),\n    header: 'Avg time',\n    meta: { align: 'end' },\n  }),\n])\n\nconst DataTable1 = (props: DataTable1Props) => {\n  const { period, rows = noRows, errorMessage, status, title } = props\n  const { description = summarize(rows, period) } = props\n  const table = useDataTable({\n    columns,\n    data: rows,\n    initialState: { sorting: [{ desc: true, id: 'visitors' }] },\n  })\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={getBlockState(status, rows)}>\n      <section className='@container/data-table flex flex-col gap-3'>\n        <header className='flex items-start justify-between gap-3'>\n          <div className='flex min-w-0 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          </div>\n        </header>\n        <DataTableContent caption={`${title}: ${description}`} table={table} />\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { DataTable1, exampleProps as dataTable1ExampleProps, type DataTable1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/data-table/data-table-01.tsx"
    }
  ],
  "meta": {
    "shows": "A table of rows with sortable column headers.",
    "size": "full",
    "usedWith": [
      "data-table-06",
      "stat-group-02"
    ],
    "component": "DataTable1",
    "props": "{ description?: string; period?: string; rows?: { bounceRate: number; duration: number; path: string; views: number; visitors: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
