{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "table",
  "type": "registry:ui",
  "title": "Table",
  "description": "A semantic data table in a keyboard-scrollable region: caption, column and row headers, sortable headers with aria-sort, selectable rows.",
  "dependencies": [
    "lucide-react@^1.49.0"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/table.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/table.tsx",
      "content": "import type { ReactNode, TdHTMLAttributes, ThHTMLAttributes } from 'react';\nimport { ArrowDown, ArrowUp, ChevronsUpDown } from 'lucide-react';\nimport { cn } from '../lib/utils';\n\n/**\n * A data table in a keyboard-scrollable frame. The caption names it (visible, or `hideCaption` for screen readers\n * only). Wide tables scroll sideways inside the frame instead of the page.\n */\nexport function Table({ caption, hideCaption, children, className }: { caption: string; hideCaption?: boolean; children: ReactNode; className?: string }) {\n  return (\n    // A focusable, named region so a keyboard user can scroll a table that overflows.\n    <div role=\"region\" aria-label={caption} tabIndex={0} className={cn('@container w-full overflow-x-auto rounded-kh-lg border border-kh-line bg-kh-surface focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-(--kh-focus)', className)}>\n      <table className=\"w-full border-collapse text-left text-kh-small\">\n        <caption className={cn(hideCaption ? 'sr-only' : 'border-b border-kh-line px-4 py-3 text-left text-kh-body font-medium text-kh-ink')}>{caption}</caption>\n        {children}\n      </table>\n    </div>\n  );\n}\n\nexport const TableHead = ({ children }: { children: ReactNode }) => <thead className=\"bg-kh-surface-2\">{children}</thead>;\nexport const TableBody = ({ children }: { children: ReactNode }) => <tbody className=\"divide-y divide-kh-line\">{children}</tbody>;\nexport const TableFoot = ({ children }: { children: ReactNode }) => <tfoot className=\"border-t border-kh-line bg-kh-surface-2 font-medium\">{children}</tfoot>;\nexport const TableRow = ({ children, selected }: { children: ReactNode; selected?: boolean }) => (\n  <tr aria-selected={selected || undefined} className=\"transition-colors duration-(--kh-dur) hover:bg-kh-surface-2/60 aria-selected:bg-kh-accent-soft\">{children}</tr>\n);\n\nexport type SortState = 'ascending' | 'descending' | 'none';\n\nexport interface TableHeaderProps extends Omit<ThHTMLAttributes<HTMLTableCellElement>, 'onClick'> {\n  /** Makes the header a sort button. Pass the current state; `aria-sort` is set on the cell. */\n  sort?: SortState;\n  onSort?: () => void;\n  align?: 'left' | 'right';\n}\n\n/** A column header (`scope=\"col\"`). With `sort` and `onSort` it holds a button that asks for the next sort order. */\nexport function TableHeader({ sort, onSort, align = 'left', className, children, ...rest }: TableHeaderProps) {\n  const cell = cn('whitespace-nowrap px-4 py-3 text-kh-caption font-medium uppercase tracking-wide text-kh-muted', align === 'right' && 'text-right', className);\n  if (!onSort) return <th scope=\"col\" className={cell} {...rest}>{children}</th>;\n  const Icon = sort === 'ascending' ? ArrowUp : sort === 'descending' ? ArrowDown : ChevronsUpDown;\n  return (\n    <th scope=\"col\" aria-sort={sort ?? 'none'} className={cell} {...rest}>\n      <button\n        type=\"button\"\n        onClick={onSort}\n        className={cn(\n          '-mx-2 inline-flex min-h-9 items-center gap-1.5 rounded-kh px-2 uppercase tracking-wide hover:text-kh-ink focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-(--kh-focus)',\n          sort && sort !== 'none' && 'text-kh-ink',\n          align === 'right' && 'flex-row-reverse',\n        )}\n      >\n        {children}\n        <Icon aria-hidden className=\"size-3.5\" />\n      </button>\n    </th>\n  );\n}\n\n/** A row header cell (`scope=\"row\"`): the thing the rest of the row describes. */\nexport const TableRowHeader = ({ children, className }: { children: ReactNode; className?: string }) => (\n  <th scope=\"row\" className={cn('whitespace-nowrap px-4 py-3 text-left font-medium text-kh-ink', className)}>{children}</th>\n);\n\nexport function TableCell({ align = 'left', className, children, ...rest }: TdHTMLAttributes<HTMLTableCellElement> & { align?: 'left' | 'right' }) {\n  return <td className={cn('px-4 py-3 text-kh-ink-2', align === 'right' && 'text-right tabular-nums', className)} {...rest}>{children}</td>;\n}\n"
    }
  ]
}
