@gridkitjs/react 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,8 +29,12 @@ const columns: readonly ColumnDefinition<Row>[] = [
29
29
  <DataGridComponent
30
30
  dataSource={rows}
31
31
  columns={columns}
32
+ getRowId={(row) => String(row.Id)}
33
+ label="Application costs"
32
34
  resizableColumns
33
35
  resizeMode="fit"
36
+ selectable={{ rows: "multiple", cells: "single" }}
37
+ onRowSelectionChange={({ selected }) => persist(selected)}
34
38
  />;
35
39
  ```
36
40
 
@@ -39,6 +43,16 @@ drives its default alignment. With `resizableColumns`, a column edge can be
39
43
  dragged to resize or double-clicked to fit its content. `resizeMode="fit"`
40
44
  keeps columns filling the grid; `"fixed"` lets each keep its own width.
41
45
 
46
+ `selectable` says which parts of the grid the user may select and how many of
47
+ each — `false`, `"single"` or `"multiple"` per member, off by default. Click
48
+ replaces, Ctrl-click toggles, Shift-click takes a range, and thirteen callbacks
49
+ report it with the resolved row, column or cell value rather than a bare id.
50
+ Give `getRowId` alongside it for data that sorts, filters or pages.
51
+
52
+ The grid is an ARIA grid: one tab stop, with the arrow keys moving cell to cell
53
+ within it, `Ctrl+Arrow` reordering a column and `Alt+Arrow` resizing one. Name
54
+ it with `label`, or a screen reader announces only "grid".
55
+
42
56
  Requires React 19.
43
57
 
44
58
  Full documentation: [github.com/blagojablazhevski/gridkit](https://github.com/blagojablazhevski/gridkit#readme)
package/dist/index.d.ts CHANGED
@@ -1,7 +1,34 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ColumnDefinition as ColumnDefinition$1, ColumnSizingState, ColumnOrderState, ColumnSizeDefaults, ColumnResizeEvent, ColumnOrderEvent, ResolvedColumn as ResolvedColumn$1 } from '@gridkitjs/core';
4
- export { CellTemplateContext, ColumnResizeEvent, ColumnSizeDefaults, ColumnSizingState } from '@gridkitjs/core';
3
+ import { RowSelectEvent, RowsSelectEvent, RowSelectionChangeEvent, CellSelectEvent as CellSelectEvent$1, CellSelectionChangeEvent as CellSelectionChangeEvent$1, ColumnDefinition as ColumnDefinition$1, ColumnSelectEvent as ColumnSelectEvent$1, ColumnSelectionChangeEvent as ColumnSelectionChangeEvent$1, ColumnsSelectEvent as ColumnsSelectEvent$1, SelectableConfig, SelectionState, CellSelectionState, ColumnSizingState, ColumnOrderState, ColumnSizeDefaults, ColumnResizeEvent, ColumnOrderEvent, ColumnSortState, ColumnSortEvent, FilterState, ResolvedColumn as ResolvedColumn$1, SelectedCell as SelectedCell$1, SelectedColumn as SelectedColumn$1 } from '@gridkitjs/core';
4
+ export { CellSelectionMode, CellSelectionState, CellTemplateContext, ColumnResizeEvent, ColumnSizeDefaults, ColumnSizingState, ResolvedRow, RowSelectEvent, RowSelectionChangeEvent, RowsSelectEvent, SelectableConfig, SelectedCellRef, SelectionMode, SelectionState } from '@gridkitjs/core';
5
+
6
+ /**
7
+ * Reported as the user selects. Every one of these is fanned out from a single
8
+ * diff of the transition it describes, so no two can disagree about what one
9
+ * interaction did.
10
+ */
11
+ interface SelectionCallbacks<Row> {
12
+ /** Called once per row newly selected. The last call names the last row. */
13
+ onRowSelect?: ((event: RowSelectEvent<Row>) => void) | undefined;
14
+ /** Called once with every row one interaction selected. */
15
+ onRowsSelect?: ((event: RowsSelectEvent<Row>) => void) | undefined;
16
+ onRowDeselect?: ((event: RowSelectEvent<Row>) => void) | undefined;
17
+ onRowsDeselect?: ((event: RowsSelectEvent<Row>) => void) | undefined;
18
+ /**
19
+ * Called once per change with what it added, what it removed and everything
20
+ * selected after it — the one to persist from.
21
+ */
22
+ onRowSelectionChange?: ((event: RowSelectionChangeEvent<Row>) => void) | undefined;
23
+ onColumnSelect?: ((event: ColumnSelectEvent<Row>) => void) | undefined;
24
+ onColumnsSelect?: ((event: ColumnsSelectEvent<Row>) => void) | undefined;
25
+ onColumnDeselect?: ((event: ColumnSelectEvent<Row>) => void) | undefined;
26
+ onColumnsDeselect?: ((event: ColumnsSelectEvent<Row>) => void) | undefined;
27
+ onColumnSelectionChange?: ((event: ColumnSelectionChangeEvent<Row>) => void) | undefined;
28
+ onCellSelect?: ((event: CellSelectEvent<Row>) => void) | undefined;
29
+ onCellDeselect?: ((event: CellSelectEvent<Row>) => void) | undefined;
30
+ onCellSelectionChange?: ((event: CellSelectionChangeEvent<Row>) => void) | undefined;
31
+ }
5
32
 
6
33
  /**
7
34
  * A column whose header and cells may render arbitrary React content.
@@ -11,6 +38,21 @@ export { CellTemplateContext, ColumnResizeEvent, ColumnSizeDefaults, ColumnSizin
11
38
  type ColumnDefinition<Row> = ColumnDefinition$1<Row, ReactNode>;
12
39
  /** A column paired with the width it renders at. */
13
40
  type ResolvedColumn<Row> = ResolvedColumn$1<Row, ReactNode>;
41
+ /**
42
+ * The selection payloads, bound to React's node type for the same reason
43
+ * `ColumnDefinition` is: they carry a resolved column, whose label is whatever
44
+ * a `headerTemplate` returned.
45
+ *
46
+ * The row payloads name no node type at all and so are re-exported from
47
+ * `@gridkitjs/core` as they are.
48
+ */
49
+ type SelectedColumn<Row> = SelectedColumn$1<Row, ReactNode>;
50
+ type SelectedCell<Row> = SelectedCell$1<Row, ReactNode>;
51
+ type ColumnSelectEvent<Row> = ColumnSelectEvent$1<Row, ReactNode>;
52
+ type ColumnsSelectEvent<Row> = ColumnsSelectEvent$1<Row, ReactNode>;
53
+ type ColumnSelectionChangeEvent<Row> = ColumnSelectionChangeEvent$1<Row, ReactNode>;
54
+ type CellSelectEvent<Row> = CellSelectEvent$1<Row, ReactNode>;
55
+ type CellSelectionChangeEvent<Row> = CellSelectionChangeEvent$1<Row, ReactNode>;
14
56
  type Borders = "horizontal" | "vertical" | "all" | "none";
15
57
  /**
16
58
  * How a column's width relates to the grid's.
@@ -26,11 +68,39 @@ interface HoverableConfig {
26
68
  columns?: boolean;
27
69
  cells?: boolean;
28
70
  }
29
- interface DataGridProps<Row> {
71
+ interface DataGridProps<Row> extends SelectionCallbacks<Row> {
30
72
  columns?: readonly ColumnDefinition<Row>[] | undefined;
31
73
  dataSource?: readonly Row[] | undefined;
74
+ /**
75
+ * A row's stable identity, for state keyed by it. Defaults to the row's
76
+ * position, which is enough for a static grid but ties that state to where a
77
+ * row sits rather than to the row — so anything sorting, filtering or paging
78
+ * its data should give one.
79
+ *
80
+ * Called for every row on every change to `dataSource`, so it should be
81
+ * cheap and stable; an inline arrow is fine, one that re-reads the data is
82
+ * not.
83
+ */
84
+ getRowId?: ((row: Row, index: number) => string) | undefined;
32
85
  borders?: Borders | undefined;
33
86
  hoverable?: HoverableConfig | undefined;
87
+ /**
88
+ * Which parts of the grid the user may select, and how many of each —
89
+ * `{ rows: "multiple", cells: "single" }`. A cell addresses one value, so it
90
+ * has no `"multiple"`.
91
+ *
92
+ * Off by default, unlike `hoverable`: selection claims the click, which a
93
+ * grid that only displays data should not do. Give `getRowId` alongside it
94
+ * for data that sorts, filters or pages, or a selection follows the position
95
+ * rather than the row.
96
+ */
97
+ selectable?: SelectableConfig | undefined;
98
+ /** Row ids selected to start with, keyed as `getRowId` resolves them. Uncontrolled. */
99
+ defaultRowSelection?: SelectionState | undefined;
100
+ /** Column ids selected to start with. Uncontrolled. */
101
+ defaultColumnSelection?: SelectionState | undefined;
102
+ /** The cell selected to start with. Uncontrolled. */
103
+ defaultCellSelection?: CellSelectionState | undefined;
34
104
  /** Whether columns can be dragged wider, unless a column says otherwise. */
35
105
  resizableColumns?: boolean | undefined;
36
106
  /**
@@ -68,7 +138,32 @@ interface DataGridProps<Row> {
68
138
  * the order as it was does not call it.
69
139
  */
70
140
  onColumnOrderChange?: ((event: ColumnOrderEvent) => void) | undefined;
141
+ /**
142
+ * Whether columns can be sorted by clicking their header toggle, unless a
143
+ * column says otherwise. Shift-click stacks a column into the sort instead
144
+ * of replacing it.
145
+ */
146
+ sortableColumns?: boolean | undefined;
147
+ /** The sort to start with, in priority order. Uncontrolled. */
148
+ defaultColumnSort?: ColumnSortState | undefined;
149
+ /**
150
+ * Called once when the user changes the sort — a toggle, a stack, or a
151
+ * clear back to "none".
152
+ */
153
+ onColumnSortChange?: ((event: ColumnSortEvent) => void) | undefined;
154
+ /** The filter to start with — every applied entry, ANDed together. Uncontrolled. */
155
+ defaultFilter?: FilterState<Row> | undefined;
156
+ /**
157
+ * The grid's accessible name, announced when it takes focus. A grid without
158
+ * one is read only as "grid", which says nothing about which grid.
159
+ */
160
+ label?: string | undefined;
161
+ /**
162
+ * The id of an element naming the grid, for a heading already on the page.
163
+ * Takes precedence over `label`, as `aria-labelledby` does.
164
+ */
165
+ labelledBy?: string | undefined;
71
166
  }
72
- declare function DataGridComponent<Row>({ dataSource, columns, borders, hoverable, resizableColumns, reorderableColumns, resizeMode, defaultColumnSizing, defaultColumnOrder, columnSizeDefaults, onColumnResize, onColumnOrderChange, }: DataGridProps<Row>): react.JSX.Element;
167
+ declare function DataGridComponent<Row>({ dataSource, columns, getRowId, borders, hoverable, selectable, defaultRowSelection, defaultColumnSelection, defaultCellSelection, resizableColumns, reorderableColumns, resizeMode, defaultColumnSizing, defaultColumnOrder, columnSizeDefaults, onColumnResize, onColumnOrderChange, sortableColumns, defaultColumnSort, onColumnSortChange, defaultFilter, label, labelledBy, ...callbacks }: DataGridProps<Row>): react.JSX.Element;
73
168
 
74
- export { type ColumnDefinition, DataGridComponent, type DataGridProps, type ResizeMode, type ResolvedColumn };
169
+ export { type CellSelectEvent, type CellSelectionChangeEvent, type ColumnDefinition, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnsSelectEvent, DataGridComponent, type DataGridProps, type ResizeMode, type ResolvedColumn, type SelectedCell, type SelectedColumn };