@atom-learning/components 2.24.0 → 2.25.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 +207 -0
- package/dist/components/accordion/AccordionContent.js +1 -1
- package/dist/components/accordion/AccordionItem.js +1 -1
- package/dist/components/alert-dialog/AlertDialogContent.js +1 -1
- package/dist/components/avatar/Avatar.js +1 -1
- package/dist/components/button/Button.js +1 -1
- package/dist/components/calendar/Calendar.js +1 -1
- package/dist/components/carousel/CarouselArrows.js +1 -1
- package/dist/components/carousel/CarouselSlide.js +1 -1
- package/dist/components/checkbox-field/CheckboxField.js +1 -1
- package/dist/components/chip/Chip.js +1 -1
- package/dist/components/chip/ChipGroup.js +1 -1
- package/dist/components/chip-dismissible-group/ChipDismissibleGroupRoot.js +1 -1
- package/dist/components/data-table/DataTable.d.ts +24 -2
- package/dist/components/data-table/DataTable.js +1 -1
- package/dist/components/data-table/DataTable.types.d.ts +28 -0
- package/dist/components/data-table/DataTable.types.js +1 -0
- package/dist/components/data-table/DataTableBody.js +1 -1
- package/dist/components/data-table/DataTableContext.d.ts +13 -11
- package/dist/components/data-table/DataTableContext.js +1 -1
- package/dist/components/data-table/DataTableDataCell.js +1 -1
- package/dist/components/data-table/DataTableError.d.ts +7 -0
- package/dist/components/data-table/DataTableError.js +1 -0
- package/dist/components/data-table/DataTableGlobalFilter.js +1 -1
- package/dist/components/data-table/DataTableLoading.d.ts +273 -0
- package/dist/components/data-table/DataTableLoading.js +1 -0
- package/dist/components/data-table/DataTableRow.js +1 -1
- package/dist/components/data-table/DataTableTable.js +1 -1
- package/dist/components/data-table/getNewAsyncData.d.ts +3 -0
- package/dist/components/data-table/getNewAsyncData.js +1 -0
- package/dist/components/data-table/pagination/Pagination.d.ts +1 -3
- package/dist/components/data-table/pagination/Pagination.js +1 -1
- package/dist/components/data-table/pagination/PaginationButtons.d.ts +1 -0
- package/dist/components/data-table/pagination/PaginationButtons.js +1 -1
- package/dist/components/dialog/DialogContent.js +1 -1
- package/dist/components/dismissible/DismissibleRoot.js +1 -1
- package/dist/components/dismissible/DismissibleTrigger.js +1 -1
- package/dist/components/dropdown-menu/DropdownMenuLinkItem.js +1 -1
- package/dist/components/field-wrapper/FieldDescription.js +1 -1
- package/dist/components/field-wrapper/InlineFieldWrapper.js +1 -1
- package/dist/components/file-input/FileInput.js +1 -1
- package/dist/components/grid/Grid.js +1 -1
- package/dist/components/heading/Heading.js +1 -1
- package/dist/components/icon/Icon.js +1 -1
- package/dist/components/index.d.ts +11 -11
- package/dist/components/inline-message/InlineMessage.js +1 -1
- package/dist/components/label/Label.js +1 -1
- package/dist/components/link/Link.js +1 -1
- package/dist/components/loader/Loader.js +1 -1
- package/dist/components/markdown-content/components/MarkdownEmphasis.d.ts +266 -0
- package/dist/components/markdown-content/components/MarkdownEmphasis.js +1 -1
- package/dist/components/markdown-content/components/MarkdownHeading.d.ts +0 -2
- package/dist/components/markdown-content/components/MarkdownHeading.js +1 -1
- package/dist/components/markdown-content/components/MarkdownImage.js +1 -1
- package/dist/components/markdown-content/components/MarkdownInlineCode.js +1 -1
- package/dist/components/markdown-content/components/MarkdownLink.js +1 -1
- package/dist/components/markdown-content/components/MarkdownListItem.js +1 -1
- package/dist/components/markdown-content/components/MarkdownParagraph.d.ts +0 -2
- package/dist/components/markdown-content/components/MarkdownParagraph.js +1 -1
- package/dist/components/markdown-content/components/MarkdownStrong.js +1 -1
- package/dist/components/markdown-content/components/MarkdownThematicBreak.js +1 -1
- package/dist/components/markdown-content/components/index.d.ts +1 -1
- package/dist/components/navigation/NavigationMenuDropdownContent.d.ts +2 -7
- package/dist/components/navigation/NavigationMenuDropdownContent.js +1 -1
- package/dist/components/navigation/NavigationMenuDropdownTrigger.js +1 -1
- package/dist/components/navigation/NavigationMenuLink.js +1 -1
- package/dist/components/notification-badge/NotificationBadge.js +1 -1
- package/dist/components/number-input/NumberInput.js +1 -1
- package/dist/components/number-input-field/NumberInputField.js +1 -1
- package/dist/components/popover/PopoverContent.js +1 -1
- package/dist/components/radio-button/RadioButton.js +1 -1
- package/dist/components/radio-button-field/RadioButtonField.js +1 -1
- package/dist/components/radio-button-field/RadioField.js +1 -1
- package/dist/components/radio-card/RadioCardGroup.js +1 -1
- package/dist/components/search-input/SearchInput.js +1 -1
- package/dist/components/select-field/SelectField.js +1 -1
- package/dist/components/sidedrawer/SidedrawerAccordion/SidedrawerAccordionContent.js +1 -1
- package/dist/components/sidedrawer/SidedrawerContent.js +1 -1
- package/dist/components/slider-field/SliderField.js +1 -1
- package/dist/components/stack-content/StackContent.js +1 -1
- package/dist/components/stepper/StepperStepBack.js +1 -1
- package/dist/components/table/TableHeader.js +1 -1
- package/dist/components/tabs/Tabs.js +1 -1
- package/dist/components/tabs/utils.js +1 -1
- package/dist/components/text/Text.js +1 -1
- package/dist/components/toast/Toast.js +1 -1
- package/dist/components/toast/ToastProvider.js +1 -1
- package/dist/components/toggle-group/ToggleGroupButton.js +1 -1
- package/dist/components/tooltip/TooltipContent.js +1 -1
- package/dist/components/video/Video.js +1 -1
- package/dist/docgen.json +1 -1
- package/dist/docs/DataTable.mdx +86 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.js +1 -1
- package/dist/utilities/hooks/useCallbackRef.js +1 -1
- package/package.json +1 -1
package/dist/docs/DataTable.mdx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: DataTable
|
|
3
|
-
component: DataTable, DataTable.Table, DataTable.Head, DataTable.HeaderCell, DataTable.Body, DataTable.Row, DataTable.DataCell, DataTable.GlobalFilter
|
|
3
|
+
component: DataTable, DataTable.Table, DataTable.Head, DataTable.HeaderCell, DataTable.Body, DataTable.Row, DataTable.DataCell, DataTable.GlobalFilter, DataTable.Loading, DataTable.Error
|
|
4
4
|
description: Displays tabular data with features such as sorting and pagination
|
|
5
5
|
category: Content
|
|
6
6
|
---
|
|
@@ -133,6 +133,91 @@ Note also that `useDataTable` can only be called by a child component of `DataTa
|
|
|
133
133
|
</DataTable>
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
+
### Server-side pagination and sorting
|
|
137
|
+
|
|
138
|
+
`DataTable` can be used with local pagination or server-side pagination (getting only the data needed for the current page). To use one or the other, you have to use the `data` or `getAsyncData` prop respectively.
|
|
139
|
+
|
|
140
|
+
The `getAsyncData` function accepts an object with the necessary parameters to get the relevant piece of data for the current page and order. All the parameters are optional, with these defaults:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
{
|
|
144
|
+
pageIndex: 0,
|
|
145
|
+
pageSize: 10,
|
|
146
|
+
sortBy: undefined,
|
|
147
|
+
sortDirection: undefined,
|
|
148
|
+
globalFilter: ''
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The response from the `getAsyncData` function must match the following schema:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
{
|
|
156
|
+
results: Array<Record<string, unknown>> // your current page data, sorted if specified
|
|
157
|
+
total: number // the total number of elements in your data
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
A loading state using `<DataTable.Loading>` is automatically included in `DataTable` which is visible while the `getAsyncData` promise is pending.
|
|
162
|
+
|
|
163
|
+
You can use `DataTable.Error` to display your own error component when the `getAsyncData` function promise rejects. Notice `DataTable.Error` doesn't render anything on its own, but whatever is passed as childern.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
<DataTable
|
|
167
|
+
columns={columns}
|
|
168
|
+
defaultPageSize={10}
|
|
169
|
+
defaultSort={{ column: 'name', direction: 'asc' }}
|
|
170
|
+
initialState={{ pagination: { pageIndex: 0, pageSize: 10 } }}
|
|
171
|
+
getAsyncData={async ({
|
|
172
|
+
pageIndex,
|
|
173
|
+
pageSize,
|
|
174
|
+
sortBy,
|
|
175
|
+
sortDirection,
|
|
176
|
+
globalFilter
|
|
177
|
+
}) => {
|
|
178
|
+
const params = new URLSearchParams({
|
|
179
|
+
page: pageIndex,
|
|
180
|
+
pageSize,
|
|
181
|
+
order: sortBy,
|
|
182
|
+
dir: sortDirection,
|
|
183
|
+
search: globalFilter
|
|
184
|
+
})
|
|
185
|
+
const response = await fetch(`https://your-api?${params.toString()}`)
|
|
186
|
+
const { results, total } = await response.json()
|
|
187
|
+
|
|
188
|
+
return { results, total }
|
|
189
|
+
}}
|
|
190
|
+
>
|
|
191
|
+
<DataTable.Table sortable css={{ mb: '$4', minWidth: '500px' }} />
|
|
192
|
+
<DataTable.Error>
|
|
193
|
+
{(retry) => <Button onClick={retry}>Try again</Button>}
|
|
194
|
+
</DataTable.Error>
|
|
195
|
+
<DataTable.Pagination />
|
|
196
|
+
</DataTable>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`DataTable.Error` provides a `retry` function to the children which allows you to recall the `getAsyncData` function. The `retry` function can be called with all the paginated parameters as an optional object. If no parameters are provided, `retry` will be called with the last paginated options.
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
<DataTable.Error>
|
|
203
|
+
{(retry) => (
|
|
204
|
+
<Button
|
|
205
|
+
onClick={() =>
|
|
206
|
+
retry?.({
|
|
207
|
+
pageIndex: 5,
|
|
208
|
+
pageSize: 10,
|
|
209
|
+
sortBy: 'name',
|
|
210
|
+
sortDirection: 'asc',
|
|
211
|
+
globalFilter: ''
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
>
|
|
215
|
+
Retry
|
|
216
|
+
</Button>
|
|
217
|
+
)}
|
|
218
|
+
</DataTable.Error>
|
|
219
|
+
```
|
|
220
|
+
|
|
136
221
|
## Features
|
|
137
222
|
|
|
138
223
|
### Search
|