List
Render rows of data in a bordered CSS grid with configurable columns and optional column groups.
List is a client component ("use client") that renders a data grid built from Box and Text: an optional group header row, a column header row, and one row per data item. Use it for compact tables of records. Each cell renders a component you supply per column.
Import#
import { List } from "@reactberry/system/blocks";
Usage#
import { List } from "@reactberry/system/blocks";
import { Text } from "@reactberry/system/elements";
const users = [
{ id: "u1", name: "Ada Lovelace", city: "London", role: "Admin" },
{ id: "u2", name: "Grace Hopper", city: "New York", role: "Editor" },
];
const grid = [
{ label: "ID", width: "4rem", key: "id", align: "center", component: (p: any) => <Text>{p.id}</Text> },
{ label: "Name", width: "1fr", key: "name", component: (p: any) => <Text fontWeight="600">{p.name}</Text> },
{ label: "City", width: "10rem", key: "city", group: "Details", component: (p: any) => <Text>{p.value}</Text> },
{ label: "Role", width: "8rem", key: "role", group: "Details", component: (p: any) => <Text>{p.value}</Text> },
];
export default function UserList() {
return <List data={users} grid={grid} rowHeight="2.5rem" onRowClick={(item) => console.log(item.name)} />;
}
Examples#
Column groups#
Give columns the same group value to show them under a shared header row.
Selection#
Pass selected and onSelect to toggle rows. Row data is filtered to the keys in grid, so the grid needs an id column for selection to work.
API#
List#
| Prop | Type | Default | Description |
|---|---|---|---|
data | DataItem[] | [] | Row objects. |
grid | (GridColumn | GroupedColumn)[] | [… | Column definitions. Columns with the same |
gap | string | xxxsmall | Gap and bottom padding of the group header row. |
selected | string[] | [] | Ids of selected rows. |
onSelect | ((id: string) => void) | — | Called with the row's |
onRowClick | ((item: DataItem) => void) | — | Called when a row is clicked. Receives the row item, filtered to the
keys used in |
rowHeight | string | 2rem | Fixed height and max height of each row. Default is "2rem". |
All other props are spread onto the group header row only, so they have no effect when no columns are grouped. The default grid is a three-column id / name / empty setup.
GridColumn#
| Prop | Type | Default | Description |
|---|---|---|---|
label* | string | ReactNode | — | Header content. |
width* | string | — | Grid track size, such as |
key* | string | string[] | — | Data key(s) to keep and pass to |
component* | ComponentType<any> | — | Cell renderer. Receives the row's kept fields as props plus |
align | any | "start" | Cell and header alignment. |
minWidth | string | — | Applied to each cell. |
maxWidth | string | — | Applied to each cell. |
autoWidth | boolean | — | Measures content to size the column. |
group | string | — | Columns sharing a value are grouped under one header. |
columnProps | any | — | Spread onto the column header. |
cellProps | any | — | Spread onto each cell. |
groupProps | any | — | Spread onto the group header when this is the first column of its group. |
Accessibility#
- Rows are clickable
divelements withcursor="pointer"when a handler is set. They are not focusable and have no keyboard handling or ARIA grid roles. - Selected rows are marked only by a check mark emoji at the start of every cell; there is no other selected styling or ARIA state.
Notes#
- Row data is filtered to the keys listed in
gridbefore rendering. Selection,onSelect,onRowClickand cell components only see those fields; without anidcolumn,idisundefined. autoWidthcolumns are measured after mount and on horizontal window resize (debounced 250ms), using up to 20 rows plus the header and adding 24px. Measurement queries cells by a global class name, so multipleListinstances withautoWidthon one page can affect each other.- Group headers read
groupPropsfrom the first column in the group. ThegroupPropsfield on aGroupedColumnobject is not used. - The module also exports
createColumnGroup(groupHeader, columns, groupProps?), which returns aGroupedColumn, and the typesDataItem,ListProps,GridColumnandGroupedColumn. These are not re-exported from@reactberry/system/blocks, and the package does not expose deep import paths, so they are not currently importable by consumers. Use thegroupfield on columns instead.