{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table",
  "type": "registry:component",
  "title": "Data Table",
  "description": "Sortable table with sticky header, zebra rows, status pills, an empty state and optional pagination.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "lists",
    "table",
    "data",
    "sort",
    "pagination",
    "pill",
    "analytics"
  ],
  "docs": "https://hyperblur.dev/effects/data-table",
  "files": [
    {
      "path": "registry/hyperblur/data-table.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/data-table.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface DataTableColumn {\n  key: string;\n  header: string;\n  align?: \"left\" | \"center\" | \"right\";\n  render?: (row: Record<string, unknown>) => React.ReactNode;\n  sortable?: boolean;\n}\n\nexport interface DataTableProps extends React.HTMLAttributes<HTMLDivElement> {\n  columns: DataTableColumn[];\n  rows: Record<string, unknown>[];\n  zebra?: boolean;\n  maxHeight?: number;\n  emptyText?: string;\n  pageSize?: number;\n  caption?: string;\n}\n\nconst css = `\n.hb-dt {\n  display: flex;\n  flex-direction: column;\n  min-width: 0;\n  border-radius: 12px;\n  border: 1px solid #262626;\n  background: #111111;\n  color: #ededed;\n  overflow: hidden;\n  font-size: 13px;\n}\n.hb-dt-scroll { overflow: auto; max-height: var(--hb-dt-h, 320px); outline: none; }\n.hb-dt-scroll:focus-visible { box-shadow: inset 0 0 0 2px rgba(47, 123, 255, .6); }\n.hb-dt-table { width: 100%; border-collapse: separate; border-spacing: 0; }\n.hb-dt-table caption {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip: rect(0 0 0 0);\n  white-space: nowrap;\n}\n.hb-dt-th {\n  position: sticky;\n  top: 0;\n  z-index: 1;\n  padding: 0;\n  background: #171717;\n  border-bottom: 1px solid #262626;\n  color: #8f8f8f;\n  font-size: 11px;\n  font-weight: 500;\n  letter-spacing: .04em;\n  text-transform: uppercase;\n  text-align: left;\n  white-space: nowrap;\n}\n.hb-dt-th[data-align=\"right\"] { text-align: right; }\n.hb-dt-th[data-align=\"center\"] { text-align: center; }\n.hb-dt-h {\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  width: 100%;\n  padding: 9px 14px;\n  border: 0;\n  background: none;\n  color: inherit;\n  font: inherit;\n  letter-spacing: inherit;\n  text-transform: inherit;\n  text-align: inherit;\n  cursor: default;\n}\n.hb-dt-th[data-align=\"right\"] .hb-dt-h { justify-content: flex-end; }\n.hb-dt-th[data-align=\"center\"] .hb-dt-h { justify-content: center; }\n.hb-dt-h[data-sortable=\"true\"] { cursor: pointer; transition: color .15s ease; }\n.hb-dt-h[data-sortable=\"true\"]:hover { color: #ededed; }\n.hb-dt-h:focus-visible { outline: 2px solid rgba(47, 123, 255, .7); outline-offset: -2px; border-radius: 4px; }\n.hb-dt-th[aria-sort=\"ascending\"], .hb-dt-th[aria-sort=\"descending\"] { color: #ededed; }\n.hb-dt-arrow { width: 8px; height: 10px; flex: none; opacity: .35; transition: opacity .15s ease, transform .2s ease; }\n.hb-dt-th[aria-sort=\"ascending\"] .hb-dt-arrow,\n.hb-dt-th[aria-sort=\"descending\"] .hb-dt-arrow { opacity: 1; }\n.hb-dt-th[aria-sort=\"descending\"] .hb-dt-arrow { transform: rotate(180deg); }\n.hb-dt-td {\n  padding: 10px 14px;\n  border-bottom: 1px solid #1c1c1c;\n  text-align: left;\n  font-weight: 400;\n  white-space: nowrap;\n}\n.hb-dt-td[data-align=\"right\"] { text-align: right; font-variant-numeric: tabular-nums; }\n.hb-dt-td[data-align=\"center\"] { text-align: center; }\n.hb-dt-tr:last-child .hb-dt-td { border-bottom: 0; }\n.hb-dt[data-zebra=\"true\"] .hb-dt-tr:nth-child(even) .hb-dt-td { background: rgba(255, 255, 255, .02); }\n.hb-dt-tr { transition: background-color .15s ease; }\n.hb-dt-tr:hover .hb-dt-td { background: rgba(255, 255, 255, .045); }\n.hb-dt-empty { padding: 28px 14px; text-align: center; color: #8f8f8f; }\n.hb-dt-foot {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 12px;\n  padding: 8px 12px;\n  border-top: 1px solid #262626;\n  background: #131313;\n  color: #8f8f8f;\n  font-size: 12px;\n}\n.hb-dt-range { font-variant-numeric: tabular-nums; }\n.hb-dt-pager { display: flex; align-items: center; gap: 6px; }\n.hb-dt-btn {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 26px;\n  height: 26px;\n  padding: 0;\n  border-radius: 7px;\n  border: 1px solid #262626;\n  background: #171717;\n  color: #ededed;\n  cursor: pointer;\n  transition: border-color .15s ease, background-color .15s ease, opacity .15s ease;\n}\n.hb-dt-btn:hover:not(:disabled) { border-color: #3a3a3a; background: #1f1f1f; }\n.hb-dt-btn:focus-visible { outline: 2px solid rgba(47, 123, 255, .7); outline-offset: 1px; }\n.hb-dt-btn:disabled { opacity: .35; cursor: default; }\n.hb-dt-btn svg { width: 12px; height: 12px; }\n.hb-dt-pill {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  padding: 2px 9px 2px 7px;\n  border-radius: 999px;\n  font-size: 11px;\n  font-weight: 500;\n  line-height: 1.5;\n  color: var(--hb-pill);\n  background: color-mix(in srgb, var(--hb-pill) 14%, transparent);\n  border: 1px solid color-mix(in srgb, var(--hb-pill) 28%, transparent);\n}\n.hb-dt-pill::before { content: \"\"; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-dt-tr, .hb-dt-h, .hb-dt-arrow, .hb-dt-btn { transition: none !important; }\n}\n`;\n\nconst TONES: Record<string, string> = {\n  paid: \"#22c55e\",\n  active: \"#22c55e\",\n  success: \"#22c55e\",\n  succeeded: \"#22c55e\",\n  completed: \"#22c55e\",\n  delivered: \"#22c55e\",\n  approved: \"#22c55e\",\n  pending: \"#f5b301\",\n  processing: \"#f5b301\",\n  trial: \"#f5b301\",\n  review: \"#f5b301\",\n  draft: \"#f5b301\",\n  failed: \"#ef4444\",\n  cancelled: \"#ef4444\",\n  canceled: \"#ef4444\",\n  overdue: \"#ef4444\",\n  declined: \"#ef4444\",\n  error: \"#ef4444\",\n  refunded: \"#2f7bff\",\n  scheduled: \"#2f7bff\",\n  new: \"#2f7bff\",\n};\n\nexport function pill(status: string) {\n  const tone = TONES[String(status).trim().toLowerCase()] ?? \"#8f8f8f\";\n  return (\n    <span className=\"hb-dt-pill\" style={{ [\"--hb-pill\" as string]: tone }}>\n      <style href=\"hb-data-table\" precedence=\"default\">{css}</style>\n      {status}\n    </span>\n  );\n}\n\nfunction compare(a: unknown, b: unknown) {\n  const aNil = a === null || a === undefined || a === \"\";\n  const bNil = b === null || b === undefined || b === \"\";\n  if (aNil || bNil) return aNil === bNil ? 0 : aNil ? 1 : -1;\n  if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n  if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();\n  if (typeof a === \"boolean\" && typeof b === \"boolean\") return Number(a) - Number(b);\n  return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: \"base\" });\n}\n\nfunction cellText(value: unknown) {\n  if (value === null || value === undefined) return \"\";\n  if (value instanceof Date) return value.toISOString().slice(0, 10);\n  return String(value);\n}\n\nexport function DataTable({\n  columns,\n  rows,\n  zebra = true,\n  maxHeight = 320,\n  emptyText = \"No results\",\n  pageSize,\n  caption = \"Data table\",\n  className = \"\",\n  style,\n  ...rest\n}: DataTableProps) {\n  const [sort, setSort] = React.useState<{ key: string; dir: \"asc\" | \"desc\" } | null>(null);\n  const [page, setPage] = React.useState(0);\n\n  const sorted = React.useMemo(() => {\n    const indexed = rows.map((row, i) => ({ row, i }));\n    if (!sort) return indexed;\n    const sign = sort.dir === \"asc\" ? 1 : -1;\n    return indexed.sort((x, y) => {\n      const a = x.row[sort.key];\n      const b = y.row[sort.key];\n      const aNil = a === null || a === undefined || a === \"\";\n      const bNil = b === null || b === undefined || b === \"\";\n      if (aNil || bNil) return compare(a, b) || x.i - y.i;\n      return compare(a, b) * sign || x.i - y.i;\n    });\n  }, [rows, sort]);\n\n  const paged = typeof pageSize === \"number\" && pageSize > 0;\n  const size = paged ? Math.floor(pageSize) : sorted.length;\n  const pageCount = paged ? Math.max(1, Math.ceil(sorted.length / size)) : 1;\n  const current = Math.min(page, pageCount - 1);\n  const visible = paged ? sorted.slice(current * size, current * size + size) : sorted;\n  const from = sorted.length === 0 ? 0 : current * size + 1;\n  const to = paged ? Math.min(sorted.length, current * size + size) : sorted.length;\n\n  const toggle = (key: string) => {\n    setPage(0);\n    setSort((prev) => {\n      if (!prev || prev.key !== key) return { key, dir: \"asc\" };\n      if (prev.dir === \"asc\") return { key, dir: \"desc\" };\n      return null;\n    });\n  };\n\n  return (\n    <div\n      className={`hb-dt ${className}`}\n      data-zebra={zebra ? \"true\" : \"false\"}\n      style={{ [\"--hb-dt-h\" as string]: `${maxHeight}px`, ...style }}\n      {...rest}\n    >\n      <style href=\"hb-data-table\" precedence=\"default\">{css}</style>\n      <div className=\"hb-dt-scroll\" role=\"region\" aria-label={caption} tabIndex={0}>\n        <table className=\"hb-dt-table\">\n          <caption>{caption}</caption>\n          <thead>\n            <tr>\n              {columns.map((col) => {\n                const sortable = col.sortable !== false;\n                const dir = sort && sort.key === col.key ? sort.dir : null;\n                return (\n                  <th\n                    key={col.key}\n                    scope=\"col\"\n                    className=\"hb-dt-th\"\n                    data-align={col.align ?? \"left\"}\n                    aria-sort={sortable ? (dir === \"asc\" ? \"ascending\" : dir === \"desc\" ? \"descending\" : \"none\") : undefined}\n                  >\n                    {sortable ? (\n                      <button type=\"button\" className=\"hb-dt-h\" data-sortable=\"true\" onClick={() => toggle(col.key)}>\n                        {col.header}\n                        <svg className=\"hb-dt-arrow\" viewBox=\"0 0 8 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                          <path d=\"M4 9V1.5M1.2 4.2 4 1.4l2.8 2.8\" />\n                        </svg>\n                      </button>\n                    ) : (\n                      <span className=\"hb-dt-h\">{col.header}</span>\n                    )}\n                  </th>\n                );\n              })}\n            </tr>\n          </thead>\n          <tbody>\n            {visible.length === 0 ? (\n              <tr>\n                <td className=\"hb-dt-empty\" colSpan={Math.max(1, columns.length)}>\n                  {emptyText}\n                </td>\n              </tr>\n            ) : (\n              visible.map(({ row, i }) => (\n                <tr key={i} className=\"hb-dt-tr\">\n                  {columns.map((col, c) => {\n                    const content = col.render ? col.render(row) : cellText(row[col.key]);\n                    return c === 0 ? (\n                      <th key={col.key} scope=\"row\" className=\"hb-dt-td\" data-align={col.align ?? \"left\"}>\n                        {content}\n                      </th>\n                    ) : (\n                      <td key={col.key} className=\"hb-dt-td\" data-align={col.align ?? \"left\"}>\n                        {content}\n                      </td>\n                    );\n                  })}\n                </tr>\n              ))\n            )}\n          </tbody>\n        </table>\n      </div>\n      {paged ? (\n        <div className=\"hb-dt-foot\">\n          <span className=\"hb-dt-range\" aria-live=\"polite\">\n            {from}-{to} of {sorted.length}\n          </span>\n          <div className=\"hb-dt-pager\">\n            <button\n              type=\"button\"\n              className=\"hb-dt-btn\"\n              aria-label=\"Previous page\"\n              disabled={current === 0}\n              onClick={() => setPage(current - 1)}\n            >\n              <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M7.5 2.5 4 6l3.5 3.5\" />\n              </svg>\n            </button>\n            <button\n              type=\"button\"\n              className=\"hb-dt-btn\"\n              aria-label=\"Next page\"\n              disabled={current >= pageCount - 1}\n              onClick={() => setPage(current + 1)}\n            >\n              <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M4.5 2.5 8 6l-3.5 3.5\" />\n              </svg>\n            </button>\n          </div>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}