{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "table",
  "title": "Table",
  "author": "superzero11 <https://github.com/superzero11/uiset>",
  "description": "A plain HTML table in a scroll area: sticky headings, a sticky first column, and rows that stack into labelled blocks on narrow screens.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.5",
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://uiset.dev/r/uiset.json",
    "https://uiset.dev/r/scroll-area.json"
  ],
  "files": [
    {
      "path": "registry/uiset/ui/table.tsx",
      "content": "\"use client\"\n\nimport {\n  createContext,\n  useContext,\n  useEffect,\n  useRef,\n  type ComponentProps,\n  type CSSProperties,\n} from \"react\"\nimport {\n  ScrollArea,\n  ScrollAreaContent,\n  ScrollAreaCorner,\n  ScrollAreaScrollbar,\n  ScrollAreaThumb,\n  ScrollAreaViewport,\n} from \"./scroll-area\"\nimport \"./table/table.css\"\n\n// Browsers have dropped a table's roles when CSS changes its display, which stacking does,\n// so a table that stacks states each role itself.\nconst Stacks = createContext(false)\n\n/** Copies each column's heading onto its cells, for the stacked layout to print beside them. */\nfunction labelCells(table: HTMLTableElement) {\n  const headings = [...table.querySelectorAll(\"thead tr:last-child > *\")].map(\n    (cell) => cell.textContent?.trim() ?? \"\",\n  )\n  for (const row of table.querySelectorAll(\":scope > :is(tbody, tfoot) > tr\")) {\n    ;[...row.children].forEach((cell, index) => {\n      if (cell.hasAttribute(\"data-own-label\")) return\n      const heading = headings[index]\n      if (heading && cell.getAttribute(\"data-label\") !== heading)\n        cell.setAttribute(\"data-label\", heading)\n    })\n  }\n}\n\nfunction Table({\n  label,\n  stack = false,\n  stickyHeader = false,\n  stickyColumn = false,\n  maxHeight,\n  minWidth,\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<\"table\">, \"aria-label\"> & {\n  /** Names the table's scrolling region for screen readers and agents. */\n  label: string\n  /** Below 30rem of its own width, each row becomes a block of labelled values. */\n  stack?: boolean\n  /** Keeps the headings in view while the body scrolls. Give it a `maxHeight`. */\n  stickyHeader?: boolean\n  /** Keeps each row's first cell in view while the rest scrolls sideways. */\n  stickyColumn?: boolean\n  maxHeight?: string\n  /** The narrowest the table gets before it scrolls sideways, like \"40rem\". */\n  minWidth?: string\n}) {\n  const table = useRef<HTMLTableElement>(null)\n  useEffect(() => {\n    const element = table.current\n    if (!stack || !element) return\n    labelCells(element)\n    const observer = new MutationObserver(() => labelCells(element))\n    observer.observe(element, { childList: true, subtree: true, characterData: true })\n    return () => observer.disconnect()\n  }, [stack])\n  return (\n    <ScrollArea\n      className={[\"table-frame\", className].filter(Boolean).join(\" \")}\n      data-stack={stack ? \"\" : undefined}\n      data-sticky-header={stickyHeader ? \"\" : undefined}\n      data-sticky-column={stickyColumn ? \"\" : undefined}\n      style={\n        { \"--table-max-height\": maxHeight, \"--table-min-width\": minWidth } as CSSProperties\n      }\n    >\n      <ScrollAreaViewport role=\"region\" aria-label={label}>\n        <ScrollAreaContent>\n          <Stacks value={stack}>\n            <table ref={table} role={stack ? \"table\" : undefined} className=\"table\" {...props}>\n              {children}\n            </table>\n          </Stacks>\n        </ScrollAreaContent>\n      </ScrollAreaViewport>\n      <ScrollAreaScrollbar orientation=\"horizontal\">\n        <ScrollAreaThumb />\n      </ScrollAreaScrollbar>\n      <ScrollAreaScrollbar orientation=\"vertical\">\n        <ScrollAreaThumb />\n      </ScrollAreaScrollbar>\n      <ScrollAreaCorner />\n    </ScrollArea>\n  )\n}\n\nfunction TableCaption(props: ComponentProps<\"caption\">) {\n  return <caption {...props} />\n}\n\nfunction TableHeader(props: ComponentProps<\"thead\">) {\n  return <thead role={useContext(Stacks) ? \"rowgroup\" : undefined} {...props} />\n}\n\nfunction TableBody(props: ComponentProps<\"tbody\">) {\n  return <tbody role={useContext(Stacks) ? \"rowgroup\" : undefined} {...props} />\n}\n\nfunction TableFooter(props: ComponentProps<\"tfoot\">) {\n  return <tfoot role={useContext(Stacks) ? \"rowgroup\" : undefined} {...props} />\n}\n\nfunction TableRow(props: ComponentProps<\"tr\">) {\n  return <tr role={useContext(Stacks) ? \"row\" : undefined} {...props} />\n}\n\ntype Align = \"start\" | \"center\" | \"end\"\n\nfunction TableHead({\n  align,\n  scope = \"col\",\n  ...props\n}: Omit<ComponentProps<\"th\">, \"align\"> & { align?: Align }) {\n  const stacks = useContext(Stacks)\n  return (\n    <th\n      scope={scope}\n      role={stacks ? (scope === \"row\" ? \"rowheader\" : \"columnheader\") : undefined}\n      data-align={align}\n      {...props}\n    />\n  )\n}\n\nfunction TableCell({\n  align,\n  label,\n  ...props\n}: Omit<ComponentProps<\"td\">, \"align\"> & {\n  align?: Align\n  /** What the stacked layout prints beside this cell, when it isn't the column's heading. */\n  label?: string\n}) {\n  return (\n    <td\n      role={useContext(Stacks) ? \"cell\" : undefined}\n      data-align={align}\n      data-label={label}\n      data-own-label={label === undefined ? undefined : \"\"}\n      {...props}\n    />\n  )\n}\n\nexport {\n  Table,\n  TableBody,\n  TableCaption,\n  TableCell,\n  TableFooter,\n  TableHead,\n  TableHeader,\n  TableRow,\n}\n",
      "type": "registry:ui",
      "target": "@ui/table.tsx"
    },
    {
      "path": "registry/uiset/ui/table/table.css",
      "content": "@layer ui-sdk, uiset.tokens, uiset.base, uiset.skin;\n\n@layer uiset.base {\n  .table-frame {\n    /* What sticky cells paint over the rows that pass under them. Set it to the surface\n       the table sits on, like a card's. */\n    --table-background: var(--ui-background);\n    container: uiset-table / inline-size;\n    width: 100%;\n    background: var(--table-background);\n\n    & > [data-slot=\"scroll-area-viewport\"] {\n      max-height: var(--table-max-height, none);\n    }\n\n    & [data-slot=\"scroll-area-content\"] {\n      padding: 0;\n    }\n\n    /* Room for the sideways scrollbar, which would otherwise lie over the last row. */\n    &[data-overflow-x] [data-slot=\"scroll-area-content\"] {\n      padding-block-end: 0.625rem;\n    }\n  }\n\n  /* Separate borders: with collapsed ones, a sticky cell's border scrolls away without it. */\n  .table {\n    width: 100%;\n    min-width: var(--table-min-width, 0);\n    border-collapse: separate;\n    border-spacing: 0;\n    font-size: var(--ui-font-size);\n    font-variant-numeric: tabular-nums;\n    line-height: 1.4;\n\n    & :is(th, td) {\n      padding: calc(var(--ui-spacing) * 2.5) calc(var(--ui-spacing) * 3);\n      border-block-end: 1px solid var(--ui-border);\n      text-align: start;\n      vertical-align: middle;\n\n      &[data-align=\"center\"] {\n        text-align: center;\n      }\n\n      &[data-align=\"end\"] {\n        text-align: end;\n      }\n    }\n\n    & thead th {\n      color: var(--ui-muted-foreground);\n      font-weight: 600;\n      white-space: nowrap;\n    }\n\n    & tbody th {\n      font-weight: 600;\n    }\n\n    & tbody:last-child > tr:last-child > :is(th, td),\n    & tfoot > tr:last-child > :is(th, td) {\n      border-block-end: 0;\n    }\n\n    & tfoot :is(th, td) {\n      font-weight: 600;\n    }\n\n    & caption {\n      caption-side: bottom;\n      padding: calc(var(--ui-spacing) * 2.5) calc(var(--ui-spacing) * 3);\n      border-block-start: 1px solid var(--ui-border);\n      color: var(--ui-muted-foreground);\n      font-size: 0.8125rem;\n      text-align: start;\n    }\n  }\n\n  .table-frame[data-sticky-header] .table thead th {\n    position: sticky;\n    inset-block-start: 0;\n    z-index: 1;\n    background: var(--table-background);\n  }\n\n  .table-frame[data-sticky-column] .table tr > :first-child {\n    position: sticky;\n    inset-inline-start: 0;\n    z-index: 1;\n    background: var(--table-background);\n  }\n\n  .table-frame[data-sticky-column][data-sticky-header] .table thead tr > :first-child {\n    z-index: 2;\n  }\n\n  /* An edge on the kept column, once the rest has moved under it. A shadow, because a\n     border here would notch the line under each row. */\n  .table-frame[data-sticky-column][data-overflow-x]:not([data-at-x-start])\n    .table\n    tr\n    > :first-child {\n    box-shadow: 1px 0 0 var(--ui-border);\n\n    &:dir(rtl) {\n      box-shadow: -1px 0 0 var(--ui-border);\n    }\n  }\n\n  @media (forced-colors: active) {\n    .table-frame[data-sticky-column][data-overflow-x]:not([data-at-x-start])\n      .table\n      tr\n      > :first-child {\n      border-inline-end: 1px solid CanvasText;\n    }\n  }\n\n  @container uiset-table (max-width: 30rem) {\n    /* Stacked rows run long: the page scrolls them, not a box inside the page. */\n    .table-frame[data-stack] > [data-slot=\"scroll-area-viewport\"] {\n      max-height: none;\n    }\n\n    .table-frame[data-stack] .table {\n      min-width: 0;\n\n      &,\n      & :is(tbody, tfoot, tr, th, td, caption) {\n        display: block;\n      }\n\n      /* Out of sight, still in the table: screen readers keep the column headings. */\n      & thead {\n        position: absolute;\n        width: 1px;\n        height: 1px;\n        overflow: hidden;\n        clip-path: inset(50%);\n        white-space: nowrap;\n      }\n\n      & tr {\n        padding: calc(var(--ui-spacing) * 2) calc(var(--ui-spacing) * 3);\n        border-block-end: 1px solid var(--ui-border);\n      }\n\n      & tbody:last-child > tr:last-child,\n      & tfoot > tr:last-child {\n        border-block-end: 0;\n      }\n\n      & tr > :is(th, td) {\n        position: relative;\n        min-height: 1lh;\n        padding: calc(var(--ui-spacing) * 1) 0;\n        padding-inline-start: 42%;\n        border: 0;\n        background: none;\n        text-align: start;\n        overflow-wrap: anywhere;\n      }\n\n      /* The empty alt text keeps screen readers from saying the heading twice. */\n      & tr > :is(th, td)[data-label]::before {\n        position: absolute;\n        inset-inline-start: 0;\n        width: 38%;\n        color: var(--ui-muted-foreground);\n        font-weight: 500;\n        content: attr(data-label);\n        content: attr(data-label) / \"\";\n      }\n\n      & tr > :is(th, td):not([data-label]) {\n        padding-inline-start: 0;\n      }\n\n      & tr > :is(th, td):empty {\n        display: none;\n      }\n\n      & caption {\n        border-block-start: 0;\n        border-block-end: 1px solid var(--ui-border);\n      }\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/table/table.css"
    }
  ],
  "type": "registry:ui"
}