{
  "name": "table",
  "type": "registry:ui",
  "framework": "react",
  "title": "Table",
  "description": "A bordered data table with sortable headings, selectable rows and a caption.",
  "files": [
    {
      "path": "ui/table.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/*\n * A real `<table>`, so rows, columns and headers are announced as what they\n * are. The wrapper is what scrolls sideways on a narrow screen, which keeps\n * the table itself from pushing the page wide. `className` lands on the\n * table; the wrapper takes `wrapperClassName`.\n */\nexport interface TableProps extends React.ComponentProps<\"table\"> {\n  wrapperClassName?: string\n}\n\nconst Table = React.forwardRef<HTMLTableElement, TableProps>(\n  ({ className, wrapperClassName, ...props }, ref) => (\n    <div\n      className={cn(\n        \"w-full overflow-x-auto rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-surface\",\n        wrapperClassName\n      )}\n    >\n      <table\n        ref={ref}\n        className={cn(\n          \"w-full border-collapse text-sm leading-5 text-newt-text-secondary\",\n          className\n        )}\n        {...props}\n      />\n    </div>\n  )\n)\nTable.displayName = \"Table\"\n\nconst TableHeader = React.forwardRef<\n  HTMLTableSectionElement,\n  React.ComponentProps<\"thead\">\n>((props, ref) => <thead ref={ref} {...props} />)\nTableHeader.displayName = \"TableHeader\"\n\nconst TableBody = React.forwardRef<\n  HTMLTableSectionElement,\n  React.ComponentProps<\"tbody\">\n>(({ className, ...props }, ref) => (\n  <tbody\n    ref={ref}\n    className={cn(\n      \"[&>tr:hover]:bg-newt-bg-hover [&>tr:not(:first-child)>td]:border-t [&>tr:not(:first-child)>td]:border-newt-border\",\n      className\n    )}\n    {...props}\n  />\n))\nTableBody.displayName = \"TableBody\"\n\nexport interface TableRowProps extends React.ComponentProps<\"tr\"> {\n  /** Marks the row as chosen, for a table whose rows can be picked. */\n  selected?: boolean\n}\n\nconst TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(\n  ({ className, selected, ...props }, ref) => (\n    <tr\n      ref={ref}\n      aria-selected={selected}\n      className={cn(\n        \"aria-selected:bg-newt-bg-active aria-selected:text-newt-text-primary\",\n        className\n      )}\n      {...props}\n    />\n  )\n)\nTableRow.displayName = \"TableRow\"\n\n/** Which way a column is sorted. `none` means sortable, not sorted by. */\nexport type TableSort = \"ascending\" | \"descending\" | \"none\"\n\nexport interface TableHeadProps extends Omit<\n  React.ComponentProps<\"th\">,\n  \"align\"\n> {\n  /** `end` aligns the column to the inline end, for numbers. */\n  align?: \"start\" | \"end\"\n  /** Makes the heading a button and states the column's sort order. */\n  sort?: TableSort\n  /** Called when the sortable heading is activated. */\n  onSort?: () => void\n}\n\nconst TableHead = React.forwardRef<HTMLTableCellElement, TableHeadProps>(\n  (\n    {\n      className,\n      align = \"start\",\n      sort,\n      onSort,\n      scope = \"col\",\n      children,\n      ...props\n    },\n    ref\n  ) => (\n    <th\n      ref={ref}\n      scope={scope}\n      aria-sort={sort}\n      className={cn(\n        \"whitespace-nowrap border-b border-newt-border bg-newt-bg-elevated px-4 py-2.5 text-xs font-bold uppercase tracking-[0.02em] text-newt-text-muted\",\n        align === \"end\" ? \"text-end\" : \"text-start\",\n        className\n      )}\n      {...props}\n    >\n      {sort === undefined ? (\n        children\n      ) : (\n        <button\n          type=\"button\"\n          onClick={onSort}\n          className={cn(\n            \"-mx-1.5 -my-1 inline-flex items-center gap-1 rounded-[var(--newt-radius-sm)] px-1.5 py-1 uppercase tracking-[inherit] hover:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-newt-text-link\",\n            sort !== \"none\" && \"text-newt-text-primary\"\n          )}\n        >\n          {children}\n          <svg\n            viewBox=\"0 0 16 16\"\n            aria-hidden=\"true\"\n            className={cn(\n              \"h-3 w-3\",\n              sort === \"none\" && \"opacity-0\",\n              sort === \"descending\" && \"rotate-180\"\n            )}\n          >\n            <path\n              fill=\"currentColor\"\n              d=\"M8 3.5a1 1 0 0 1 .7.3l3.5 3.5a1 1 0 0 1-1.4 1.4L8 5.9 5.2 8.7a1 1 0 0 1-1.4-1.4l3.5-3.5a1 1 0 0 1 .7-.3Z\"\n            />\n          </svg>\n        </button>\n      )}\n    </th>\n  )\n)\nTableHead.displayName = \"TableHead\"\n\nexport interface TableCellProps extends Omit<\n  React.ComponentProps<\"td\">,\n  \"align\"\n> {\n  /** `end` aligns the cell to the inline end and sets tabular figures. */\n  align?: \"start\" | \"end\"\n}\n\nconst TableCell = React.forwardRef<HTMLTableCellElement, TableCellProps>(\n  ({ className, align = \"start\", ...props }, ref) => (\n    <td\n      ref={ref}\n      className={cn(\n        \"whitespace-nowrap px-4 py-2.5\",\n        align === \"end\" ? \"text-end tabular-nums\" : \"text-start\",\n        className\n      )}\n      {...props}\n    />\n  )\n)\nTableCell.displayName = \"TableCell\"\n\nconst TableCaption = React.forwardRef<\n  HTMLTableCaptionElement,\n  React.ComponentProps<\"caption\">\n>(({ className, ...props }, ref) => (\n  <caption\n    ref={ref}\n    className={cn(\n      \"caption-bottom border-t border-newt-border px-4 py-2.5 text-start text-xs text-newt-text-muted\",\n      className\n    )}\n    {...props}\n  />\n))\nTableCaption.displayName = \"TableCaption\"\n\nexport {\n  Table,\n  TableHeader,\n  TableBody,\n  TableRow,\n  TableHead,\n  TableCell,\n  TableCaption,\n}\n",
      "type": "registry:ui"
    }
  ]
}