@atom-learning/components 2.27.0 → 2.28.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/CHANGELOG.md +22 -6
- package/dist/components/data-table/DataTable.d.ts +5 -0
- package/dist/components/data-table/DataTable.js +1 -1
- package/dist/components/data-table/DataTable.types.d.ts +18 -2
- package/dist/components/data-table/DataTableContext.d.ts +5 -10
- package/dist/components/data-table/DataTableContext.js +1 -1
- package/dist/components/data-table/DataTableRow.d.ts +1 -2
- package/dist/components/data-table/DataTableRow.js +1 -1
- package/dist/components/data-table/DataTableTable.d.ts +1 -2
- package/dist/components/data-table/drag-and-drop/DragAndDropContainer.d.ts +21 -0
- package/dist/components/data-table/drag-and-drop/DragAndDropContainer.js +1 -0
- package/dist/components/data-table/drag-and-drop/DragAndDropTable.d.ts +8 -0
- package/dist/components/data-table/drag-and-drop/DragAndDropTable.js +1 -0
- package/dist/components/data-table/drag-and-drop/DragAndDropTableBody.d.ts +5 -0
- package/dist/components/data-table/drag-and-drop/DragAndDropTableBody.js +1 -0
- package/dist/components/data-table/drag-and-drop/DraggableRow.d.ts +7 -0
- package/dist/components/data-table/drag-and-drop/DraggableRow.js +1 -0
- package/dist/components/data-table/drag-and-drop/Handle.d.ts +564 -0
- package/dist/components/data-table/drag-and-drop/Handle.js +1 -0
- package/dist/components/data-table/drag-and-drop/index.d.ts +4 -0
- package/dist/components/data-table/usePagination.d.ts +8 -0
- package/dist/components/data-table/usePagination.js +1 -0
- package/dist/components/data-table/useSorting.d.ts +9 -0
- package/dist/components/data-table/useSorting.js +1 -0
- package/dist/components/table/Table.js +1 -1
- package/dist/components/table/TableBody.js +1 -1
- package/dist/components/table/TableRow.d.ts +272 -1
- package/dist/components/table/TableRow.js +1 -1
- package/dist/docgen.json +1 -1
- package/dist/docs/DataTable.mdx +37 -1
- package/dist/index.cjs.js +1 -1
- package/package.json +5 -1
package/dist/docs/DataTable.mdx
CHANGED
|
@@ -15,7 +15,7 @@ The root `DataTable` component manages the table's state and exposes it via the
|
|
|
15
15
|
|
|
16
16
|
Other `DataTable` components call `useDataTable` and provide useful default implementations for common patterns. For example, `DataTable.Head` will render a header for every column defined in the parent `DataTable`. `DataTable.Body` will render a row for every data item. `DataTable.Table` combines both `DataTable.Head` and `DataTable.Body`.
|
|
17
17
|
|
|
18
|
-
### Using defaults vs
|
|
18
|
+
### Using defaults vs rolling your own
|
|
19
19
|
|
|
20
20
|
Here's a simple config for some table data and columns.
|
|
21
21
|
|
|
@@ -241,3 +241,39 @@ If `DataTable`'s `isSortable` state is `true`, then `DataTable.Header` will be c
|
|
|
241
241
|
### Pagination
|
|
242
242
|
|
|
243
243
|
`DataTable.Pagination` can be passed as a child to `DataTable` to render the pagination UI and configure the parent `DataTable` to paginate its data. Note: there is currently a bug where `DataTable` will render all rows on the initial render, even when paginated. There is no visible effect, but it can cause performance issues on large tables. The workaround for this is to pass an `initialState` prop to `DataTable`. E.g. `initialState={pagination: {pageSize: 5, pageIndex: 0}}`. This will force pagination to apply properly on the initial render. Make sure the `pagination` prop matches the config you use in `DataTable.Pagination`, as the latter will take precedence after the initial render.
|
|
244
|
+
|
|
245
|
+
### Drag and drop
|
|
246
|
+
|
|
247
|
+
The `DataTable.DragAndDropTable` can be rendered in place of `DataTable.Table` to allow users to reorder table rows via drag and drop. It takes an optional `onDragAndDrop` prop which is a function that fires when rows have been re-ordered via drag-and-drop. Use this to sync those changes with external data sources.
|
|
248
|
+
|
|
249
|
+
Note that column sorting conflicts with drag and drop behaviour. In any context where you allow drag and drop reordering, you probably want to disable column sorting (see User Sorting above). Similarly, you should probably disable pagination because users won't be able to drag rows across page boundaries.
|
|
250
|
+
|
|
251
|
+
#### Row IDs
|
|
252
|
+
|
|
253
|
+
Drag-and-drop functionality relies on each table row having a unique ID. `DataTable.DragAndDropContainer` will throw an error if your don't provide unique IDs for each row in the `data` provided to `DataTable`, so you should consider wrapping your table in an `ErrorBoundary` to reduce the impact on your user if there is a problem with your data. By default, `DataTable.DragAndDropContainer` will look for this id in an `id` property on each object in `data`. You can use the `idColumn` prop to provide the name of a different property, e.g. `userId`, that already exists on your data so that you don't have to generate new IDs just for the table. For example, you could provide data like this with no additional configuration:
|
|
254
|
+
|
|
255
|
+
```tsx
|
|
256
|
+
const data = [
|
|
257
|
+
{ name: 'chrissy', hobby: 'bare-knuckle boxing', id: 1 },
|
|
258
|
+
{ name: 'agatha', hobby: 'crossfit', id: 2 },
|
|
259
|
+
{ name: 'betty', hobby: 'acting', id: 3 }
|
|
260
|
+
]`
|
|
261
|
+
|
|
262
|
+
<DataTable data={data} columns={columns}>
|
|
263
|
+
<DataTable.DragAndDropTable onDragAndDrop={(oldIndex, newIndex, newData) => console.log(oldIndex, newIndex, newData)}/>
|
|
264
|
+
</DataTable>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Or you could provide this data and specify the id column accordingly:
|
|
268
|
+
|
|
269
|
+
```tsx
|
|
270
|
+
const data = [
|
|
271
|
+
{ name: 'chrissy', hobby: 'bare-knuckle boxing', userId: 1 },
|
|
272
|
+
{ name: 'agatha', hobby: 'crossfit', userId: 2 },
|
|
273
|
+
{ name: 'betty', hobby: 'acting', userId: 3 }
|
|
274
|
+
]`
|
|
275
|
+
|
|
276
|
+
<DataTable data={data} columns={columns}>
|
|
277
|
+
<DataTable.DragAndDropTable idColumn="userId" onDragAndDrop={(oldIndex, newIndex, newData) => console.log(oldIndex, newIndex, newData)} />
|
|
278
|
+
</DataTable>
|
|
279
|
+
```
|