Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/table-row-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@astryxdesign/core': patch
'@astryxdesign/cli': patch
---

[feat] Table plugins can now read where a row sits. Table passes each body row and cell transform an immutable `TableRowContext` (the row's key, its zero-based `logicalIndex` in the complete data, the row and header counts, and the row model). It passes the scroll-wrapper transform a `TableRenderContext` with a stable `viewport` reference. A plugin declares `rowModel: 'flat'` when its body transforms keep one row per data item. `useTableSelection` and `useTableStickyColumns` declare it. `useTableRowIndex()` without options now numbers rows from the context (passing `data` still numbers from that array), and rows that move re-render only for plugins that read the index. Read context values during the transform; a later read from a callback warns in development. The CLI's numbered-rows block no longer passes `data`.

@cixzhang
15 changes: 5 additions & 10 deletions apps/storybook/stories/TableRowIndex.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Story = StoryObj;
*/
export const Default: Story = {
render: () => {
const rowIndex = useTableRowIndex<Track>({data: tracks});
const rowIndex = useTableRowIndex<Track>();
return (
<Table
data={tracks}
Expand All @@ -79,7 +79,6 @@ export const Default: Story = {
export const CustomLabelAndStart: Story = {
render: () => {
const rowIndex = useTableRowIndex<Track>({
data: tracks,
label: 'No.',
startFrom: 0,
});
Expand All @@ -96,9 +95,9 @@ export const CustomLabelAndStart: Story = {
};

/**
* The index reflects the current view: with sorting active, pass the **sorted**
* data to `useTableRowIndex` so numbering renumbers as the order changes. Sort
* by Plays to see rows renumber 1..n in the new order.
* The index reflects the current view: Table gives each row its position, so
* numbering renumbers as the sort order changes. Sort by Plays to see rows
* renumber 1..n in the new order.
*/
export const RenumbersWithSort: Story = {
render: () => {
Expand All @@ -111,11 +110,7 @@ export const RenumbersWithSort: Story = {
onSortChange: setSort,
});
const sortPlugin = useTableSortable<Track>(sortConfig);
// Pass the sorted data + a stable key so the index tracks the sorted order.
const rowIndex = useTableRowIndex<Track>({
data: sortedData,
getRowKey: item => item.id,
});
const rowIndex = useTableRowIndex<Track>();
const plugins = useMemo(
() => ({rowIndex, sort: sortPlugin}),
[rowIndex, sortPlugin],
Expand Down
3 changes: 3 additions & 0 deletions docs/specs/components/Table/Table.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ verified_by:
packages/core/src/Table/__tests__/Table.a11y.test.tsx,
packages/core/src/Table/__tests__/Table.a11y.chromium.spec.ts,
packages/core/src/Table/Table.perf.test.tsx,
packages/core/src/Table/TableRowContext.test.tsx,
packages/core/src/Table/plugins/rowIndex/useTableRowIndex.test.tsx,
packages/core/src/Table/plugins/selection/useTableSelection.test.tsx,
packages/core/src/Table/plugins/sortable/useTableSortable.test.tsx,
packages/core/src/Table/plugins/sortable/__tests__/useTableSortable.a11y.test.tsx,
Expand Down Expand Up @@ -453,6 +455,7 @@ for this aggregate ownership.
| FR14 | `__tests__/TableRowGlide.a11y.browser.spec.ts` screenshot checks of the divider mid-glide, in pinned columns, and under an open detail panel; `plugins/rowExpansion/useTableRowExpansion.glide.test.tsx` for the divider an open panel carries | a theme with a custom divider colour; an app override of a row's border; both mid-glide and on a pinned cell; an open detail panel's divider under the same theme and override | a divider whose width, style or colour differs from the row's border, or that drops a theme or app override, fails | `audit:Table/theming` |
| FR15 | `plugins/rowExpansion/useTableRowExpansion.glide.test.tsx` and `__tests__/TableRowGlide.a11y.browser.spec.ts`: row expansion with and without `animatedLayout`, plus source inspection of the panel's entrance and its hide on close | open and close with the handle; without it; reduced motion under a coarse and a fine pointer; a glyph turn beside the glide; a `dividers="grid"` and a `dividers="columns"` table with the option | rows that jump with the handle in a table without column lines, a closing panel that animates or leaves its space empty before the rows arrive, a panel and rows on different motion, a glyph on its own timing beside the glide, travel under reduced motion, or any motion without the handle a table with column lines that glides or animates its panel, or one whose glyph does not keep its own turn, fails | `audit:Table/plugins` |
| Accessibility contract | `__tests__/Table.a11y.test.tsx` and `__tests__/Table.a11y.chromium.spec.ts` bind Table to the base Table contract (`internal/a11y-spec`), composing each module's contract only for the states rendered with that module: the sort module contract (`plugins/sortable/__tests__/useTableSortable.a11y.ts`) for the sorted state; `__tests__/TableScroll.a11y.chromium.spec.ts` keeps the Scroll region evidence | Labelled data-driven, sorted descending, composed RTL with row headers, and empty data | Losing the table role or declared name, row, header, or cell roles, or a part leaving its row or the table, fails the base binding; a missing or stale `aria-sort` fails the composed sort module contract. | `audit:Table/accessibility` |
| FR17 transform context | `TableRowContext.test.tsx` and `plugins/rowIndex/useTableRowIndex.test.tsx`: row, cell and scroll-wrapper contexts, row-model admission, read-tracked re-rendering, and row numbering from the context | Keys with and without `idKey`; flat, undeclared and declared row models; a re-sort with and without an index read; an appended row with a count read; numbering after a re-sort without `data` | A missing or mutable context, a renumbered or stale index, a moved row re-rendered for a plugin that never reads its index, or numbering from a data lookup fails | `audit:Table/plugins` |
| FR16-FR22 | Pending parent protocol, render-count, API-compile, lifecycle and browser tests plus the module verification maps | Canonical type/key collisions; first-party flat declarations and diagnostic full-render fallbacks; invalid/unknown modes; both owner orders; optional context arities; full/empty/loading/windowed data; pinned paint; native focus and no-op frames | A second key/offset/renderer, order-selected owner, full cell work before slicing, stale source/ref, empty-loading contradiction, or removed focus destination fails | `audit:Table/plugins` |
| Module backlink | `scripts/check-knowledge.mjs` | Active parent and colocated module record | A missing, duplicate, mis-parented, wrong-kind, misnamed, or undiscovered module record fails knowledge validation. | `audit:Table/modules` |
| Theming anatomy map | `scripts/check-knowledge.mjs`, `themingTargets.test.ts`, and CLI parent-aware target discovery tests | Canonical anatomy and eight current targets | Missing, extra, duplicated, prefixed, stale, or independently owned member mappings fail repository validation or discovery coverage. | `audit:Table/theming` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const doc = {
name: 'useTableRowIndex — Numbered Rows',
displayName: 'useTableRowIndex — Numbered Rows',
description:
'A table with a prepended row-number column via useTableRowIndex. Numbering is monospaced, right-aligned, and follows the rendered data order.',
'A table with a prepended row-number column via useTableRowIndex. Numbering is monospaced, right-aligned, and follows the rows the table renders.',
isReady: true,
aspectRatio: 16 / 9,
componentsUsed: ['Table'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const columns: TableColumn<Track>[] = [
];

export default function TableRowIndexTable() {
// Pass the rendered data array — numbering follows its order.
const rowIndex = useTableRowIndex<Track>({data: tracks});
// Table gives each row its position, so numbering follows the rendered rows.
const rowIndex = useTableRowIndex<Track>();

return (
<Table
Expand Down
27 changes: 22 additions & 5 deletions packages/core/api-report.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading