@atom-learning/components 2.32.3-beta.0 → 2.33.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 +60 -0
- package/README.md +11 -5
- package/dist/components/accordion/AccordionItem.js +1 -1
- package/dist/components/accordion/AccordionTrigger.js +1 -1
- package/dist/components/avatar/Avatar.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.js +1 -1
- package/dist/components/data-table/DataTableBody.js +1 -1
- package/dist/components/data-table/DataTableDataCell.js +1 -1
- package/dist/components/data-table/DataTableGlobalFilter.js +1 -1
- package/dist/components/data-table/DataTableRow.js +1 -1
- package/dist/components/data-table/DataTableTable.js +1 -1
- package/dist/components/data-table/drag-and-drop/DraggableRow.js +1 -1
- package/dist/components/data-table/drag-and-drop/Handle.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/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/list/List.js +1 -1
- package/dist/components/markdown-content/components/MarkdownEmphasis.js +1 -1
- 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.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/navigation/NavigationMenuDropdownContent.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.d.ts +2 -0
- 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/Slider.d.ts +2 -1
- package/dist/components/slider/Slider.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/Table.d.ts +1 -5
- package/dist/components/table/Table.js +1 -1
- package/dist/components/table/TableBody.js +1 -1
- package/dist/components/table/TableHeader.js +1 -1
- package/dist/components/table/TableRow.js +1 -1
- package/dist/components/tabs/Tabs.js +1 -1
- package/dist/components/tabs/TabsTrigger.js +1 -1
- package/dist/components/tabs/TabsTriggerList.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/experiments/color-scheme/ColorScheme.js +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/utilities/hooks/useCallbackRef.js +1 -1
- package/package.json +6 -6
- package/dist/components/table/TableStickyColumnsContainer.d.ts +0 -9
- package/dist/components/table/TableStickyColumnsContainer.js +0 -1
- package/dist/docs/Accordion.mdx +0 -94
- package/dist/docs/ActionIcon.mdx +0 -87
- package/dist/docs/AlertDialog.mdx +0 -40
- package/dist/docs/Avatar.mdx +0 -129
- package/dist/docs/Badge.mdx +0 -55
- package/dist/docs/Box.mdx +0 -52
- package/dist/docs/Button.mdx +0 -68
- package/dist/docs/CONTRIBUTING.md +0 -224
- package/dist/docs/CSSWrapper.mdx +0 -10
- package/dist/docs/Carousel.mdx +0 -88
- package/dist/docs/Checkbox.mdx +0 -19
- package/dist/docs/CheckboxField.mdx +0 -14
- package/dist/docs/Chip.mdx +0 -118
- package/dist/docs/ChipDismissibleGroup.mdx +0 -33
- package/dist/docs/ChipToggleGroup.mdx +0 -27
- package/dist/docs/Combobox.mdx +0 -44
- package/dist/docs/DataTable.mdx +0 -279
- package/dist/docs/DateField.mdx +0 -20
- package/dist/docs/DateInput.mdx +0 -87
- package/dist/docs/Dialog.mdx +0 -68
- package/dist/docs/Dismissible.mdx +0 -48
- package/dist/docs/DismissibleGroup.mdx +0 -29
- package/dist/docs/Divider.mdx +0 -16
- package/dist/docs/DropdownMenu.mdx +0 -30
- package/dist/docs/EmptyState.mdx +0 -23
- package/dist/docs/FieldWrapper.mdx +0 -30
- package/dist/docs/FileInput.mdx +0 -45
- package/dist/docs/Flex.mdx +0 -16
- package/dist/docs/Form.mdx +0 -411
- package/dist/docs/Grid.mdx +0 -28
- package/dist/docs/Heading.mdx +0 -30
- package/dist/docs/Icon.mdx +0 -30
- package/dist/docs/Image.mdx +0 -14
- package/dist/docs/InlineMessage.mdx +0 -52
- package/dist/docs/Input.mdx +0 -24
- package/dist/docs/InputField.mdx +0 -26
- package/dist/docs/Label.mdx +0 -32
- package/dist/docs/Link.mdx +0 -53
- package/dist/docs/List.mdx +0 -38
- package/dist/docs/Loader.mdx +0 -16
- package/dist/docs/MarkdownContent.mdx +0 -77
- package/dist/docs/NavigationMenu.mdx +0 -144
- package/dist/docs/NotificationBadge.mdx +0 -35
- package/dist/docs/NumberInput.mdx +0 -37
- package/dist/docs/NumberInputField.mdx +0 -26
- package/dist/docs/PasswordField.mdx +0 -23
- package/dist/docs/PasswordInput.mdx +0 -15
- package/dist/docs/Popover.mdx +0 -29
- package/dist/docs/ProgressBar.mdx +0 -56
- package/dist/docs/README.mdx +0 -79
- package/dist/docs/RadioButton.mdx +0 -10
- package/dist/docs/RadioButtonField.mdx +0 -25
- package/dist/docs/RadioCard.mdx +0 -62
- package/dist/docs/SearchField.mdx +0 -26
- package/dist/docs/SearchInput.mdx +0 -13
- package/dist/docs/Select.mdx +0 -56
- package/dist/docs/SelectField.mdx +0 -17
- package/dist/docs/Sidedrawer.mdx +0 -155
- package/dist/docs/Slider.mdx +0 -117
- package/dist/docs/SliderField.mdx +0 -35
- package/dist/docs/Stack.mdx +0 -24
- package/dist/docs/StackContent.mdx +0 -32
- package/dist/docs/Stepper.mdx +0 -154
- package/dist/docs/Styling.mdx +0 -85
- package/dist/docs/Switch.mdx +0 -28
- package/dist/docs/Table.mdx +0 -146
- package/dist/docs/Tabs.mdx +0 -76
- package/dist/docs/Text.mdx +0 -24
- package/dist/docs/Textarea.mdx +0 -12
- package/dist/docs/TextareaField.mdx +0 -21
- package/dist/docs/Toast.mdx +0 -20
- package/dist/docs/ToggleGroup.mdx +0 -88
- package/dist/docs/Tooltip.mdx +0 -25
- package/dist/docs/TopBar.mdx +0 -95
- package/dist/docs/Video.mdx +0 -12
- package/dist/docs/accessibility.mdx +0 -67
- package/dist/docs/coreconcepts.mdx +0 -77
- package/dist/docs/introduction.mdx +0 -33
- package/dist/docs/versioning.mdx +0 -40
package/dist/docs/DataTable.mdx
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: DataTable
|
|
3
|
-
component: DataTable, DataTable.Table, DataTable.Head, DataTable.HeaderCell, DataTable.Body, DataTable.Row, DataTable.DataCell, DataTable.GlobalFilter, DataTable.Loading, DataTable.Error
|
|
4
|
-
description: Displays tabular data with features such as sorting and pagination
|
|
5
|
-
category: Content
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`DataTable` provides complex features for tables, like sorting and pagination. It's built around the `@tanstack/react-table` library and exposes the `table` state from that library directly. All util functions from the library are also compatible with `DataTable`. It's worth a good read of [`@tanstack/react-table`'s documentation](https://tanstack.com/table/v8/docs/guide/introduction) too, since we won't be repeating much of it here.
|
|
9
|
-
|
|
10
|
-
`DataTable` and its subcomponents are designed to be very simple to use. This is achieved by abstracting complex and/or boilerplate logic away from the consumer. For example, `DataTable.Pagination` can be dropped inside a `DataTable` to paginate the table's data without the need to add any configuration on `DataTable` itself. This is achieved by having `DataTable.Pagination` itself use the `applyPagination` and `setPageSize` methods exposed by `useDataTable` on its first render. This pattern should be replicated wherever practical to maintain the best developer experience possible.
|
|
11
|
-
|
|
12
|
-
## Anatomy
|
|
13
|
-
|
|
14
|
-
The root `DataTable` component manages the table's state and exposes it via the React Context API. This state can be accessed by any child components by calling `useDataTable`. You can pass an `initialState` prop to `DataTable` as described in the [`@tanstack/react-table` docs](https://tanstack.com/table/v8/docs/api/core/table#initialstate).
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
### Using defaults vs rolling your own
|
|
19
|
-
|
|
20
|
-
Here's a simple config for some table data and columns.
|
|
21
|
-
|
|
22
|
-
```tsx
|
|
23
|
-
// import { createColumnHelper } from '@tanstack/react-table'
|
|
24
|
-
|
|
25
|
-
const columnHelper = createColumnHelper<{
|
|
26
|
-
name: string
|
|
27
|
-
hobby: string
|
|
28
|
-
}>()
|
|
29
|
-
|
|
30
|
-
const columns = [
|
|
31
|
-
columnHelper.accessor('name', {
|
|
32
|
-
cell: (info) => info.getValue()
|
|
33
|
-
}),
|
|
34
|
-
columnHelper.accessor('hobby', {
|
|
35
|
-
cell: (info) => info.getValue()
|
|
36
|
-
}),
|
|
37
|
-
// Columns created with columnHelper.display won't be sortable.
|
|
38
|
-
// They need a header to be set manually since they're not just reading
|
|
39
|
-
// a property from the row.
|
|
40
|
-
columnHelper.display({
|
|
41
|
-
cell: (info) => <button>do something</button>,
|
|
42
|
-
header: 'Actions'
|
|
43
|
-
})
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
const data = [
|
|
47
|
-
{ name: 'chrissy', hobby: 'bare-knuckle boxing' },
|
|
48
|
-
{ name: 'agatha', hobby: 'crossfit' },
|
|
49
|
-
{ name: 'betty', hobby: 'acting' }
|
|
50
|
-
]
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
There are basically two ways to use `DataTable` to build a table from this config. The first uses the highest-level components that are bundled into `DataTable` to provide useful default behaviours with minimal code. The second directly accesses the state from `DataTable` and combines it with the `Table` UI components to achieve the same thing. This demonstrates how you could create more custom table UIs without the need to extend the high-level components.
|
|
54
|
-
|
|
55
|
-
#### With Defaults
|
|
56
|
-
|
|
57
|
-
The following two examples are exactly equivalent in their output. The second example is included to demonstrate what `DataTable`'s subcomponents do: they bundle up UI components and logic to provide useful defaults. They exist at various levels of abstraction, e.g. `DataTable.Table` renders `DataTable.Body`, which renders `DataTable.Row`. This means that you can use whichever component provides useful functionality for your use case while still being low-level enough to let you combine it with your own custom logic.
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
<DataTable columns={columns} data={data}>
|
|
61
|
-
<DataTable.Table sortable css={{mb: '$4'}}/>
|
|
62
|
-
<DataTable.Pagination pageSize={5} />
|
|
63
|
-
</DataTable>
|
|
64
|
-
|
|
65
|
-
<DataTable columns={columns} data={data}>
|
|
66
|
-
<Table>
|
|
67
|
-
<DataTable.Head sortable />
|
|
68
|
-
<DataTable.Body />
|
|
69
|
-
</Table>
|
|
70
|
-
<DataTable.Pagination pageSize={5} />
|
|
71
|
-
</DataTable>
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Rolling your own
|
|
75
|
-
|
|
76
|
-
If you need more flexibility than the default implementations provide, you can roll your own. Note that you can mix and match default implementations with your own. For example you could write your own table head implementation but use `DataTable.Body` for the body.
|
|
77
|
-
|
|
78
|
-
Note also that `useDataTable` can only be called by a child component of `DataTable`. In a real example, you'll probably have a separate named component which makes the `useDataTable` call, because if you're not using the defaults as above then you probably have some complex logic involved. In this example we've got an inline child component for simplicity.
|
|
79
|
-
|
|
80
|
-
Note that if you update the value of the `data` prop, it will reset the state of the table. This is useful if you are manipulating the data outside the context of the table.
|
|
81
|
-
|
|
82
|
-
```tsx
|
|
83
|
-
<DataTable columns={columns} data={data}>
|
|
84
|
-
{() => {
|
|
85
|
-
const { getHeaderGroups, getRowModel, setGlobalFilter, getState } =
|
|
86
|
-
useDataTable()
|
|
87
|
-
const { globalFilter } = getState()
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<>
|
|
91
|
-
<Label htmlFor="search">User search</Label>
|
|
92
|
-
<SearchInput
|
|
93
|
-
name="search"
|
|
94
|
-
value={globalFilter}
|
|
95
|
-
onChange={setGlobalFilter}
|
|
96
|
-
/>
|
|
97
|
-
<Table>
|
|
98
|
-
<Table.Header>
|
|
99
|
-
{getHeaderGroups().map((headerGroup) => (
|
|
100
|
-
<Table.Row key={headerGroup.id}>
|
|
101
|
-
{headerGroup.headers.map((header) => {
|
|
102
|
-
const sort = header.column.getIsSorted()
|
|
103
|
-
return (
|
|
104
|
-
<Table.HeaderCell
|
|
105
|
-
onClick={header.column.getToggleSortingHandler()}
|
|
106
|
-
{...props}
|
|
107
|
-
>
|
|
108
|
-
{flexRender(
|
|
109
|
-
header.column.columnDef.header,
|
|
110
|
-
header.getContext()
|
|
111
|
-
)}
|
|
112
|
-
{sort && { asc: '^', desc: 'v' }[sort as string]}
|
|
113
|
-
</Table.HeaderCell>
|
|
114
|
-
)
|
|
115
|
-
})}
|
|
116
|
-
</Table.Row>
|
|
117
|
-
))}
|
|
118
|
-
</Table.Header>
|
|
119
|
-
<Table.Body>
|
|
120
|
-
{getRowModel().rows.map((row) => (
|
|
121
|
-
<Table.Row>
|
|
122
|
-
{row.getVisibleCells().map((cell) => (
|
|
123
|
-
<Table.Cell key={cell.id}>
|
|
124
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
125
|
-
</Table.Cell>
|
|
126
|
-
))}
|
|
127
|
-
</Table.Row>
|
|
128
|
-
))}
|
|
129
|
-
</Table.Body>
|
|
130
|
-
</Table>
|
|
131
|
-
</>
|
|
132
|
-
// Then you could build your own pagination here too I guess? If you really wanted to?
|
|
133
|
-
)
|
|
134
|
-
}}
|
|
135
|
-
</DataTable>
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Server-side pagination and sorting
|
|
139
|
-
|
|
140
|
-
`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.
|
|
141
|
-
|
|
142
|
-
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:
|
|
143
|
-
|
|
144
|
-
```
|
|
145
|
-
{
|
|
146
|
-
pageIndex: 0,
|
|
147
|
-
pageSize: 10,
|
|
148
|
-
sortBy: undefined,
|
|
149
|
-
sortDirection: undefined,
|
|
150
|
-
globalFilter: ''
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
The response from the `getAsyncData` function must match the following schema:
|
|
155
|
-
|
|
156
|
-
```ts
|
|
157
|
-
{
|
|
158
|
-
results: Array<Record<string, unknown>> // your current page data, sorted if specified
|
|
159
|
-
total: number // the total number of elements in your data
|
|
160
|
-
}
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
A loading state using `<DataTable.Loading>` is automatically included in `DataTable` which is visible while the `getAsyncData` promise is pending.
|
|
164
|
-
|
|
165
|
-
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.
|
|
166
|
-
|
|
167
|
-
```tsx
|
|
168
|
-
<DataTable
|
|
169
|
-
columns={columns}
|
|
170
|
-
defaultPageSize={10}
|
|
171
|
-
defaultSort={{ column: 'name', direction: 'asc' }}
|
|
172
|
-
initialState={{ pagination: { pageIndex: 0, pageSize: 10 } }}
|
|
173
|
-
getAsyncData={async ({
|
|
174
|
-
pageIndex,
|
|
175
|
-
pageSize,
|
|
176
|
-
sortBy,
|
|
177
|
-
sortDirection,
|
|
178
|
-
globalFilter
|
|
179
|
-
}) => {
|
|
180
|
-
const params = new URLSearchParams({
|
|
181
|
-
page: pageIndex,
|
|
182
|
-
pageSize,
|
|
183
|
-
order: sortBy,
|
|
184
|
-
dir: sortDirection,
|
|
185
|
-
search: globalFilter
|
|
186
|
-
})
|
|
187
|
-
const response = await fetch(`https://your-api?${params.toString()}`)
|
|
188
|
-
const { results, total } = await response.json()
|
|
189
|
-
|
|
190
|
-
return { results, total }
|
|
191
|
-
}}
|
|
192
|
-
>
|
|
193
|
-
<DataTable.Table sortable css={{ mb: '$4', minWidth: '500px' }} />
|
|
194
|
-
<DataTable.Error>
|
|
195
|
-
{(retry) => <Button onClick={retry}>Try again</Button>}
|
|
196
|
-
</DataTable.Error>
|
|
197
|
-
<DataTable.Pagination />
|
|
198
|
-
</DataTable>
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
`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.
|
|
202
|
-
|
|
203
|
-
```tsx
|
|
204
|
-
<DataTable.Error>
|
|
205
|
-
{(retry) => (
|
|
206
|
-
<Button
|
|
207
|
-
onClick={() =>
|
|
208
|
-
retry?.({
|
|
209
|
-
pageIndex: 5,
|
|
210
|
-
pageSize: 10,
|
|
211
|
-
sortBy: 'name',
|
|
212
|
-
sortDirection: 'asc',
|
|
213
|
-
globalFilter: ''
|
|
214
|
-
})
|
|
215
|
-
}
|
|
216
|
-
>
|
|
217
|
-
Retry
|
|
218
|
-
</Button>
|
|
219
|
-
)}
|
|
220
|
-
</DataTable.Error>
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## Features
|
|
224
|
-
|
|
225
|
-
### Search
|
|
226
|
-
|
|
227
|
-
`DataTable.Search` renders a search input that filters the whole table by matching the input against values from any table column.
|
|
228
|
-
|
|
229
|
-
### Sorting
|
|
230
|
-
|
|
231
|
-
A `DataTable`'s data can be sorted by default and can also be sortable by the user. These two options are independent of each other.
|
|
232
|
-
|
|
233
|
-
#### Default sorting
|
|
234
|
-
|
|
235
|
-
`DataTable` takes an optional `defaultSort` prop to configure the column and direction for the table's default sorting, e.g. `{column: 'name', direction: 'asc'}`
|
|
236
|
-
|
|
237
|
-
#### User sorting
|
|
238
|
-
|
|
239
|
-
If `DataTable`'s `isSortable` state is `true`, then `DataTable.Header` will be clickable to toggle between ascending, descending and no sorting in any sortable columns. `DataTable.Head` and `DataTable.Table` take an optional boolean `sortable` prop to configure this option.
|
|
240
|
-
|
|
241
|
-
### Pagination
|
|
242
|
-
|
|
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
|
-
```
|
package/dist/docs/DateField.mdx
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Date Field
|
|
3
|
-
component: DateField
|
|
4
|
-
description: DateField renders a field composed of an DateInput, a Label and a InlineMessage
|
|
5
|
-
category: Form fields
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`DateField` is the preferred way to render a form field for dates.
|
|
9
|
-
|
|
10
|
-
In addition to text `Label` (required) and a validation error (optional), `DateField` accepts all the same props as `DateInput` and will pass them on to the `DateInput` it renders. However, as with all our composed components,
|
|
11
|
-
`DateField`’s `css` prop will be applied to a containing `Box`—the styling of the individual components inside `DateField` cannot be altered.
|
|
12
|
-
|
|
13
|
-
Err on the side of using consistent form fields, but if you really need something with different styling then consider composing your own field from the
|
|
14
|
-
`DateInput`, `Label` and `InlineMessage` components.
|
|
15
|
-
|
|
16
|
-
```tsx preview
|
|
17
|
-
<Form>
|
|
18
|
-
<DateField name="exam-date" label="Exam date" initialDate={new Date()} />
|
|
19
|
-
</Form>
|
|
20
|
-
```
|
package/dist/docs/DateInput.mdx
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Date Input
|
|
3
|
-
component: DateInput
|
|
4
|
-
description: A form component that provides a styled date selector without a label
|
|
5
|
-
category: Form primitives
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
Date Inputs should be accompanied by labels, so rather than using `DateInput` directly in a UI,
|
|
9
|
-
it’s normally best to the `DateField` component, which combines a `DateInput` with a `Label` and
|
|
10
|
-
displays validation errors. Alternatively, use this `DateInput` component to compose other field components
|
|
11
|
-
with more specific requirements.
|
|
12
|
-
|
|
13
|
-
`DateInput` is composed from [Dayzed](https://github.com/deseretdigital/dayzed), so further reading on the API can be found there. Some options from Dayzed are set by default in order to provide a uniform experience. For example, the prop `showOutsideDays`, which shows days outside the current calendar month that would appear on the grid, defaults to true in order to avoid extra whitespace.
|
|
14
|
-
|
|
15
|
-
```tsx preview
|
|
16
|
-
<DateInput />
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Initial Date
|
|
20
|
-
|
|
21
|
-
The `DateInput` component allows passing of an initial date, which will be selected by default. If you wish this to be the current date, you can use `new Date()` as per the preview below. Strings are also accepted and default to the `DD/MM/YYYY` format. It is recommended to use standard constructors for the date object as per MDN specifications.
|
|
22
|
-
|
|
23
|
-
```tsx preview
|
|
24
|
-
<DateInput initialDate={new Date()} />
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Date Format
|
|
28
|
-
|
|
29
|
-
Any combination of date formats can be passed in as a string, such as `DD/MM/YY` or `YYYY/MM/DD`. The default is `DD/MM/YYYY`. A full list of possible formats can be found [here](https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens).
|
|
30
|
-
|
|
31
|
-
```tsx
|
|
32
|
-
<DateInput dateFormat="YYYY/MM/DD" />
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Dayzed customisation
|
|
36
|
-
|
|
37
|
-
### First Day of Week
|
|
38
|
-
|
|
39
|
-
The calendar that is rendered by this component can have its first day of the week customised for different locales. The default is 1 (Monday), but for locales such as the US, pass in `firstDayOfWeek={0}` to set it to Sunday.
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
<DateInput firstDayOfWeek={0} />
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Translations
|
|
46
|
-
|
|
47
|
-
The weekday and month names can be changed to anything you wish by passing in an array of strings to `weekdayNames` and `monthNames`.
|
|
48
|
-
|
|
49
|
-
> NOTE: It is very important that you keep these labels in the right order. Weekdays must be `Sun -> Sat` and months must be `Jan -> Dec`.
|
|
50
|
-
|
|
51
|
-
```tsx preview
|
|
52
|
-
<DateInput
|
|
53
|
-
weekdayNames={['D', 'L', 'M', 'X', 'J', 'V', 'S']}
|
|
54
|
-
monthNames={[
|
|
55
|
-
'Enero',
|
|
56
|
-
'Febrero',
|
|
57
|
-
'Marzo',
|
|
58
|
-
'Abril',
|
|
59
|
-
'Mayo',
|
|
60
|
-
'Junio',
|
|
61
|
-
'Julio',
|
|
62
|
-
'Agosto',
|
|
63
|
-
'Septiembre',
|
|
64
|
-
'Octubre',
|
|
65
|
-
'Noviembre',
|
|
66
|
-
'Diciembre'
|
|
67
|
-
]}
|
|
68
|
-
/>
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
You can also translate the internal labels for accessibility purposes. The `labels` prop accepts an object containing three keys, `open`, `next`, and `previous`. These should all be strings.
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
<DateInput
|
|
75
|
-
labels={{
|
|
76
|
-
open: 'Open label',
|
|
77
|
-
next: 'Next month label',
|
|
78
|
-
previous: 'Previous month label'
|
|
79
|
-
}}
|
|
80
|
-
/>
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
If you need even finer control over what happens with the selected date, you can pass `onChange`, which takes a `Date` type as input.
|
|
84
|
-
|
|
85
|
-
```tsx
|
|
86
|
-
<DateInput onChange={(date) => doSomethingWith(date)} />
|
|
87
|
-
```
|
package/dist/docs/Dialog.mdx
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Dialog
|
|
3
|
-
component: Dialog,Dialog.Trigger,Dialog.Content,Dialog.Close
|
|
4
|
-
description: The Dialog component renders its children inside a modal and puts a dimmer over the rest of the screen
|
|
5
|
-
category: Surfaces
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`Dialog` exports many components that combine to create a modal. The `Dialog.Trigger` renders a `<button>` by default, but this can be overridden with the `asChild` prop, which will instead add all the functional and accessibility requirements to the child component instead (see the below example).
|
|
9
|
-
|
|
10
|
-
Also, note that the component must accept a `ref`.
|
|
11
|
-
|
|
12
|
-
Read more about the underlying UI component on the [Radix UI documentation site](https://radix-ui.com/primitives/docs/components/dialog).
|
|
13
|
-
|
|
14
|
-
```tsx preview
|
|
15
|
-
<Dialog>
|
|
16
|
-
<Dialog.Trigger asChild>
|
|
17
|
-
<Button>Open Dialog</Button>
|
|
18
|
-
</Dialog.Trigger>
|
|
19
|
-
<Dialog.Content>
|
|
20
|
-
<Heading size="sm" css={{ mb: '$3' }}>
|
|
21
|
-
Dialog
|
|
22
|
-
</Heading>
|
|
23
|
-
<Text size="sm" css={{ mb: '$3' }}>
|
|
24
|
-
The `Dialog` can display any type of element as a trigger and has the
|
|
25
|
-
content hidden by default
|
|
26
|
-
</Text>
|
|
27
|
-
<Button appearance="outline" size="sm" as={Dialog.Close}>
|
|
28
|
-
Close Dialog
|
|
29
|
-
</Button>
|
|
30
|
-
</Dialog.Content>
|
|
31
|
-
</Dialog>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
`Dialog` may be rendered without a close button. It's important to note that in case the default close button is hidden, one would need to provide an action button explicitly, to close the dialog.
|
|
35
|
-
|
|
36
|
-
```tsx
|
|
37
|
-
<Dialog>
|
|
38
|
-
<Dialog.Trigger>Open Dialog</Dialog.Trigger>
|
|
39
|
-
<Dialog.Content showCloseButton={false}>
|
|
40
|
-
<Text>
|
|
41
|
-
Dialog.Close is used below to retain the correct accessible roles and
|
|
42
|
-
related logic
|
|
43
|
-
</Text>
|
|
44
|
-
<Button as={Dialog.Close}>Close</Button>
|
|
45
|
-
</Dialog.Content>
|
|
46
|
-
</Dialog>
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
`Dialog` can also be rendered with a custom background. Important to note that `Dialog.Background` needs to be a child of `Dialog.Content`
|
|
50
|
-
|
|
51
|
-
```tsx
|
|
52
|
-
<Dialog>
|
|
53
|
-
<Dialog.Trigger>Open Dialog</Dialog.Trigger>
|
|
54
|
-
<Dialog.Content>
|
|
55
|
-
<Dialog.Background>
|
|
56
|
-
<Text>
|
|
57
|
-
Custom Background Content
|
|
58
|
-
</Text>
|
|
59
|
-
</Dialog.Background>
|
|
60
|
-
<Text>
|
|
61
|
-
Dialog.Background will appear above the Overlay, but below the DialogContent
|
|
62
|
-
</Text>
|
|
63
|
-
<Button as={Dialog.Close}>Close</Button>
|
|
64
|
-
</Dialog.Content>
|
|
65
|
-
</Dialog>
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
For any modifications of the default `Dialog` visuals, for example bypassing the panel design entirely, we recommend utilising the Radix UI Dialog component directly. You will need to wrap each exported component within a `styled()` function to enable `css` and `as`, and compose together `Dialog.Overlay` and `Dialog.Close` within `Dialog.Content` to mimic the behaviour of this modal.
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Dismissible
|
|
3
|
-
component: DismissibleRoot,Dismissible.Trigger
|
|
4
|
-
description: An element with a dismiss button which removes it from the view
|
|
5
|
-
category: Primitives
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`Dismissible` itself is a primitive. It has not been designed so it should not be used out-of-the-box as a user facing component.
|
|
9
|
-
Test the component is accessible depending on each implementation use case.
|
|
10
|
-
|
|
11
|
-
```tsx preview
|
|
12
|
-
<Dismissible
|
|
13
|
-
value="a"
|
|
14
|
-
onDismiss={(value) => {
|
|
15
|
-
alert(`dismiss ${value}`)
|
|
16
|
-
}}
|
|
17
|
-
>
|
|
18
|
-
Press the trigger to dismiss this ->
|
|
19
|
-
<Dismissible.Trigger aria-label="Dismiss 'a'" />
|
|
20
|
-
</Dismissible>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```tsx preview
|
|
24
|
-
<Dismissible
|
|
25
|
-
value="custom"
|
|
26
|
-
onDismiss={(value) => {
|
|
27
|
-
alert(`dismiss ${value}`)
|
|
28
|
-
}}
|
|
29
|
-
asChild
|
|
30
|
-
>
|
|
31
|
-
<Box
|
|
32
|
-
css={{
|
|
33
|
-
width: '100%',
|
|
34
|
-
fontFamily: 'system-ui',
|
|
35
|
-
border: '1px solid',
|
|
36
|
-
borderRadius: 4,
|
|
37
|
-
display: 'flex',
|
|
38
|
-
justifyContent: 'space-between',
|
|
39
|
-
padding: 8
|
|
40
|
-
}}
|
|
41
|
-
>
|
|
42
|
-
Basic custom implementation example
|
|
43
|
-
<Dismissible.Trigger asChild>
|
|
44
|
-
<button type="button">Custom Dismiss Trigger</button>
|
|
45
|
-
</Dismissible.Trigger>
|
|
46
|
-
</Box>
|
|
47
|
-
</Dismissible>
|
|
48
|
-
```
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Dismissible Group
|
|
3
|
-
component: DismissibleGroupRoot,DismissibleGroup.Item,DismissibleGroup.Trigger
|
|
4
|
-
description: A set of dismissible elements.
|
|
5
|
-
category: Primitives
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`DismissibleGroup` itself is a primitive. It has not been designed so it should not be used out-of-the-box as a user facing component.
|
|
9
|
-
Test the component is accessible depending on each implementation use case.
|
|
10
|
-
|
|
11
|
-
```tsx preview
|
|
12
|
-
<DismissibleGroup
|
|
13
|
-
onDismiss={(value) => {
|
|
14
|
-
alert(`dismiss ${value}`)
|
|
15
|
-
}}
|
|
16
|
-
>
|
|
17
|
-
<DismissibleGroup.Item value="a">
|
|
18
|
-
A
|
|
19
|
-
<DismissibleGroup.Trigger aria-label="Dismiss A" />
|
|
20
|
-
</DismissibleGroup.Item>
|
|
21
|
-
<DismissibleGroup.Item value="b" disabled>
|
|
22
|
-
B
|
|
23
|
-
<DismissibleGroup.Trigger />
|
|
24
|
-
</DismissibleGroup.Item>
|
|
25
|
-
<DismissibleGroup.Item value="c" disabled>
|
|
26
|
-
C
|
|
27
|
-
</DismissibleGroup.Item>
|
|
28
|
-
</DismissibleGroup>
|
|
29
|
-
```
|
package/dist/docs/Divider.mdx
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Divider
|
|
3
|
-
component: Divider
|
|
4
|
-
description: Use Divider to render a horizontal or vertical line which will extend to parent node's width / height
|
|
5
|
-
category: Content
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
It adds default styling and the `css` prop. Provide `orientation` as `horizontal` or `vertical` to achieve desirable output
|
|
9
|
-
|
|
10
|
-
```tsx preview
|
|
11
|
-
<Divider />
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
```tsx preview
|
|
15
|
-
<Divider orientation="vertical"/>
|
|
16
|
-
```
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Dropdown Menu
|
|
3
|
-
component: DropdownMenu,DropdownMenu.Trigger,DropdownMenu.Content,DropdownMenu.Item,DropdownMenu.Separator
|
|
4
|
-
description: The DropdownMenu components can be composed to create flexible dropdown menus with different types of items.
|
|
5
|
-
category: Surfaces
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`DropdownMenu` exports many components that combine to create a dropdown menu. The `DropdownMenu.Trigger` renders a `<button>` by default, but this can be overridden with the `asChild` prop, which will instead add all the functional and accessibility requirements to the child component instead (see the below example).
|
|
9
|
-
|
|
10
|
-
Also, note that the component must accept a `ref`.
|
|
11
|
-
|
|
12
|
-
Read more about the underlying UI component on the [Radix UI documentation site](https://radix-ui.com/primitives/docs/components/dropdown-menu).
|
|
13
|
-
|
|
14
|
-
```tsx preview
|
|
15
|
-
<DropdownMenu>
|
|
16
|
-
<DropdownMenu.Trigger asChild>
|
|
17
|
-
<Button>Click me</Button>
|
|
18
|
-
</DropdownMenu.Trigger>
|
|
19
|
-
<DropdownMenu.Content sideOffset={16}>
|
|
20
|
-
<DropdownMenu.Item onClick={() => alert('Great clicking!')}>
|
|
21
|
-
Item 1
|
|
22
|
-
</DropdownMenu.Item>
|
|
23
|
-
<DropdownMenu.Item>Item 2</DropdownMenu.Item>
|
|
24
|
-
<DropdownMenu.Separator />
|
|
25
|
-
<DropdownMenu.LinkItem href="/logout">Log Out</DropdownMenu.LinkItem>
|
|
26
|
-
</DropdownMenu.Content>
|
|
27
|
-
</DropdownMenu>
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
For any modifications of the default `DropdownMenu` visuals, we recommend utilising the Radix UI DropdownMenu component directly. You will need to wrap each exported component within a `styled()` function to enable the `css` prop.
|
package/dist/docs/EmptyState.mdx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Empty State
|
|
3
|
-
component: EmptyState
|
|
4
|
-
description: Empty states are messages that provide an explanation of an interface in absence of content.
|
|
5
|
-
category: Content
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`EmptyState` exports a number of components that can be composed together to create an `EmptyState` message.
|
|
9
|
-
The message can include Title and/or Body and sometimes they appear together with an illustration and actionable buttons.
|
|
10
|
-
There are 5 different size variants of `EmptyState` ( 'xs', 'sm', 'md', 'lg' and 'xl').
|
|
11
|
-
|
|
12
|
-
```jsx preview live
|
|
13
|
-
<EmptyState size="lg">
|
|
14
|
-
<EmptyState.Image
|
|
15
|
-
src="https://app.atomlearning.com/dist/29a378dc127c669808f2.svg"
|
|
16
|
-
alt=""
|
|
17
|
-
/>
|
|
18
|
-
<EmptyState.Title>No users found!</EmptyState.Title>
|
|
19
|
-
<EmptyState.Body>
|
|
20
|
-
You need to add some users before you can use this feature
|
|
21
|
-
</EmptyState.Body>
|
|
22
|
-
</EmptyState>
|
|
23
|
-
```
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Field Wrapper
|
|
3
|
-
component: FieldWrapper,InlineFieldWrapper
|
|
4
|
-
description: A utility component to help with composing consistent form fields
|
|
5
|
-
category: Form primitives
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
`FieldWrapper` renders a `Label` and (when applicable) a `InlineMessage`. Use it to wrap any type of input to create a consistent set of form fields.
|
|
9
|
-
|
|
10
|
-
```tsx preview
|
|
11
|
-
<FieldWrapper label="Example Field" fieldId="example">
|
|
12
|
-
<Input name="example" id="example" />
|
|
13
|
-
</FieldWrapper>
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
`InlineFieldWrapper` does the same but renders the label inline with the input, for example:`Checkbox`es and `Radio`s.
|
|
17
|
-
|
|
18
|
-
```tsx preview
|
|
19
|
-
<InlineFieldWrapper label="Example Checkbox">
|
|
20
|
-
<Checkbox name="example2" id="example2" />
|
|
21
|
-
</InlineFieldWrapper>
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
It can also be used alongside components like `Input`, `Select` or `Switch` when you may require some condensed inline fields. You can use the `direction` and `align` props to handle how the label is positioned relative to the component, in this case the label is placed on the right with `direction="reverse"` and it's aligned centrally with the switch.
|
|
25
|
-
|
|
26
|
-
```tsx preview
|
|
27
|
-
<InlineFieldWrapper direction="reverse" align="center" label="Toggle a field">
|
|
28
|
-
<Switch />
|
|
29
|
-
</InlineFieldWrapper>
|
|
30
|
-
```
|