Repository navigation
Description
Problem
Table's public API takes columns as headers: string[] and rows as data: ComponentChild[][]. Three issues fall out of this shape:
- Lost types at the call site. Consumers who have a typed record array (
Employee[],Order[], etc.) must project toComponentChild[][]themselves. The positional dependency betweenheaders[i]anddata[i][j]is invisible to the type system — typo a column order or miscount cells and the table renders silently miscolumned data. - Repeated formatting work. Every consumer re-implements the same display logic — number alignment, currency formatting, date rendering, monospace IDs — at the call site. There's no place for the library to provide sensible defaults.
rowHeader: booleanis leading-only. It marks the first column as<th scope=\"row\">, but real tables often want a non-leading column (an ID, a name) as the row header.
Impact
- Every typed-data consumer carries the same projection-and-formatting boilerplate.
- The positional API silently breaks when columns are reordered without matching changes to the data array.
- Foundation work for
DataTable(#milestone:DataTable) — the editable variant cannot cleanly compose on top of the current shape because it needs schema metadata (column type, validators, accessor key) per column.
Suggested Approach
Introduce a typed column descriptor and replace the positional API:
interface ITableColumn<T> {
key: keyof T & string;
label: string;
type?: 'text' | 'number' | 'date' | 'currency';
render?: (row: T) => ComponentChild;
rowHeader?: boolean;
align?: 'start' | 'end' | 'center';
}
interface ITableProps<T> extends IBaseProps {
caption: string;
columns: ITableColumn<T>[];
rows: T[];
rowKey?: (row: T) => string;
// striped, dense, captionHidden unchanged
}key: indexes the row to extract the cell valuetype: drives default formatting and alignment (numbers right-align, currency usesIntl.NumberFormat, dates useIntl.DateTimeFormat)render: escape hatch for custom display (overridestype)rowHeader: any column can opt into<th scope=\"row\">rowKey: takes the typed row, not rendered cells
Default formatting per type:
text(default): plain text, left-alignednumber:Intl.NumberFormat, right-alignedcurrency: requires acurrency: string(ISO 4217); right-aligneddate:Intl.DateTimeFormat
This is a prerequisite for the DataTable milestone — the editable variant defines IDataTableColumn<T> extends ITableColumn<T> with editable, validate, and editor-specific props, sharing all structural pieces.
Migration
Breaking change to a public component. In-repo migration covers dev/sections/TableSection.tsx, tests/table.test.tsx, and tests/a11y/table.a11y.test.tsx — handled in the same PR.
For external consumers (apps depending on auldrant-ui):
| Before | After |
|---|---|
headers={['Name', 'Age']} |
columns={[{ key: 'name', label: 'Name' }, { key: 'age', label: 'Age', type: 'number' }]} |
data={[[u.name, u.age], ...]} |
rows={users} |
rowHeader (first column only) |
columns[0].rowHeader: true (any column) |
rowKey={(row, i) => ...} reading rendered cells |
rowKey={(row) => row.id} typed against T |
Migration note for the release: the new API requires a typed row array. Consumers projecting from disparate sources can use a mapping pass (rows.map(r => ({ name: r.name, age: r.age, ... }))) before passing to <Table>.
Activity
chore: add internal form primitives (DataInput, FieldError) (#159)
[-]Tabular form editors require consumers to orchestrate cells, focus, and label wiring[/-][+]Refactor Table to schema-driven columns for typed projection and built-in formatting[/+]