{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-data-table",
  "type": "registry:ui",
  "title": "react-tw/data-table.tsx",
  "description": "Carbon `DataTable` as a React + Tailwind component driven by data, with the rules of core/table Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-grid",
    "@kanok-ui/core-table",
    "@kanok-ui/tw-checkbox",
    "@kanok-ui/tw-data-table-columns",
    "@kanok-ui/tw-data-table-csv",
    "@kanok-ui/tw-data-table-grid",
    "@kanok-ui/tw-data-table-parts",
    "@kanok-ui/tw-data-table-resize",
    "@kanok-ui/tw-data-table-skeleton",
    "@kanok-ui/tw-dom",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-pagination",
    "@kanok-ui/tw-refs",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/data-table.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/data-table.tsx",
      "content": "import { useEffect, useLayoutEffect, useRef, useState, type ReactNode, type ComponentProps } from 'react';\nimport { cellText, filterRows as filterTableRows, type SortContext, type SortDirection } from '../core/table.ts';\nimport type { CellEditor } from '../core/grid.ts';\nimport { DataTable as DataTablePrimitive } from '@purpurabog/ui/headless';\nimport { Checkbox } from './checkbox.tsx';\nimport { GridDataCell, gridFocusRing, type DataTableCellEdit, type DataTableEditOption } from './data-table-grid.tsx';\nimport type { DataTableColumnResize } from './data-table-resize.tsx';\nimport { ColumnSettings, type DataTableColumnsChange } from './data-table-columns.tsx';\nimport { measurePins, pinClasses } from './data-table-pins.ts';\nimport { ExportCsvButton, type DataTableCsvExport } from './data-table-csv.tsx';\nimport { Pagination, type PaginationChange } from './pagination.tsx';\nimport { BatchActionsBar, HeaderCell, TableTitle, ToolbarSearch, chevronRight, scrollBoxProps, tableNaming, textOf } from './data-table-parts.tsx';\nimport { ALIGN, PAGINATION_SIZE, SIZES, cellBase, cellClasses, checkboxInCell, expandButtonClasses, rowClasses, type DataTableSize, type RowLook } from './data-table.styles.ts';\nimport { elementByIdIn } from './lib/dom.ts';\nimport { useLanguage, useTranslation } from './lib/i18n.ts';\nimport { useMergedRefs } from './lib/refs.ts';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `DataTable` as a React + Tailwind component driven by data, with the rules of core/table\n * (and the look `<ui-data-table>` had before 1.0.0): `headers` (`{ key, header }`) and `rows` (`{ id, …cells }`).\n * Sizes xs / sm / md / lg (default) / xl, `zebra`, `staticWidth`, a `heading` / `description`\n * header (Carbon `TableContainer`).\n *\n * Sorting (`sortable`, or per column): the header button cycles none → ascending → descending →\n * none, a new column starts ascending and none restores the order of `rows`; `sortRow` replaces\n * the comparison and `manualSorting` leaves `rows` in the order given (sort on the server).\n *\n * Selection: `selectable` adds a checkbox column with select-all (Carbon toggle: it clears when any\n * row is selected), `radio` a single-choice radio column. `batchActions` (buttons) appear on a\n * brand bar over the toolbar while rows are selected, with the count and Cancel.\n *\n * Toolbar: `searchable` adds a filter field (collapsed to its magnifier until focused, or always\n * open with `searchPersistent`); `filterRows` replaces the test and `manualFiltering` leaves it to\n * you. `toolbar` holds more controls. `renderExpandedRow` makes rows expandable (`expandAll` adds the\n * header toggle), `stickyHeader` scrolls the body under the header, `pageSize` pages the rows with a\n * Pagination under the table, `loading` shows skeleton rows. Every state can be controlled\n * (`sortKey`, `selectedIds`, `filterText`, `expandedIds`, `page`, `pageSize`) or left to the table\n * (`default…`). A polite status announces a sort and, once typing pauses, the rows shown.\n *\n * Beyond Carbon: a header's `editable` makes the table an APG editable grid\n * (data-table-grid.tsx; set `rows` from `onCellEdit`), and `resizable` puts a resize handle on the\n * column headers (data-table-resize.tsx; `columnWidths`, `onColumnResize`). `columnSettings` adds a\n * \"Columns\" toolbar button that shows / hides columns (data-table-columns.tsx; `hiddenColumns`,\n * `onColumnsChange`, a header's `hideable` / `hidden`); hidden columns leave the search too. A header's\n * `pinned: 'start'` (first column) / `'end'` (last column) keeps it in view while the table scrolls\n * sideways (IBM Products Datagrid sticky columns; data-table-pins.ts). `csvExport` adds an Export CSV\n * toolbar button (data-table-csv.tsx; `dataTableToCsv` / `downloadCsv` for the selected or all rows).\n */\nexport interface DataTableHeader {\n    /** Property of each row shown in this column. */\n    key: string;\n    /** Column title. */\n    header: string;\n    /** Overrides the table's `sortable` for this column. */\n    sortable?: boolean;\n    /** Text alignment of the column's cells; the header label stays at the start, as in Carbon. */\n    align?: 'start' | 'center' | 'end';\n    /** The column's cells can be edited in place (makes the table an APG editable grid). */\n    editable?: CellEditor;\n    /** Choices of an `editable: 'select'` column; the cell shows the matching label. */\n    options?: DataTableEditOption[];\n    /** Checks an edited value before it is saved; return a message to keep the editor open, '' to accept. */\n    validate?: (value: string | number, row: DataTableRow) => string;\n    /** Overrides the table's `resizable` for this column. */\n    resizable?: boolean;\n    /** Starting width in px (a resized width in `columnWidths` wins). */\n    width?: number;\n    /** Narrowest the column can be resized to, in px (default 50). */\n    minWidth?: number;\n    /** Widest the column can be resized to, in px (default: the table's visible width). */\n    maxWidth?: number;\n    /** `false`: the user can't hide this column from the toolbar's \"Columns\" list (`columnSettings`). */\n    hideable?: boolean;\n    /** Hidden until the user shows it from the \"Columns\" list; Reset hides it again. */\n    hidden?: boolean;\n    /**\n     * Keeps the column in view while the table scrolls sideways (IBM Products Datagrid `sticky`):\n     * `'start'` on the first column (the select / expand columns stay with it; from 672px wide),\n     * `'end'` on the last one (e.g. row actions).\n     */\n    pinned?: 'start' | 'end';\n}\n\nexport interface DataTableRow {\n    /** Stable identity; keeps DOM and selection across sorting. */\n    id: string;\n    /** The row can't be selected. */\n    disabled?: boolean;\n    [key: string]: unknown;\n}\n\nexport type { DataTableSize } from './data-table.styles.ts';\nexport type DataTableSortDirection = SortDirection;\n\nexport interface DataTableSort {\n    key: string;\n    direction: DataTableSortDirection;\n}\n\nexport interface DataTableExpandChange {\n    expandedIds: string[];\n    expanded: boolean;\n    /** The row that opened / closed; absent for expand-all. */\n    id?: string;\n}\n\nexport interface DataTableProps<R extends DataTableRow = DataTableRow> extends Omit<ComponentProps<'div'>, 'headers' | 'rows' | 'size' | 'zebra' | 'staticWidth' | 'heading' | 'description' | 'label' | 'sortable' | 'sortKey' | 'sortDirection' | 'defaultSortKey' | 'defaultSortDirection' | 'onSortChange' | 'manualSorting' | 'sortRow' | 'renderCell' | 'selectable' | 'radio' | 'selectedIds' | 'defaultSelectedIds' | 'onSelectionChange' | 'batchActions' | 'toolbar' | 'searchable' | 'searchPersistent' | 'filterText' | 'defaultFilterText' | 'onFilterChange' | 'filterRows' | 'manualFiltering' | 'searchLabel' | 'searchPlaceholder' | 'renderExpandedRow' | 'expandedIds' | 'defaultExpandedIds' | 'onExpandChange' | 'expandAll' | 'stickyHeader' | 'loading' | 'loadingRows' | 'pageSize' | 'defaultPageSize' | 'page' | 'defaultPage' | 'pageSizes' | 'onPageChange' | 'totalSelected' | 'totalCount' | 'onSelectAll' | 'emptyText' | 'noResultsText' | 'onCellEdit' | 'resizable' | 'columnWidths' | 'defaultColumnWidths' | 'onColumnResize' | 'columnSettings' | 'hiddenColumns' | 'defaultHiddenColumns' | 'onColumnsChange' | 'csvExport' | 'csvFileName' | 'onCsvExport' | 'lang' | 'className'> {\n    headers: DataTableHeader[];\n    rows: R[];\n    size?: DataTableSize;\n    /** Alternate row backgrounds (Carbon `useZebraStyles`). */\n    zebra?: boolean;\n    /** Width follows the content instead of filling the container (Carbon `useStaticWidth`). */\n    staticWidth?: boolean;\n    /** Heading above the table; also names it. */\n    heading?: ReactNode;\n    description?: ReactNode;\n    /** Accessible name when there is no `heading`. */\n    label?: string;\n    /** Every column sorts unless its header sets `sortable: false`. */\n    sortable?: boolean;\n    sortKey?: string;\n    sortDirection?: DataTableSortDirection;\n    defaultSortKey?: string;\n    defaultSortDirection?: DataTableSortDirection;\n    /** After a header click (or the sort you control should change). */\n    onSortChange?: (sort: DataTableSort) => void;\n    /** Keep `rows` in the given order; the headers still show the sort (server-side sorting). */\n    manualSorting?: boolean;\n    /** Replaces the comparison; return as for `Array.prototype.sort` in the given `direction`. */\n    sortRow?: (a: unknown, b: unknown, context: SortContext) => number;\n    /** Renders one cell (default: `row[header.key]` as text). */\n    renderCell?: (row: R, header: DataTableHeader) => ReactNode;\n    /** Checkbox column with select-all; batch actions appear while rows are selected. */\n    selectable?: boolean;\n    /** Single selection with a radio column (Carbon `radio`). */\n    radio?: boolean;\n    selectedIds?: string[];\n    defaultSelectedIds?: string[];\n    onSelectionChange?: (selectedIds: string[], rows: R[]) => void;\n    /** Buttons acting on the selected rows (e.g. `<Button>`; `size=\"sm\"` for xs / sm tables). */\n    batchActions?: ReactNode;\n    /** Controls after the search (an overflow menu, a primary button). */\n    toolbar?: ReactNode;\n    /** Filter field in the toolbar (Carbon `TableToolbarSearch`). */\n    searchable?: boolean;\n    /** Keep the search open instead of collapsing it to its magnifier. */\n    searchPersistent?: boolean;\n    filterText?: string;\n    defaultFilterText?: string;\n    onFilterChange?: (value: string) => void;\n    /** Replaces the row test: return true to keep `row` for `text`. */\n    filterRows?: (row: R, text: string, headers: DataTableHeader[]) => boolean;\n    /** Keep every row; filter yourself on `onFilterChange` (server-side filtering). */\n    manualFiltering?: boolean;\n    /** Search label; default the translation plus the table's name (\"Filter table: Contracts\"). */\n    searchLabel?: string;\n    searchPlaceholder?: string;\n    /** Content of a row's expansion; setting it makes rows expandable. */\n    renderExpandedRow?: (row: R) => ReactNode;\n    expandedIds?: string[];\n    defaultExpandedIds?: string[];\n    onExpandChange?: (change: DataTableExpandChange) => void;\n    /** Header button that expands / collapses every row. */\n    expandAll?: boolean;\n    /** Keep the header visible while the body scrolls in a box (`--ui-data-table-max-height`, 300px). */\n    stickyHeader?: boolean;\n    /** Skeleton rows while data loads; the toolbar and headers stay, the table is `aria-busy`. */\n    loading?: boolean;\n    /** Skeleton rows while `loading` (default: the rows shown now, else the page size, else 5). */\n    loadingRows?: number;\n    /** Rows per page: a Pagination under the table pages the sorted, filtered rows (0: no paging). */\n    pageSize?: number;\n    defaultPageSize?: number;\n    page?: number;\n    defaultPage?: number;\n    pageSizes?: number[];\n    onPageChange?: (change: PaginationChange) => void;\n    /** Selected count for the batch bar when the selection includes rows not in `rows` (server paging). */\n    totalSelected?: number;\n    /** Rows across every page (server paging): the batch bar offers \"Select all (N)\" and calls `onSelectAll`. */\n    totalCount?: number;\n    onSelectAll?: (totalCount: number) => void;\n    /** Shown when there are no rows (default: the translation's \"No data\"). */\n    emptyText?: ReactNode;\n    /** Shown when the filter leaves no rows (default: the translation's \"No results found…\"). */\n    noResultsText?: ReactNode;\n    /** An edited cell was saved: set `rows` to `edit.rows` (or keep yours to refuse it). */\n    onCellEdit?: (edit: DataTableCellEdit<R>) => void;\n    /** Every column gets a resize handle (a header's `resizable` overrides). */\n    resizable?: boolean;\n    /** Column widths in px by header key: the resized ones, or saved ones to restore. */\n    columnWidths?: Record<string, number>;\n    defaultColumnWidths?: Record<string, number>;\n    /** After a column was resized (once per drag or key press). */\n    onColumnResize?: (change: DataTableColumnResize) => void;\n    /** A \"Columns\" button in the toolbar: a checkbox list that shows / hides columns (no Carbon counterpart). */\n    columnSettings?: boolean;\n    /** Keys of the columns not shown (controlled; a header with `hideable: false` always shows). */\n    hiddenColumns?: string[];\n    /** Hidden columns to start with (uncontrolled; default: the headers marked `hidden`). */\n    defaultHiddenColumns?: string[];\n    /** After the user showed / hid a column, or Reset. */\n    onColumnsChange?: (change: DataTableColumnsChange) => void;\n    /** An \"Export CSV\" button in the toolbar: the rows shown (filtered, sorted, every page) and the columns shown (no Carbon counterpart). */\n    csvExport?: boolean;\n    /** Name of the downloaded file (`.csv` is added); default: the heading when it is text, else \"table\". */\n    csvFileName?: string;\n    /** Before the Export CSV button downloads; `preventDefault()` to export another way. */\n    onCsvExport?: (detail: DataTableCsvExport<R>) => void;\n    lang?: string;\n    className?: string;\n}\n\nexport function DataTable<R extends DataTableRow = DataTableRow>({\n    headers,\n    rows,\n    size = 'lg',\n    zebra = false,\n    staticWidth = false,\n    heading,\n    description,\n    label,\n    sortable = false,\n    sortKey,\n    sortDirection,\n    defaultSortKey = '',\n    defaultSortDirection = 'none',\n    onSortChange,\n    manualSorting = false,\n    sortRow,\n    renderCell,\n    selectable = false,\n    radio = false,\n    selectedIds,\n    defaultSelectedIds = [],\n    onSelectionChange,\n    batchActions,\n    toolbar,\n    searchable = false,\n    searchPersistent = false,\n    filterText,\n    defaultFilterText = '',\n    onFilterChange,\n    filterRows,\n    manualFiltering = false,\n    searchLabel,\n    searchPlaceholder,\n    renderExpandedRow,\n    expandedIds,\n    defaultExpandedIds = [],\n    onExpandChange,\n    expandAll = false,\n    stickyHeader = false,\n    loading = false,\n    loadingRows = 0,\n    pageSize,\n    defaultPageSize = 0,\n    page,\n    defaultPage = 1,\n    pageSizes = [10, 25, 50],\n    onPageChange,\n    totalSelected,\n    totalCount,\n    onSelectAll,\n    emptyText,\n    noResultsText,\n    onCellEdit,\n    resizable = false,\n    columnWidths,\n    defaultColumnWidths = {},\n    onColumnResize,\n    columnSettings = false,\n    hiddenColumns,\n    defaultHiddenColumns,\n    onColumnsChange,\n    csvExport = false,\n    csvFileName,\n    onCsvExport,\n    lang,\n    className,\n    ...rest\n}: Readonly<DataTableProps<R>>) {\n    const t = useTranslation(lang).dataTable;\n    const locale = useLanguage(lang);\n    const expandable = renderExpandedRow !== undefined;\n    const table = DataTablePrimitive.useDataTable<R, DataTableHeader>({\n        headers,\n        rows,\n        sortable,\n        sortKey,\n        sortDirection,\n        defaultSortKey,\n        defaultSortDirection,\n        onSortChange,\n        manualSorting,\n        sortRow,\n        locale,\n        selectable,\n        radio,\n        selectedIds,\n        defaultSelectedIds,\n        onSelectionChange,\n        filterText,\n        defaultFilterText,\n        onFilterChange,\n        filterRows,\n        manualFiltering,\n        expandable,\n        expandedIds,\n        defaultExpandedIds,\n        onExpandChange,\n        pageSize,\n        defaultPageSize,\n        page,\n        defaultPage,\n        onPageChange,\n        hiddenColumns,\n        defaultHiddenColumns,\n        onColumnsChange,\n        resizable,\n        columnWidths,\n        defaultColumnWidths,\n        onColumnResize,\n        staticWidth,\n        onCellEdit,\n    });\n    const ids = table.id;\n    const shownHeaders = table.columns;\n    const shown = table.pageRows;\n    const { grid, resize, paged } = table;\n    const [announcement, setAnnouncement] = useState('');\n    const [scrollable, setScrollable] = useState(false);\n    const announceTimer = useRef<ReturnType<typeof setTimeout>>(undefined);\n    const selectAllPending = useRef(false);\n    const content = useRef<HTMLDivElement>(null);\n    const contentRef = useMergedRefs(content, table.boxRef);\n    const bar = useRef<HTMLDivElement>(null);\n\n    const hasSelection = table.selectable;\n    const selectedCount = totalSelected ?? rows.filter((r) => table.isSelected(r.id)).length;\n    const selectAllTotal = totalCount ?? (paged ? table.filteredRows.filter((r) => !r.disabled).length : undefined);\n    const batchActive = selectable && !radio && selectedCount > 0 && batchActions != null;\n\n    // a scrolling box must be reachable by keyboard (WCAG 2.1.1): sticky-header scrolls vertically, a wide table horizontally\n    const { tableRef } = table;\n    useEffect(() => {\n        const box = content.current;\n        const inner = tableRef.current;\n        if (!box || !inner || typeof ResizeObserver === 'undefined') return;\n        const observer = new ResizeObserver(() => setScrollable(box.scrollWidth > box.clientWidth + 1));\n        observer.observe(box);\n        observer.observe(inner);\n        return () => observer.disconnect();\n    }, [tableRef]);\n\n    useEffect(() => () => clearTimeout(announceTimer.current), []);\n\n    // loading starts or ends: say so (not on the first render)\n    const wasLoading = useRef(loading);\n    useEffect(() => {\n        if (wasLoading.current === loading) return;\n        wasLoading.current = loading;\n        setAnnouncement(loading ? t.loading : '');\n    }, [loading, t]);\n\n    // \"Select all (N)\" went away once everything was selected: keep focus in the bar, on Cancel\n    useLayoutEffect(() => {\n        if (!selectAllPending.current || bar.current?.querySelector('[data-select-all-pages]')) return;\n        selectAllPending.current = false;\n        bar.current?.querySelector<HTMLElement>('[data-cancel]')?.focus();\n    });\n\n    const selectAllId = `${ids}select-all`;\n    const cancelSelection = () => {\n        table.setSelectedIds([]);\n        // the bar goes inert under the focused Cancel button: hand focus to select-all, as a closing dialog\n        elementByIdIn(content.current, selectAllId)?.focus();\n    };\n    const selectAllPages = () => {\n        selectAllPending.current = true;\n        if (totalCount == null) table.selectAll();\n        else onSelectAll?.(totalCount);\n    };\n\n    const onSearchChange = (value: string) => {\n        if (value === table.filterText) return;\n        table.setFilterText(value);\n        // one announcement when typing pauses, not one per keystroke; with manual filtering the count is the app's to give\n        clearTimeout(announceTimer.current);\n        if (manualFiltering) return;\n        const shownCount = filterTableRows(rows, shownHeaders, value, filterRows).length;\n        announceTimer.current = setTimeout(() => setAnnouncement(t.rowsShown(shownCount, rows.length)), 500);\n    };\n\n    /** The row's first column, so each row's control has its own name (\"Select row, Load balancer 1\"). */\n    const rowName = (row: R) => {\n        const key = headers[0]?.key;\n        const value = key === undefined ? '' : row[key];\n        return typeof value === 'string' || typeof value === 'number' ? `, ${value}` : '';\n    };\n\n    const sizeLook = SIZES[size];\n    const withBoth = expandable && hasSelection;\n    const selectCell = (isRadio: boolean) =>\n        // a fixed layout (resized columns) ignores the checkbox column's 40px min-inline-size\n        cn(cellBase, isRadio ? 'w-12' : 'w-8', 'min-w-10 ps-4 pe-1', isRadio ? sizeLook.radio : sizeLook.select, withBoth && 'ps-1.5 pe-1.5', resize.fixed && !isRadio && 'w-10');\n    const expandCellClasses = cn(cellBase, 'w-10 p-(--_expand-pad)');\n    // with both the chevron and the selection column, the first column starts at 8px (Carbon)\n    const firstColumn = withBoth ? 'ps-2' : '';\n    // z-2: over pinned body cells scrolling under it; --_head-edge: a pinned header cell keeps this line\n    const sticky = stickyHeader && 'sticky top-0 z-2 [--_head-edge:inset_0_-1px_0_var(--ui-ghost-active)] shadow-[inset_0_-1px_0_var(--ui-ghost-active)]';\n    const pins = table.pins;\n    // the pinned leading cells' offsets follow the select / expand cells' widths\n    useLayoutEffect(() => measurePins(content.current, tableRef.current, pins.start));\n    // --ui-table-header-background: Carbon's layer-accent; a design can use its own, and a rule under it (--ui-table-header-rule)\n    const headCell = cn(cellBase, 'bg-[color:var(--ui-table-header-background,var(--ui-layer-accent))]', sticky || 'shadow-[var(--ui-table-header-rule,0_0_#0000)]');\n    const columnCount = shownHeaders.length + [hasSelection, expandable, resize.hasFiller].filter(Boolean).length;\n\n    const renderSelectAllCell = () => {\n        if (radio) {\n            return (\n                <th scope=\"col\" className={cn(headCell, selectCell(true), 'font-semibold text-[color:var(--ui-table-header-ink,var(--ui-ink))]')}>\n                    <span className=\"sr-only\">{t.selectRow}</span>\n                </th>\n            );\n        }\n        const all = table.getSelectAllProps();\n        // a cell, not a column header: it holds a control, and its label lives in the checkbox\n        return (\n            <td className={cn(headCell, selectCell(false), 'text-ink-muted')}>\n                <Checkbox id={selectAllId} hideLabel label={all.checked || all.indeterminate ? t.unselectAll : t.selectAll} {...all} className={checkboxInCell} />\n            </td>\n        );\n    };\n\n    const renderExpandHeaderCell = () => {\n        // a cell, not a column header: it holds at most a control\n        if (!expandAll) return <td className={cn(headCell, expandCellClasses, 'text-ink-muted')} />;\n        return (\n            <td className={cn(headCell, expandCellClasses, 'text-ink-muted')}>\n                <DataTablePrimitive.ExpandAll aria-label={table.allExpanded ? t.collapseAll : t.expandAll} className={expandButtonClasses}>\n                    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n                        {chevronRight}\n                    </svg>\n                </DataTablePrimitive.ExpandAll>\n            </td>\n        );\n    };\n\n    // in a grid every body cell can be the Tab stop: the focus ring of <ui-data-table>'s editable grid\n    const gridRing = grid.enabled && gridFocusRing;\n    const selectIndex = expandable ? 1 : 0;\n    const dataOffset = selectIndex + (hasSelection ? 1 : 0);\n\n    const renderSelectCell = (row: R, look: RowLook) => {\n        const name = (look.selected ? t.unselectRow : t.selectRow) + rowName(row);\n        if (radio) {\n            return (\n                <DataTablePrimitive.Cell index={selectIndex} className={cn(cellBase, cellClasses(look), selectCell(true), gridRing)}>\n                    {/* the circle centred, margins 1 / -2 / 2 / 2 (Carbon radio cell); the native radio lies on it */}\n                    <span className={cn('relative flex cursor-pointer justify-center text-ink', row.disabled && 'cursor-not-allowed text-ink-disabled')}>\n                        <DataTablePrimitive.SelectRow aria-label={name} className=\"peer absolute start-[calc(50%-7px)] top-px z-1 m-0 size-[18px] cursor-[inherit] opacity-0\" />\n                        <span\n                            aria-hidden=\"true\"\n                            className={cn(\n                                'ms-0.5 -me-0.5 mt-px mb-0.5 box-border grid size-[18px] shrink-0 place-items-center rounded-[50%] border border-solid border-ink bg-transparent',\n                                \"peer-checked:after:size-2 peer-checked:after:rounded-[50%] peer-checked:after:bg-ink peer-checked:after:content-['']\",\n                                'peer-focus:outline-[length:var(--ui-focus-width,2px)] peer-focus:outline-offset-1 peer-focus:outline-focus',\n                                row.disabled && 'border-ink-disabled peer-checked:after:bg-ink-disabled',\n                                'forced-colors:border-[CanvasText] forced-colors:[forced-color-adjust:none] forced-colors:peer-checked:after:bg-[Highlight]',\n                            )}\n                        />\n                    </span>\n                </DataTablePrimitive.Cell>\n            );\n        }\n        return (\n            <DataTablePrimitive.Cell index={selectIndex} className={cn(cellBase, cellClasses(look), selectCell(false), gridRing)}>\n                <Checkbox hideLabel label={name} {...table.getSelectRowProps(row)} className={checkboxInCell} />\n            </DataTablePrimitive.Cell>\n        );\n    };\n\n    const renderRow = (row: R, index: number) => {\n        const isOpen = table.isExpanded(row.id);\n        const look: RowLook = {\n            zebraTable: zebra,\n            zebra: index % 2 === 1,\n            selected: table.isSelected(row.id),\n            first: index === 0,\n            last: index === shown.length - 1 && !isOpen,\n            expanded: isOpen,\n        };\n        const cells = cellClasses(look);\n        const parent = (\n            <DataTablePrimitive.Row\n                key={row.id}\n                rowId={row.id}\n                className={cn(rowClasses(look), isOpen && '[@media(hover:hover)]:[&:has(+tr:hover)]:bg-ghost-hover')}\n            >\n                {expandable ? (\n                    <DataTablePrimitive.Cell index={0} className={cn(expandCellClasses, cellClasses(look, true), gridRing)}>\n                        <DataTablePrimitive.ExpandToggle aria-label={(isOpen ? t.collapseRow : t.expandRow) + rowName(row)} className={expandButtonClasses}>\n                            <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n                                {chevronRight}\n                            </svg>\n                        </DataTablePrimitive.ExpandToggle>\n                    </DataTablePrimitive.Cell>\n                ) : null}\n                {hasSelection ? renderSelectCell(row, look) : null}\n                {shownHeaders.map((header, i) => (\n                    <GridDataCell\n                        key={header.key}\n                        rowId={row.id}\n                        value={row[header.key]}\n                        column={header}\n                        index={dataOffset + i}\n                        className={cn(cellBase, 'pt-(--_cell-pad-start) pb-(--_cell-pad-end)', cells, ALIGN[header.align ?? 'start'], i === 0 && firstColumn)}\n                        content={() => (renderCell ? renderCell(row, header) : cellText(row[header.key]))}\n                        rowName={rowName(row)}\n                    />\n                ))}\n                <DataTablePrimitive.Filler className={cn(cells, 'p-0')} />\n            </DataTablePrimitive.Row>\n        );\n        // one flat list of rows, so opening a row doesn't remount it (a nested array is a new React parent)\n        if (!isOpen) return [parent];\n        const child = (\n            <DataTablePrimitive.ExpandedRow\n                key={`${row.id}-child`}\n                rowId={row.id}\n                className={cn(rowClasses({ ...look, first: false, expanded: false }), '[@media(hover:hover)]:[tr:hover+&]:bg-ghost-hover')}\n            >\n                <td\n                    colSpan={columnCount}\n                    className={cn(\n                        'box-border border-0 border-b border-solid border-b-hairline py-0 pe-4 text-start align-top',\n                        look.selected ? 'text-ink' : 'text-[color:var(--ui-table-cell-ink,var(--ui-ink-muted))] group-hover/row:text-ink',\n                        hasSelection ? 'ps-[88px]' : 'ps-14',\n                    )}\n                >\n                    <div className=\"pt-4 pb-6\">{renderExpandedRow?.(row)}</div>\n                </td>\n            </DataTablePrimitive.ExpandedRow>\n        );\n        return [parent, child];\n    };\n\n    const renderBody = () => {\n        if (loading) {\n            const count = loadingRows || shown.length || table.pageSize || 5;\n            return Array.from({ length: count }, (_, i) => {\n                const look: RowLook = { zebraTable: zebra, zebra: i % 2 === 1, selected: false, first: i === 0, last: i === count - 1, expanded: false };\n                const cells = cellClasses(look);\n                // placeholder rows have no identity: the index is the key\n                return (\n                    <tr /* NOSONAR: skeleton rows: decoration, never focusable */ key={i} aria-hidden=\"true\" className={rowClasses(look)}>\n                        {expandable ? <td className={cn(expandCellClasses, cells)} /> : null}\n                        {hasSelection ? <td className={cn(cellBase, cells, selectCell(radio))} /> : null}\n                        {shownHeaders.map((header) => (\n                            <td key={header.key} className={cn(cellBase, 'pt-(--_cell-pad-start) pb-(--_cell-pad-end)', cells)}>\n                                <span className=\"skeleton block h-4 w-16 max-w-full\" />\n                            </td>\n                        ))}\n                        <DataTablePrimitive.Filler className={cn(cells, 'p-0')} />\n                    </tr>\n                );\n            });\n        }\n        if (shown.length === 0) {\n            const filteredOut = table.filterText.trim() !== '';\n            const look: RowLook = { zebraTable: zebra, zebra: false, selected: false, first: true, last: true, expanded: false };\n            return [\n                <tr key=\"empty\" className={rowClasses(look)}>\n                    <td colSpan={columnCount} className={cn(cellBase, cellClasses(look), 'py-4')}>\n                        {filteredOut ? (noResultsText ?? t.noResults) : (emptyText ?? t.noRows)}\n                    </td>\n                </tr>,\n            ];\n        }\n        return shown.flatMap((row, index) => renderRow(row, index));\n    };\n\n    const renderToolbar = () => {\n        if (toolbar == null && !searchable && !columnSettings && !csvExport && batchActions == null) return null;\n        return (\n            <section /* NOSONAR: as <ui-data-table>: the toolbar's controls form a named group */ role=\"group\" aria-label={t.toolbar} className=\"relative z-1 flex h-(--_toolbar) min-h-(--_toolbar) w-full bg-[color:var(--ui-table-background,var(--ui-surface-1))]\">\n                {batchActions == null ? null : (\n                    <BatchActionsBar\n                        actions={batchActions}\n                        active={batchActive}\n                        selectedCount={selectedCount}\n                        selectAllTotal={selectAllTotal}\n                        t={t}\n                        barRef={bar}\n                        onSelectAll={selectAllPages}\n                        onCancel={cancelSelection}\n                    />\n                )}\n                <div\n                    inert={batchActive}\n                    className={cn(\n                        'flex h-(--_toolbar) w-full justify-end transition-[transform,clip-path] duration-(--ui-duration-moderate) ease-carbon motion-reduce:transition-none [&>:not([data-search])]:shrink-0',\n                        batchActive ? '[clip-path:polygon(0_0,100%_0,100%_0,0_0)] [transform:translate3d(0,var(--_toolbar),0)]' : '[transform:translate3d(0,0,0)]',\n                    )}\n                >\n                    {searchable ? (\n                        <ToolbarSearch\n                            size={size}\n                            persistent={searchPersistent}\n                            filter={table.filterText}\n                            tableName={typeof heading === 'string' && heading ? heading : label}\n                            label={searchLabel}\n                            placeholder={searchPlaceholder}\n                            lang={lang}\n                            t={t}\n                            onChange={onSearchChange}\n                        />\n                    ) : null}\n                    {columnSettings ? <ColumnSettings headers={headers} hidden={table.hiddenColumns} onToggle={table.toggleColumn} onReset={table.resetColumns} t={t} /> : null}\n                    {csvExport ? <ExportCsvButton label={t.exportCsv} columns={shownHeaders} rows={table.sortedRows} fileName={csvFileName ?? textOf(heading) ?? textOf(label) ?? ''} onExport={onCsvExport} /> : null}\n                    {toolbar}\n                </div>\n            </section>\n        );\n    };\n\n    const named = heading != null && heading !== '';\n    const renderTable = () => (\n        <div\n            ref={contentRef}\n            {...scrollBoxProps(stickyHeader || scrollable, named, label, ids)}\n            className={cn(\n                'block overflow-x-auto outline-none focus-visible:rounded-[var(--ui-table-radius,0px)] focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-focus',\n                stickyHeader && 'max-h-(--ui-data-table-max-height,300px) scroll-pt-(--_row) overflow-y-auto',\n            )}\n        >\n            <DataTablePrimitive.Table\n                {...tableNaming(named, label, !!description, ids)}\n                aria-busy={loading || undefined}\n                style={resize.tableStyle}\n                className={cn(\n                    'border-collapse border-spacing-0',\n                    staticWidth ? 'w-auto' : 'w-full',\n                    // fixed columns never grow for their content: long words wrap inside\n                    resize.fixed && 'table-fixed [&_td]:[overflow-wrap:anywhere] [&_th]:[overflow-wrap:anywhere]',\n                    pinClasses(pins.start, pins.end),\n                )}\n            >\n                <thead className=\"bg-[color:var(--ui-table-header-background,var(--ui-layer-accent))] type-body-emphasis leading-[18px]!\">\n                    <tr className=\"h-(--_row)\">\n                        {expandable ? renderExpandHeaderCell() : null}\n                        {hasSelection ? renderSelectAllCell() : null}\n                        {shownHeaders.map((header, index) => (\n                            <HeaderCell\n                                key={header.key}\n                                header={header}\n                                index={index}\n                                table={table}\n                                t={t}\n                                size={size}\n                                ids={ids}\n                                cellClassName={headCell}\n                                firstClassName={index === 0 ? firstColumn : ''}\n                                onSort={setAnnouncement}\n                            />\n                        ))}\n                        <DataTablePrimitive.Filler className={cn(headCell, 'text-ink-muted', 'p-0')} />\n                    </tr>\n                </thead>\n                <DataTablePrimitive.Body className=\"bg-[color:var(--ui-table-background,var(--ui-surface-1))] type-body-sm leading-[18px]!\">{renderBody()}</DataTablePrimitive.Body>\n            </DataTablePrimitive.Table>\n        </div>\n    );\n\n    const renderPagination = () => {\n        if (!paged) return null;\n        return (\n            <Pagination\n                size={PAGINATION_SIZE[size]}\n                page={table.page}\n                pageSize={table.pageSize}\n                pageSizes={pageSizes}\n                totalItems={table.filteredRows.length}\n                disabled={loading}\n                lang={lang}\n                onChange={table.setPagination}\n            />\n        );\n    };\n\n    return (\n        <DataTablePrimitive.Root table={table}>\n            <div {...rest} className={cn('block font-sans', className)} style={{ ...rest.style, ...(sizeLook.vars) }}>\n                {/* --ui-table-border / -radius / -overflow / -background: Carbon's table is an open block; a design can frame it or give it its cards' fill */}\n                <div className={cn('ui-table-frame relative pt-0.5 [border:var(--ui-table-border,0_solid)] rounded-[var(--ui-table-radius,0px)] [overflow:var(--ui-table-overflow,visible)] bg-[color:var(--ui-table-background,transparent)]', staticWidth && 'w-fit')}>\n                    <TableTitle heading={named ? heading : null} description={description} ids={ids} />\n                    {renderToolbar()}\n                    <span /* NOSONAR: role=status is a polite live region; <output> isn't announced by every screen reader */ className=\"sr-only\" role=\"status\">\n                        {announcement}\n                    </span>\n                    <DataTablePrimitive.EditHint className=\"sr-only\">{t.editHint}</DataTablePrimitive.EditHint>\n                    {renderTable()}\n                    {renderPagination()}\n                </div>\n            </div>\n        </DataTablePrimitive.Root>\n    );\n}\n\nexport { DataTableSkeleton, type DataTableSkeletonProps } from './data-table-skeleton.tsx';\n"
    },
    {
      "path": "src/react-tw/data-table-pins.ts",
      "type": "registry:ui",
      "target": "components/ui/react-tw/data-table-pins.ts",
      "content": "import { cn } from './lib/utils.ts';\n\n/**\n * Pinned columns, as `<ui-data-table>` (IBM Products Datagrid sticky columns; not in Carbon): the table\n * says how many leading cells stick (expand, select, a `pinned: 'start'` first column — from 672px\n * wide) and whether a `pinned: 'end'` last column does (before the resize filler or last). Each class\n * is written out whole so Tailwind finds it.\n */\n// the inner edge's side: no underscore in these names, Tailwind would read it as a space inside calc / var\nconst ROW_COLOUR = '[:where(&>tbody>tr)]:bg-surface-1 [--pin-start-edge:-1px] [--pin-end-edge:1px] rtl:[--pin-start-edge:1px] rtl:[--pin-end-edge:-1px]';\n\nconst START: Record<1 | 2 | 3, string> = {\n    1: cn(\n        'min-[672px]:[&>*>tr>:nth-child(1):not([colspan])]:sticky min-[672px]:[&>*>tr>:nth-child(1):not([colspan])]:z-1 min-[672px]:[&>thead>tr>:nth-child(1)]:z-3',\n        'min-[672px]:[&>tbody>tr>:nth-child(1):not([colspan])]:bg-inherit',\n        'min-[672px]:[&>*>tr>:nth-child(1):not([colspan])]:start-0',\n        'min-[672px]:[&>*>tr>:nth-child(1):not([colspan])]:[box-shadow:inset_var(--pin-start-edge)_0_0_var(--ui-hairline),var(--_head-edge,0_0_transparent)]',\n    ),\n    2: cn(\n        'min-[672px]:[&>*>tr>:nth-child(-n+2):not([colspan])]:sticky min-[672px]:[&>*>tr>:nth-child(-n+2):not([colspan])]:z-1 min-[672px]:[&>thead>tr>:nth-child(-n+2)]:z-3',\n        'min-[672px]:[&>tbody>tr>:nth-child(-n+2):not([colspan])]:bg-inherit',\n        'min-[672px]:[&>*>tr>:nth-child(1):not([colspan])]:start-0 min-[672px]:[&>*>tr>:nth-child(2):not([colspan])]:start-(--_pin-1)',\n        'min-[672px]:[&>*>tr>:nth-child(2):not([colspan])]:[box-shadow:inset_var(--pin-start-edge)_0_0_var(--ui-hairline),var(--_head-edge,0_0_transparent)]',\n    ),\n    3: cn(\n        'min-[672px]:[&>*>tr>:nth-child(-n+3):not([colspan])]:sticky min-[672px]:[&>*>tr>:nth-child(-n+3):not([colspan])]:z-1 min-[672px]:[&>thead>tr>:nth-child(-n+3)]:z-3',\n        'min-[672px]:[&>tbody>tr>:nth-child(-n+3):not([colspan])]:bg-inherit',\n        'min-[672px]:[&>*>tr>:nth-child(1):not([colspan])]:start-0 min-[672px]:[&>*>tr>:nth-child(2):not([colspan])]:start-(--_pin-1) min-[672px]:[&>*>tr>:nth-child(3):not([colspan])]:start-(--_pin-2)',\n        'min-[672px]:[&>*>tr>:nth-child(3):not([colspan])]:[box-shadow:inset_var(--pin-start-edge)_0_0_var(--ui-hairline),var(--_head-edge,0_0_transparent)]',\n    ),\n};\n\nconst END: Record<1 | 2, string> = {\n    1: cn(\n        '[&>*>tr>:last-child:not([colspan])]:sticky [&>*>tr>:last-child:not([colspan])]:end-0 [&>*>tr>:last-child:not([colspan])]:z-1 [&>thead>tr>:last-child]:z-3',\n        '[&>tbody>tr>:last-child:not([colspan])]:bg-inherit',\n        '[&>*>tr>:last-child:not([colspan])]:[box-shadow:inset_var(--pin-end-edge)_0_0_var(--ui-hairline),var(--_head-edge,0_0_transparent)]',\n    ),\n    2: cn(\n        '[&>*>tr>:nth-last-child(2):not([colspan])]:sticky [&>*>tr>:nth-last-child(2):not([colspan])]:end-0 [&>*>tr>:nth-last-child(2):not([colspan])]:z-1 [&>thead>tr>:nth-last-child(2)]:z-3',\n        '[&>tbody>tr>:nth-last-child(2):not([colspan])]:bg-inherit',\n        '[&>*>tr>:nth-last-child(2):not([colspan])]:[box-shadow:inset_var(--pin-end-edge)_0_0_var(--ui-hairline),var(--_head-edge,0_0_transparent)]',\n    ),\n};\n\n/** The table's classes for its pinned columns (how many stick: the headless table's `pins`). */\nexport function pinClasses(start: number, end: number) {\n    if (!start && !end) return '';\n    return cn(ROW_COLOUR, START[start as 1 | 2 | 3], END[end as 1 | 2]);\n}\n\n/** The pinned leading cells' offsets: the widths of the select / expand cells before them, as `--_pin-1` / `--_pin-2` on the scroll box. */\nexport function measurePins(box: HTMLElement | null, table: HTMLTableElement | null, start: number) {\n    const cells = table?.querySelector('thead tr')?.children;\n    if (!box || !cells || start < 2) return;\n    let at = 0;\n    for (let i = 1; i < start; i++) {\n        at += cells[i - 1].getBoundingClientRect().width;\n        box.style.setProperty(`--_pin-${i}`, `${at}px`);\n    }\n}\n"
    },
    {
      "path": "src/react-tw/data-table.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/react-tw/data-table.styles.ts",
      "content": "import { cn } from './lib/utils.ts';\n\n// The look of DataTable (and its skeleton): Carbon's sizes, and the cascade of <ui-data-table>'s row and cell rules,\n// resolved per row as Tailwind classes.\n\n/** Carbon's table sizes: rows of 24 / 32 / 40 / 48 (default) / 64px. */\nexport type DataTableSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';\n\nexport interface SizeLook {\n    vars: Record<string, string>;\n    /** Padding of the selection cells (xl has its own). */\n    select: string;\n    radio: string;\n}\n\n/** Row height and paddings per size (Carbon `--data-table--{size}`). */\nexport const SIZES: Record<DataTableSize, SizeLook> = {\n    xs: { vars: { '--_row': '24px', '--_label-pad': '2px', '--_cell-pad-start': '2px', '--_cell-pad-end': '2px', '--_align': 'middle', '--_expand-pad': '0 0 0 8px', '--_expand-button': '24px', '--_toolbar': '24px' }, select: 'py-0', radio: 'py-0' },\n    sm: { vars: { '--_row': '32px', '--_label-pad': '7px', '--_cell-pad-start': '7px', '--_cell-pad-end': '6px', '--_align': 'middle', '--_expand-pad': '0 0 0 8px', '--_expand-button': '32px', '--_toolbar': '32px' }, select: 'py-[3px]', radio: 'py-[3px]' },\n    md: { vars: { '--_row': '40px', '--_label-pad': '7px', '--_cell-pad-start': '7px', '--_cell-pad-end': '6px', '--_align': 'middle', '--_expand-pad': '4px 0 4px 8px', '--_expand-button': '32px', '--_toolbar': '48px' }, select: 'py-[3px]', radio: 'py-[3px]' },\n    lg: { vars: { '--_row': 'var(--ui-table-row-height, 48px)', '--_label-pad': '0px', '--_cell-pad-start': '0px', '--_cell-pad-end': '0px', '--_align': 'middle', '--_expand-pad': '8px 0 8px 8px', '--_expand-button': '32px', '--_toolbar': '48px' }, select: 'py-0', radio: 'py-0' },\n    xl: { vars: { '--_row': '64px', '--_label-pad': '16px', '--_cell-pad-start': '16px', '--_cell-pad-end': '16px', '--_align': 'top', '--_expand-pad': '10px 0 22px 8px', '--_expand-button': '32px', '--_toolbar': '48px' }, select: 'pt-[13px] pb-0', radio: 'pt-4 pb-0' },\n};\n\nexport const PAGINATION_SIZE = { xs: 'sm', sm: 'sm', md: 'md', lg: 'lg', xl: 'lg' } as const;\n\n// ---- the look of rows and cells (the cascade of <ui-data-table>'s rules, resolved per row) ----\n\n/**\n * Carbon's contextual tokens (they follow the enclosing <Layer>); `row` is the line between body rows: border-subtle as\n * Carbon web components (00 on the page, 01 / 02 in layers), as `<ui-data-table>`.\n */\ntype Ink = 'layer' | 'layer-background' | 'row' | 'subtle' | 'layer-accent' | 'selected' | 'active' | 'subtle-selected' | 'hover' | 'selected-hover' | 'transparent';\n\n/** Literal class names (Tailwind only sees whole names). */\nconst TOP: Record<Ink, string> = {\n    'layer': 'border-t-surface-1',\n    'layer-background': 'border-t-layer-background',\n    'row': 'border-t-hairline',\n    'subtle': 'border-t-hairline',\n    'layer-accent': 'border-t-layer-accent',\n    'selected': 'border-t-[color:var(--ui-table-row-selected,var(--ui-surface-2))]',\n    'active': 'border-t-ghost-active',\n    'subtle-selected': 'border-t-border-subtle-selected',\n    'hover': 'border-t-ghost-hover',\n    'selected-hover': 'border-t-layer-selected-hover',\n    transparent: 'border-t-transparent',\n};\nconst BOTTOM: Record<Ink, string> = {\n    'layer': 'border-b-surface-1',\n    'layer-background': 'border-b-layer-background',\n    'row': 'border-b-hairline',\n    'subtle': 'border-b-hairline',\n    'layer-accent': 'border-b-layer-accent',\n    'selected': 'border-b-[color:var(--ui-table-row-selected,var(--ui-surface-2))]',\n    'active': 'border-b-ghost-active',\n    'subtle-selected': 'border-b-border-subtle-selected',\n    'hover': 'border-b-ghost-hover',\n    'selected-hover': 'border-b-layer-selected-hover',\n    transparent: 'border-b-transparent',\n};\nconst HOVER_TOP: Record<Ink, string> = {\n    'layer': 'group-hover/row:border-t-surface-1',\n    'layer-background': 'group-hover/row:border-t-layer-background',\n    'row': 'group-hover/row:border-t-hairline',\n    'subtle': 'group-hover/row:border-t-hairline',\n    'layer-accent': 'group-hover/row:border-t-layer-accent',\n    'selected': 'group-hover/row:border-t-[color:var(--ui-table-row-selected,var(--ui-surface-2))]',\n    'active': 'group-hover/row:border-t-ghost-active',\n    'subtle-selected': 'group-hover/row:border-t-border-subtle-selected',\n    'hover': 'group-hover/row:border-t-ghost-hover',\n    'selected-hover': 'group-hover/row:border-t-layer-selected-hover',\n    transparent: 'group-hover/row:border-t-transparent',\n};\nconst HOVER_BOTTOM: Record<Ink, string> = {\n    'layer': 'group-hover/row:border-b-surface-1',\n    'layer-background': 'group-hover/row:border-b-layer-background',\n    'row': 'group-hover/row:border-b-hairline',\n    'subtle': 'group-hover/row:border-b-hairline',\n    'layer-accent': 'group-hover/row:border-b-layer-accent',\n    'selected': 'group-hover/row:border-b-[color:var(--ui-table-row-selected,var(--ui-surface-2))]',\n    'active': 'group-hover/row:border-b-ghost-active',\n    'subtle-selected': 'group-hover/row:border-b-border-subtle-selected',\n    'hover': 'group-hover/row:border-b-ghost-hover',\n    'selected-hover': 'group-hover/row:border-b-layer-selected-hover',\n    transparent: 'group-hover/row:border-b-transparent',\n};\n\nexport interface RowLook {\n    /** The table is zebra-striped. */\n    zebraTable: boolean;\n    /** This row is an odd (striped) one. */\n    zebra: boolean;\n    selected: boolean;\n    /** First `<tr>` of the body. */\n    first: boolean;\n    /** Last `<tr>` of the body (an open row's child row comes after it). */\n    last: boolean;\n    expanded: boolean;\n}\n\n/** A striped row (not selected): layer-background at rest, ghost-hover when hovered (as `<ui-data-table zebra>`). */\nconst striped = (look: RowLook) => look.zebraTable && look.zebra && !look.selected;\n\n/** A body row's background: stripe, selection, hover. */\nexport function rowClasses(look: RowLook) {\n    let rest = 'hover:bg-ghost-hover';\n    // --ui-table-row-selected: Carbon's layer-selected; a design can use its own highlight\n    if (look.selected) rest = 'bg-[color:var(--ui-table-row-selected,var(--ui-surface-2))] hover:bg-layer-selected-hover';\n    else if (striped(look)) rest = 'bg-layer-background hover:bg-ghost-hover';\n    return cn('group/row h-(--_row) transition-[background-color] duration-(--ui-duration-fast) ease-(--ui-easing-entrance) motion-reduce:transition-none', rest);\n}\n\n/** A body cell's top and bottom rules at rest: Carbon's row borders, striped rows, then the selected run (which wins). */\nfunction restRules(look: RowLook): { top: Ink; bottom: Ink } {\n    if (look.selected) {\n        if (look.last) return { top: 'selected', bottom: 'selected' };\n        return { top: look.first ? 'subtle-selected' : 'selected', bottom: 'active' };\n    }\n    if (!look.zebraTable) return { top: 'layer', bottom: 'row' };\n    return look.zebra ? { top: 'layer-background', bottom: 'layer-background' } : { top: 'layer', bottom: 'layer' };\n}\n\n/** An open row's bottom rule (at rest, hovered): the line above its child row; the chevron cell draws none. */\nfunction openRowBottom(look: RowLook, expandCell: boolean, rest: Ink, hover: Ink): { bottom: Ink; hoverBottom: Ink } {\n    if (!look.expanded) return { bottom: rest, hoverBottom: hover };\n    // zebra: the striped table's open-row hover rule outranks the chevron cell's own (as in <ui-data-table>)\n    if (expandCell) return { bottom: 'transparent', hoverBottom: look.zebraTable ? 'subtle' : 'hover' };\n    return { bottom: look.selected && look.last ? rest : 'subtle', hoverBottom: 'subtle' };\n}\n\n/** A body cell's rules and text colour, at rest and while its row is hovered. */\nexport function cellClasses(look: RowLook, expandCell = false) {\n    const rest = restRules(look);\n    const hoverTop: Ink = look.selected ? 'selected-hover' : 'hover';\n    const { bottom, hoverBottom } = openRowBottom(look, expandCell, rest.bottom, hoverTop);\n    const top = rest.top;\n    return cn(\n        'border-0 border-y border-solid transition-[background-color] duration-(--ui-duration-fast) ease-(--ui-easing-entrance) motion-reduce:transition-none',\n        TOP[top],\n        BOTTOM[bottom],\n        HOVER_TOP[hoverTop],\n        HOVER_BOTTOM[hoverBottom],\n        // Carbon: secondary text until hovered or chosen; --ui-table-cell-ink lets a design use primary text\n        look.selected ? 'text-ink' : 'text-[color:var(--ui-table-cell-ink,var(--ui-ink-muted))] group-hover/row:text-ink',\n        // the chosen row's mark on its start edge, in its first cell: none in Carbon (Kanok: a border-interactive mark)\n        look.selected && 'first:[background-image:var(--ui-table-row-thread,none)]',\n        // the open row's child row hovered: this row lights up with it\n        look.expanded && '[@media(hover:hover)]:[tr:has(+tr:hover)>&]:text-ink',\n        look.selected && 'forced-colors:border-y-[Highlight]',\n    );\n}\n\nexport const cellBase = 'box-border px-4 text-start align-(--_align)';\nexport const ALIGN = { start: '', center: 'text-center', end: 'text-end' } as const;\n\nexport const expandButtonClasses = cn(\n    'm-0 box-border inline-flex h-(--_expand-button) w-8 cursor-pointer items-center justify-center rounded-[var(--ui-icon-control-radius,0px)] border-0 bg-transparent px-2 py-0 align-middle text-[ButtonText]',\n    'outline-none focus-visible:shadow-[inset_0_0_0_var(--ui-focus-width,2px)_var(--ui-focus)]',\n    '[&_svg]:size-4 [&_svg]:fill-icon-primary [&_svg]:[transform:rotate(90deg)] [&_svg]:transition-transform [&_svg]:duration-150 [&_svg]:ease-carbon motion-reduce:[&_svg]:transition-none',\n    'aria-expanded:[&_svg]:[transform:rotate(270deg)]',\n);\n\nexport const barButtonClasses = cn(\n    // --ui-batch-button-*: a design can make them text buttons on its tinted bar\n    'm-0 h-(--_toolbar) cursor-pointer whitespace-nowrap border-0 bg-[var(--ui-batch-button,var(--ui-primary))] px-4 text-[var(--ui-batch-button-ink,var(--ui-on-primary))] type-button',\n    'hover:bg-[var(--ui-batch-button-hover,var(--ui-blue-hover))] active:bg-[var(--ui-batch-button-active,var(--ui-blue-80))] outline-none focus-visible:rounded-[var(--ui-focus-radius,0px)] focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-[var(--ui-batch-focus,var(--ui-surface-1))]',\n    // Carbon .cds--btn: the fill and the ring change in fast-01 with the entrance easing\n    'transition-[background-color,outline] duration-(--ui-duration-fast) ease-(--ui-easing-entrance)',\n);\n\n/** Carbon draws the table checkbox 3px in and 4px down a 24px label. */\nexport const checkboxInCell = 'block h-6 ms-[3px] [&_label]:py-[3px]';\n\n/** A skeleton cell's rules: the table's, without hover. */\nexport function staticCell(look: RowLook) {\n    let bottom = look.zebraTable ? 'border-b-surface-1' : 'border-b-hairline';\n    if (look.zebraTable && look.zebra) bottom = 'border-b-layer-background';\n    return cn('border-0 border-y border-solid text-ink-muted', look.zebraTable && look.zebra ? 'border-t-layer-background' : 'border-t-surface-1', bottom);\n}\n"
    }
  ]
}
