torch-glare 2.5.6 → 2.6.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 +4 -3
- package/dist/bin/index.js +9 -24
- package/dist/bin/index.js.map +1 -1
- package/dist/src/commands/add.d.ts +2 -2
- package/dist/src/commands/add.d.ts.map +1 -1
- package/dist/src/commands/add.js +4 -70
- package/dist/src/commands/add.js.map +1 -1
- package/dist/src/commands/hook.d.ts +5 -4
- package/dist/src/commands/hook.d.ts.map +1 -1
- package/dist/src/commands/hook.js +7 -75
- package/dist/src/commands/hook.js.map +1 -1
- package/dist/src/commands/init.js +1 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/layout.d.ts +5 -4
- package/dist/src/commands/layout.d.ts.map +1 -1
- package/dist/src/commands/layout.js +7 -75
- package/dist/src/commands/layout.js.map +1 -1
- package/dist/src/commands/provider.d.ts +5 -4
- package/dist/src/commands/provider.d.ts.map +1 -1
- package/dist/src/commands/provider.js +7 -75
- package/dist/src/commands/provider.js.map +1 -1
- package/dist/src/commands/update.d.ts.map +1 -1
- package/dist/src/commands/update.js +78 -43
- package/dist/src/commands/update.js.map +1 -1
- package/dist/src/commands/utils.d.ts +5 -4
- package/dist/src/commands/utils.d.ts.map +1 -1
- package/dist/src/commands/utils.js +7 -80
- package/dist/src/commands/utils.js.map +1 -1
- package/dist/src/shared/addFromRegistry.d.ts +16 -0
- package/dist/src/shared/addFromRegistry.d.ts.map +1 -0
- package/dist/src/shared/addFromRegistry.js +88 -0
- package/dist/src/shared/addFromRegistry.js.map +1 -0
- package/dist/src/shared/getInstallCommand.d.ts.map +1 -1
- package/dist/src/shared/getInstallCommand.js +5 -0
- package/dist/src/shared/getInstallCommand.js.map +1 -1
- package/dist/src/shared/installDependencies.d.ts +0 -10
- package/dist/src/shared/installDependencies.d.ts.map +1 -1
- package/dist/src/shared/installDependencies.js +0 -17
- package/dist/src/shared/installDependencies.js.map +1 -1
- package/dist/src/shared/installFromPlan.d.ts +7 -5
- package/dist/src/shared/installFromPlan.d.ts.map +1 -1
- package/dist/src/shared/installFromPlan.js +103 -36
- package/dist/src/shared/installFromPlan.js.map +1 -1
- package/dist/src/shared/loadRegistry.d.ts +12 -3
- package/dist/src/shared/loadRegistry.d.ts.map +1 -1
- package/dist/src/shared/loadRegistry.js +19 -20
- package/dist/src/shared/loadRegistry.js.map +1 -1
- package/dist/src/shared/registryClient.d.ts +19 -0
- package/dist/src/shared/registryClient.d.ts.map +1 -0
- package/dist/src/shared/registryClient.js +128 -0
- package/dist/src/shared/registryClient.js.map +1 -0
- package/dist/src/shared/resolveEntry.d.ts +10 -7
- package/dist/src/shared/resolveEntry.d.ts.map +1 -1
- package/dist/src/shared/resolveEntry.js +18 -13
- package/dist/src/shared/resolveEntry.js.map +1 -1
- package/dist/src/shared/suggestOtherCommand.d.ts +7 -1
- package/dist/src/shared/suggestOtherCommand.d.ts.map +1 -1
- package/dist/src/shared/suggestOtherCommand.js +29 -23
- package/dist/src/shared/suggestOtherCommand.js.map +1 -1
- package/dist/src/types/main.d.ts +31 -2
- package/dist/src/types/main.d.ts.map +1 -1
- package/package.json +6 -11
- package/apps/lib/components/ActionButton.tsx +0 -93
- package/apps/lib/components/ActionsGroup.tsx +0 -27
- package/apps/lib/components/AlertDialog.tsx +0 -204
- package/apps/lib/components/Avatar.tsx +0 -46
- package/apps/lib/components/Badge.tsx +0 -250
- package/apps/lib/components/BadgeField.tsx +0 -403
- package/apps/lib/components/Breadcrumb.tsx +0 -280
- package/apps/lib/components/Button.tsx +0 -325
- package/apps/lib/components/ButtonGroup.tsx +0 -190
- package/apps/lib/components/Calendar.tsx +0 -115
- package/apps/lib/components/Card.tsx +0 -95
- package/apps/lib/components/Checkbox.tsx +0 -42
- package/apps/lib/components/ColorPicker.tsx +0 -441
- package/apps/lib/components/ConclusionHeader.tsx +0 -148
- package/apps/lib/components/ContextMenu.tsx +0 -571
- package/apps/lib/components/CountBadge.tsx +0 -52
- package/apps/lib/components/DataTable.tsx +0 -213
- package/apps/lib/components/DataViews/badge.ts +0 -49
- package/apps/lib/components/DataViews/cell.tsx +0 -324
- package/apps/lib/components/DataViews/context.ts +0 -144
- package/apps/lib/components/DataViews/data-views.tsx +0 -395
- package/apps/lib/components/DataViews/filters/children.tsx +0 -98
- package/apps/lib/components/DataViews/filters/custom.tsx +0 -34
- package/apps/lib/components/DataViews/filters/filters.tsx +0 -157
- package/apps/lib/components/DataViews/filters/index.ts +0 -4
- package/apps/lib/components/DataViews/filters/labelled.tsx +0 -20
- package/apps/lib/components/DataViews/filters/presets.tsx +0 -65
- package/apps/lib/components/DataViews/filters/sync.tsx +0 -35
- package/apps/lib/components/DataViews/filters/values.ts +0 -173
- package/apps/lib/components/DataViews/header.tsx +0 -220
- package/apps/lib/components/DataViews/hooks/index.ts +0 -5
- package/apps/lib/components/DataViews/hooks/useActiveRow.ts +0 -22
- package/apps/lib/components/DataViews/hooks/useControllable.ts +0 -52
- package/apps/lib/components/DataViews/index.ts +0 -88
- package/apps/lib/components/DataViews/panel/columns.tsx +0 -153
- package/apps/lib/components/DataViews/panel/controls.tsx +0 -106
- package/apps/lib/components/DataViews/panel/index.ts +0 -3
- package/apps/lib/components/DataViews/panel/panel.tsx +0 -164
- package/apps/lib/components/DataViews/panel/saved-views.tsx +0 -67
- package/apps/lib/components/DataViews/panel/section.tsx +0 -81
- package/apps/lib/components/DataViews/panel/sort.tsx +0 -42
- package/apps/lib/components/DataViews/panel/tab.tsx +0 -31
- package/apps/lib/components/DataViews/slots.ts +0 -72
- package/apps/lib/components/DataViews/states.tsx +0 -73
- package/apps/lib/components/DataViews/types.ts +0 -510
- package/apps/lib/components/DataViews/views/board-view.tsx +0 -381
- package/apps/lib/components/DataViews/views/card-rows.tsx +0 -36
- package/apps/lib/components/DataViews/views/inbox-view.tsx +0 -260
- package/apps/lib/components/DataViews/views/pane-views.tsx +0 -196
- package/apps/lib/components/DataViews/views/table-view.tsx +0 -493
- package/apps/lib/components/DataViews/views/tree-view.tsx +0 -367
- package/apps/lib/components/DatePicker.tsx +0 -232
- package/apps/lib/components/Dialog.tsx +0 -116
- package/apps/lib/components/Divider.tsx +0 -28
- package/apps/lib/components/Drawer.tsx +0 -451
- package/apps/lib/components/DropdownMenu.tsx +0 -554
- package/apps/lib/components/FieldHint.tsx +0 -69
- package/apps/lib/components/Form.tsx +0 -182
- package/apps/lib/components/FormBuilder/context.ts +0 -85
- package/apps/lib/components/FormBuilder/field-kind.ts +0 -28
- package/apps/lib/components/FormBuilder/fields/ChoiceFields.tsx +0 -60
- package/apps/lib/components/FormBuilder/fields/ColorField.tsx +0 -59
- package/apps/lib/components/FormBuilder/fields/CustomField.tsx +0 -11
- package/apps/lib/components/FormBuilder/fields/DateField.tsx +0 -32
- package/apps/lib/components/FormBuilder/fields/FieldArray.tsx +0 -74
- package/apps/lib/components/FormBuilder/fields/FieldShell.tsx +0 -168
- package/apps/lib/components/FormBuilder/fields/FileField.tsx +0 -39
- package/apps/lib/components/FormBuilder/fields/OptionListFields.tsx +0 -132
- package/apps/lib/components/FormBuilder/fields/OtpField.tsx +0 -31
- package/apps/lib/components/FormBuilder/fields/PhoneField.tsx +0 -109
- package/apps/lib/components/FormBuilder/fields/RichTextEditorField.tsx +0 -31
- package/apps/lib/components/FormBuilder/fields/SelectField.tsx +0 -114
- package/apps/lib/components/FormBuilder/fields/SignatureField.tsx +0 -157
- package/apps/lib/components/FormBuilder/fields/SliderField.tsx +0 -67
- package/apps/lib/components/FormBuilder/fields/SwitchBoxField.tsx +0 -41
- package/apps/lib/components/FormBuilder/fields/TableField.tsx +0 -336
- package/apps/lib/components/FormBuilder/fields/TextField.tsx +0 -213
- package/apps/lib/components/FormBuilder/fields/TreeSelectField.tsx +0 -43
- package/apps/lib/components/FormBuilder/fields/countries.ts +0 -303
- package/apps/lib/components/FormBuilder/fields/index.ts +0 -25
- package/apps/lib/components/FormBuilder/form-builder.tsx +0 -198
- package/apps/lib/components/FormBuilder/index.ts +0 -31
- package/apps/lib/components/FormBuilder/numberFormat.ts +0 -16
- package/apps/lib/components/FormBuilder/submit.tsx +0 -67
- package/apps/lib/components/FormBuilder/types.ts +0 -316
- package/apps/lib/components/FormRenderer/FormDrawer.tsx +0 -250
- package/apps/lib/components/FormRenderer/detail.tsx +0 -256
- package/apps/lib/components/FormRenderer/form-renderer.tsx +0 -358
- package/apps/lib/components/FormRenderer/header.tsx +0 -88
- package/apps/lib/components/FormRenderer/index.ts +0 -17
- package/apps/lib/components/FormRenderer/notch-action.tsx +0 -64
- package/apps/lib/components/FormRenderer/section.tsx +0 -39
- package/apps/lib/components/FormRenderer/stepper.tsx +0 -393
- package/apps/lib/components/FormRenderer/types.ts +0 -115
- package/apps/lib/components/FormSummary.tsx +0 -282
- package/apps/lib/components/HeaderBar.tsx +0 -117
- package/apps/lib/components/ImageAttachment.tsx +0 -209
- package/apps/lib/components/InnerLabelField.tsx +0 -154
- package/apps/lib/components/Input.tsx +0 -224
- package/apps/lib/components/InputField.tsx +0 -147
- package/apps/lib/components/InputOTP.tsx +0 -84
- package/apps/lib/components/Label.tsx +0 -129
- package/apps/lib/components/LabelField.tsx +0 -76
- package/apps/lib/components/LabeledCheckBox.tsx +0 -51
- package/apps/lib/components/LabeledRadio.tsx +0 -51
- package/apps/lib/components/LinkButton.tsx +0 -94
- package/apps/lib/components/LoginButton.tsx +0 -51
- package/apps/lib/components/PasswordLevel.tsx +0 -58
- package/apps/lib/components/Popover.tsx +0 -312
- package/apps/lib/components/ProfileMenu.tsx +0 -85
- package/apps/lib/components/Radio.tsx +0 -59
- package/apps/lib/components/RadioCard.tsx +0 -50
- package/apps/lib/components/ScrollArea.tsx +0 -54
- package/apps/lib/components/SearchField.tsx +0 -62
- package/apps/lib/components/SearchableSelect.tsx +0 -318
- package/apps/lib/components/SearchableTable.tsx +0 -344
- package/apps/lib/components/SearchableTree.tsx +0 -485
- package/apps/lib/components/SearchableTreeDialog.tsx +0 -502
- package/apps/lib/components/SectionBlock.tsx +0 -168
- package/apps/lib/components/Select.tsx +0 -347
- package/apps/lib/components/SimpleSelect.tsx +0 -225
- package/apps/lib/components/Skeleton.tsx +0 -12
- package/apps/lib/components/SlideDatePicker.tsx +0 -255
- package/apps/lib/components/SpinLoading.tsx +0 -174
- package/apps/lib/components/Stepper.tsx +0 -480
- package/apps/lib/components/Switch.tsx +0 -82
- package/apps/lib/components/TabFormItem.tsx +0 -153
- package/apps/lib/components/TabSwitch.tsx +0 -172
- package/apps/lib/components/Table.tsx +0 -597
- package/apps/lib/components/TextEditor/ChartBlockTool.ts +0 -676
- package/apps/lib/components/TextEditor/RichTextField.tsx +0 -46
- package/apps/lib/components/TextEditor/TableDnDWrapper.ts +0 -462
- package/apps/lib/components/TextEditor/TextEditor.tsx +0 -1164
- package/apps/lib/components/TextEditor/TextEditorToolbar.tsx +0 -429
- package/apps/lib/components/TextEditor/editor-tools/AlignmentTune.ts +0 -70
- package/apps/lib/components/TextEditor/editor-tools/ColorInlineTool.ts +0 -50
- package/apps/lib/components/TextEditor/editor-tools/StrikethroughInlineTool.ts +0 -48
- package/apps/lib/components/TextEditor/editor-tools/inlineFormat.ts +0 -98
- package/apps/lib/components/TextEditor/editorjs.d.ts +0 -60
- package/apps/lib/components/TextEditor/index.ts +0 -7
- package/apps/lib/components/TextEditor/markdownParser.ts +0 -346
- package/apps/lib/components/Textarea.tsx +0 -117
- package/apps/lib/components/Timeline.tsx +0 -263
- package/apps/lib/components/Toast.tsx +0 -87
- package/apps/lib/components/Toggle.tsx +0 -125
- package/apps/lib/components/ToggleButton.tsx +0 -140
- package/apps/lib/components/Tooltip.tsx +0 -116
- package/apps/lib/components/TransparentLabel.tsx +0 -71
- package/apps/lib/components/TreeDropDown.tsx +0 -115
- package/apps/lib/components/TreeFolder/TreeFolder.tsx +0 -380
- package/apps/lib/components/TreeFolder/TreeFolderBreadcrumb.tsx +0 -75
- package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +0 -354
- package/apps/lib/components/TreeFolder/TreeFolderStyles.tsx +0 -60
- package/apps/lib/components/TreeFolder/icons.tsx +0 -60
- package/apps/lib/components/TreeFolder/index.ts +0 -24
- package/apps/lib/components/TreeFolder/treeFolderUtils.ts +0 -109
- package/apps/lib/components/TreeFolder/types.ts +0 -77
- package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +0 -118
- package/apps/lib/hooks/useActiveTreeItem.ts +0 -61
- package/apps/lib/hooks/useClickOutside.ts +0 -27
- package/apps/lib/hooks/useDragDrop.tsx +0 -365
- package/apps/lib/hooks/useHtmlDir.ts +0 -31
- package/apps/lib/hooks/useInfiniteScroll.ts +0 -108
- package/apps/lib/hooks/useIsMobile.ts +0 -21
- package/apps/lib/hooks/useResize.ts +0 -67
- package/apps/lib/hooks/useTagSelection.ts +0 -300
- package/apps/lib/layouts/CNLayout.tsx +0 -372
- package/apps/lib/layouts/DataViewCard.tsx +0 -62
- package/apps/lib/layouts/FieldSection.tsx +0 -91
- package/apps/lib/layouts/TreeSubLayout.tsx +0 -173
- package/apps/lib/providers/ThemeProvider.tsx +0 -84
- package/apps/lib/registry.json +0 -1217
- package/apps/lib/tsconfig.json +0 -9
- package/apps/lib/tsconfig.tsbuildinfo +0 -1
- package/apps/lib/utils/cn.ts +0 -6
- package/apps/lib/utils/color.ts +0 -175
- package/apps/lib/utils/dataViews/path.ts +0 -67
- package/apps/lib/utils/dataViews/query.ts +0 -73
- package/apps/lib/utils/dataViews/types.ts +0 -187
- package/apps/lib/utils/dateFormat.ts +0 -108
- package/apps/lib/utils/resize.ts +0 -31
- package/apps/lib/utils/scroller.ts +0 -26
- package/apps/lib/utils/types.ts +0 -16
- package/docs/BLOCKS.md +0 -129
- package/docs/CHANGELOG-1.1.16.md +0 -108
- package/docs/Cover.png +0 -0
- package/docs/README.md +0 -215
- package/docs/components/action-button.md +0 -638
- package/docs/components/actions-group.md +0 -708
- package/docs/components/alert-dialog.md +0 -920
- package/docs/components/avatar.md +0 -709
- package/docs/components/badge-field.md +0 -738
- package/docs/components/badge.md +0 -301
- package/docs/components/breadcrumb.md +0 -930
- package/docs/components/button-group.md +0 -650
- package/docs/components/button.md +0 -639
- package/docs/components/calendar.md +0 -555
- package/docs/components/card.md +0 -622
- package/docs/components/chart-block-tool.md +0 -129
- package/docs/components/checkbox.md +0 -699
- package/docs/components/cn-layout.md +0 -854
- package/docs/components/color-picker.md +0 -101
- package/docs/components/conclusion-header.md +0 -80
- package/docs/components/context-menu.md +0 -483
- package/docs/components/count-badge.md +0 -560
- package/docs/components/data-table.md +0 -854
- package/docs/components/data-views/backend-response.md +0 -324
- package/docs/components/data-views/examples/a11y-rtl.md +0 -250
- package/docs/components/data-views/examples/api-orders-route.md +0 -130
- package/docs/components/data-views/examples/fields.md +0 -362
- package/docs/components/data-views/examples/filters.md +0 -307
- package/docs/components/data-views/examples/inbox-routing.md +0 -218
- package/docs/components/data-views/examples/index.md +0 -29
- package/docs/components/data-views/examples/overview.md +0 -244
- package/docs/components/data-views/examples/panel.md +0 -212
- package/docs/components/data-views/examples/scale.md +0 -231
- package/docs/components/data-views/examples/server-side.md +0 -210
- package/docs/components/data-views/examples/state.md +0 -250
- package/docs/components/data-views/examples/tree-custom.md +0 -388
- package/docs/components/data-views/examples/view-registry.md +0 -313
- package/docs/components/data-views/examples/views.md +0 -534
- package/docs/components/data-views/guide.md +0 -405
- package/docs/components/data-views/index.md +0 -1521
- package/docs/components/data-views/migration.md +0 -81
- package/docs/components/date-picker.md +0 -857
- package/docs/components/dialog.md +0 -929
- package/docs/components/divider.md +0 -766
- package/docs/components/drawer.md +0 -654
- package/docs/components/dropdown-menu.md +0 -668
- package/docs/components/field-hint.md +0 -898
- package/docs/components/field-section.md +0 -781
- package/docs/components/form-builder.md +0 -284
- package/docs/components/form-renderer.md +0 -396
- package/docs/components/form-summary.md +0 -138
- package/docs/components/form.md +0 -785
- package/docs/components/header-bar.md +0 -188
- package/docs/components/image-attachment.md +0 -906
- package/docs/components/inner-label-field.md +0 -819
- package/docs/components/input-field.md +0 -623
- package/docs/components/input-otp.md +0 -756
- package/docs/components/input.md +0 -634
- package/docs/components/label-field.md +0 -770
- package/docs/components/label.md +0 -761
- package/docs/components/labeled-check-box.md +0 -642
- package/docs/components/labeled-radio.md +0 -796
- package/docs/components/link-button.md +0 -685
- package/docs/components/login-button.md +0 -872
- package/docs/components/password-level.md +0 -803
- package/docs/components/popover.md +0 -649
- package/docs/components/profile-menu.md +0 -656
- package/docs/components/radio-card.md +0 -801
- package/docs/components/radio.md +0 -735
- package/docs/components/scroll-area.md +0 -691
- package/docs/components/search-field.md +0 -702
- package/docs/components/searchable-select.md +0 -368
- package/docs/components/searchable-table.md +0 -438
- package/docs/components/searchable-tree-dialog.md +0 -190
- package/docs/components/searchable-tree.md +0 -200
- package/docs/components/section-block.md +0 -483
- package/docs/components/select.md +0 -709
- package/docs/components/simple-select.md +0 -741
- package/docs/components/skeleton.md +0 -706
- package/docs/components/slide-date-picker.md +0 -837
- package/docs/components/spin-loading.md +0 -696
- package/docs/components/stepper.md +0 -316
- package/docs/components/switch.md +0 -770
- package/docs/components/tab-form-item.md +0 -773
- package/docs/components/tab-switch.md +0 -170
- package/docs/components/table-dnd-wrapper.md +0 -107
- package/docs/components/table.md +0 -1088
- package/docs/components/text-editor.md +0 -735
- package/docs/components/textarea.md +0 -681
- package/docs/components/timeline.md +0 -254
- package/docs/components/toast.md +0 -773
- package/docs/components/toggle-button.md +0 -643
- package/docs/components/toggle.md +0 -882
- package/docs/components/tooltip.md +0 -513
- package/docs/components/transparent-label.md +0 -721
- package/docs/components/tree-drop-down.md +0 -740
- package/docs/components/tree-folder.md +0 -110
- package/docs/components/tree-sub-layout.md +0 -707
- package/docs/explanation/architecture.md +0 -54
- package/docs/explanation/design-system.md +0 -52
- package/docs/how-to/form-and-list-recipes.md +0 -386
- package/docs/how-to/forms-with-form-builder.md +0 -472
- package/docs/how-to/guides.md +0 -1027
- package/docs/migration/changelog.md +0 -60
- package/docs/migration/form-builder-2.5.2.md +0 -113
- package/docs/reference/cli.md +0 -112
- package/docs/reference/components.md +0 -572
- package/docs/reference/hooks.md +0 -1523
- package/docs/reference/providers.md +0 -866
- package/docs/reference/tailwind-plugins.md +0 -942
- package/docs/reference/theme.md +0 -85
- package/docs/reference/types.md +0 -1016
- package/docs/reference/utilities.md +0 -726
- package/docs/tutorials/building-first-form.md +0 -846
- package/docs/tutorials/component-composition.md +0 -882
- package/docs/tutorials/getting-started.md +0 -302
- package/docs/tutorials/theming-basics.md +0 -785
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Render a backend response with DataViews
|
|
3
|
-
description: Recipes for turning common backend JSON shapes into a DataViews screen — flat lists, status fields, nested objects, hierarchies, message shapes, and server-driven filtering and paging.
|
|
4
|
-
group: how-to
|
|
5
|
-
keywords: [data-views, dataviews, recipes, backend, json, api, flat, nested, hierarchy, inbox, board, kanban, server-side, filtering, pagination, how-to]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Render a backend response with DataViews
|
|
9
|
-
|
|
10
|
-
[`DataViews`](./index.md) shows one dataset as a table, a kanban board, an inbox or
|
|
11
|
-
a tree. This guide maps the JSON you get back from an API to what you render.
|
|
12
|
-
|
|
13
|
-
One rule governs every recipe below, so it is worth stating first: **DataViews never reshapes your
|
|
14
|
-
data.** It does not group rows into columns, build a hierarchy, infer a schema, filter, sort or
|
|
15
|
-
page. It paints the `rows` you hand it, in the order you hand them, using the `fields` you describe.
|
|
16
|
-
Anything shaped — `groups`, `nodes` — you build. That is what makes a failed save leave the screen
|
|
17
|
-
showing the truth.
|
|
18
|
-
|
|
19
|
-
## TL;DR
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
const { data } = useQuery({ queryKey: ["records"], queryFn: () => api.get("/records") });
|
|
23
|
-
|
|
24
|
-
<DataViews rows={data?.rows ?? []} total={data?.total ?? 0} fields={FIELDS}>
|
|
25
|
-
<DataViews.Header title="Records">
|
|
26
|
-
<DataViews.ViewSwitch />
|
|
27
|
-
<DataViews.Search />
|
|
28
|
-
<DataViews.PanelToggle />
|
|
29
|
-
</DataViews.Header>
|
|
30
|
-
<DataViews.Table />
|
|
31
|
-
</DataViews>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
`fields` is the one thing with no default — DataViews will not guess your columns:
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
const FIELDS: FieldConfig[] = [
|
|
38
|
-
{ path: "id", label: "ID", type: "number" },
|
|
39
|
-
{ path: "name", label: "Name" },
|
|
40
|
-
{ path: "createdAt", label: "Created", type: "date-format", dateFormat: "YYYY-MM-DD" },
|
|
41
|
-
];
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Recipe 1 — A flat list of objects
|
|
45
|
-
|
|
46
|
-
The common case. Every field you list becomes a column, in the order you list it.
|
|
47
|
-
|
|
48
|
-
```json
|
|
49
|
-
[{ "id": 1, "name": "Acme", "total": 1240, "createdAt": "2025-09-10" }]
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
const FIELDS: FieldConfig[] = [
|
|
54
|
-
{ path: "id", label: "Order #", type: "number" },
|
|
55
|
-
{ path: "name", label: "Customer" },
|
|
56
|
-
{ path: "total", label: "Total", type: "currency", currency: "USD" },
|
|
57
|
-
{ path: "createdAt", label: "Created", type: "date-format", dateFormat: "YYYY-MM-DD" },
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
<DataViews rows={rows} total={rows.length} fields={FIELDS}>
|
|
61
|
-
<DataViews.Header title="Orders"><DataViews.ViewSwitch /></DataViews.Header>
|
|
62
|
-
<DataViews.Table selectable />
|
|
63
|
-
</DataViews>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
If your rows have no `id`, tell the component what identity is — selection, drag and the open row
|
|
67
|
-
all key off it:
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
<DataViews rows={rows} fields={FIELDS} getRowId={(row) => String(row.sku)}>
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Recipe 2 — A status field → a board
|
|
74
|
-
|
|
75
|
-
The board takes **columns you built**. Grouping is a decision (which statuses exist, in what order,
|
|
76
|
-
what an empty column means) that only you can make correctly.
|
|
77
|
-
|
|
78
|
-
```json
|
|
79
|
-
[{ "id": 1, "status": "Pending" }, { "id": 2, "status": "Shipped" }]
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
```tsx
|
|
83
|
-
const STATUSES = ["Pending", "Shipped", "Delivered", "Cancelled"] as const;
|
|
84
|
-
|
|
85
|
-
const groups = useMemo<RowGroup[]>(
|
|
86
|
-
() =>
|
|
87
|
-
STATUSES.map((status) => ({
|
|
88
|
-
id: status,
|
|
89
|
-
label: status,
|
|
90
|
-
color: ({ Pending: "gray", Shipped: "blue", Delivered: "green", Cancelled: "red" } as const)[status],
|
|
91
|
-
rows: rows.filter((row) => row.status === status),
|
|
92
|
-
})),
|
|
93
|
-
[rows],
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
<DataViews.Board
|
|
97
|
-
groups={groups}
|
|
98
|
-
titlePath="name"
|
|
99
|
-
onRowMove={(intent) => {
|
|
100
|
-
if (intent.to) move.mutate({ id: Number(intent.id), status: intent.to });
|
|
101
|
-
}}
|
|
102
|
-
/>
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
`onRowMove` reports **intent**. The card settles where it landed only once your refetched rows
|
|
106
|
-
agree — which is exactly why a rejected move snaps back on its own.
|
|
107
|
-
|
|
108
|
-
Paint the same field as a coloured chip in the table by giving it a type:
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
{ path: "status", label: "Status", type: "enum-badge",
|
|
112
|
-
variants: { Pending: "yellow", Shipped: "blue", Delivered: "green" } }
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Recipe 3 — Nested objects → dotted paths
|
|
116
|
-
|
|
117
|
-
No flattening step. A `path` reads as deep as you need.
|
|
118
|
-
|
|
119
|
-
```json
|
|
120
|
-
[{ "id": 1, "customer": { "name": "Acme", "email": "a@acme.com" }, "brand": { "name": "Bosch" } }]
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
```ts
|
|
124
|
-
const FIELDS: FieldConfig[] = [
|
|
125
|
-
{ path: "customer.name", label: "Customer" },
|
|
126
|
-
{ path: "customer.email", label: "Email", type: "link", linkType: "mailto" },
|
|
127
|
-
{ path: "brand.name", label: "Brand" },
|
|
128
|
-
];
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
Dotted paths work anywhere a path is taken — `titlePath`, `datePath`, `labelPath`, `sort.path` and
|
|
132
|
-
the keys of `filters`.
|
|
133
|
-
|
|
134
|
-
> **The one place `.` is special.** `DataViews.Filters` builds its controls with `FormBuilder`, and
|
|
135
|
-
> react-hook-form reads `.` as object nesting — so a filter on `customer.name` registers as
|
|
136
|
-
> `customer__name`. You still write the real path; only a hand-rolled `setValue` needs the escaped
|
|
137
|
-
> name.
|
|
138
|
-
|
|
139
|
-
## Recipe 4 — A hierarchy → `nodes`
|
|
140
|
-
|
|
141
|
-
Nested `children[]` or a flat `parentId` list both become `TreeNode[]`, and **you** do the
|
|
142
|
-
conversion: which field is the parent key, whether orphans become roots and how cycles are handled
|
|
143
|
-
are decisions the component cannot make for you.
|
|
144
|
-
|
|
145
|
-
```json
|
|
146
|
-
[{ "id": "1", "name": "Tools", "children": [{ "id": "2", "name": "Drills", "children": [] }] }]
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
```tsx
|
|
150
|
-
const toNodes = (items: ApiCategory[], depth = 0): TreeNode[] =>
|
|
151
|
-
items.map((item) => ({
|
|
152
|
-
id: item.id,
|
|
153
|
-
row: item as Row,
|
|
154
|
-
depth,
|
|
155
|
-
children: toNodes(item.children ?? [], depth + 1),
|
|
156
|
-
}));
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
From a flat `parentId` list:
|
|
160
|
-
|
|
161
|
-
```tsx
|
|
162
|
-
const toNodes = (items: ApiCategory[]): TreeNode[] => {
|
|
163
|
-
const byId = new Map(items.map((i) => [i.id, { id: i.id, row: i as Row, depth: 0, children: [] as TreeNode[] }]));
|
|
164
|
-
const roots: TreeNode[] = [];
|
|
165
|
-
for (const item of items) {
|
|
166
|
-
const node = byId.get(item.id)!;
|
|
167
|
-
const parent = item.parentId ? byId.get(item.parentId) : undefined;
|
|
168
|
-
// An orphan becoming a root is a decision — make it deliberately.
|
|
169
|
-
(parent ? parent.children : roots).push(node);
|
|
170
|
-
}
|
|
171
|
-
return roots;
|
|
172
|
-
};
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
Then render the tree, and say what its pane shows — **the pane's tabs are children, and passing
|
|
176
|
-
none means there is no pane at all**:
|
|
177
|
-
|
|
178
|
-
```tsx
|
|
179
|
-
<DataViews.Tree nodes={nodes} labelPath="name">
|
|
180
|
-
<DataViews.Tree.Table selectable />
|
|
181
|
-
<DataViews.Tree.Cards />
|
|
182
|
-
</DataViews.Tree>
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
When the tree holds one kind of thing and the pane must list another — categories in the rail,
|
|
186
|
-
items in the pane — that is `paneRows`:
|
|
187
|
-
|
|
188
|
-
```tsx
|
|
189
|
-
<DataViews.Tree nodes={categories} paneRows={(node) => itemsInCategory(node.id)}>
|
|
190
|
-
<DataViews.Tree.Table />
|
|
191
|
-
</DataViews.Tree>
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
## Recipe 5 — A message shape → the inbox
|
|
195
|
-
|
|
196
|
-
```json
|
|
197
|
-
[{ "id": 1, "subject": "Delivery delayed", "from": "ops@acme.com", "createdAt": "2025-09-10" }]
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
```tsx
|
|
201
|
-
<DataViews.Inbox titlePath="subject" datePath="createdAt">
|
|
202
|
-
<DataViews.Detail />
|
|
203
|
-
</DataViews.Inbox>
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
`DataViews.Detail` renders every visible field of the open row. For anything richer, the pane is
|
|
207
|
-
`children` and `useActiveRow()` resolves what is open.
|
|
208
|
-
|
|
209
|
-
If the open message should be a **URL** — a back button, a shareable link — make the items links:
|
|
210
|
-
|
|
211
|
-
```tsx
|
|
212
|
-
<DataViews.Inbox titlePath="subject" datePath="createdAt"
|
|
213
|
-
itemHref={(row, id) => `/inbox/${id}`} linkComponent={Link} />
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## Recipe 6 — Server-driven filtering, sorting and paging
|
|
217
|
-
|
|
218
|
-
Everything the user can ask for arrives as one object, because a query with a new filter and a
|
|
219
|
-
stale page number is not a query anyone meant to ask.
|
|
220
|
-
|
|
221
|
-
```tsx
|
|
222
|
-
const [query, setQuery] = useState(emptyQuery());
|
|
223
|
-
const { data, isPending } = useQuery({
|
|
224
|
-
queryKey: ["orders", query],
|
|
225
|
-
queryFn: () => fetch(`/api/orders?${queryToParams(query)}`).then((r) => r.json()),
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
<DataViews
|
|
229
|
-
rows={data?.rows ?? []}
|
|
230
|
-
total={data?.total ?? 0}
|
|
231
|
-
fields={FIELDS}
|
|
232
|
-
loading={isPending}
|
|
233
|
-
onQueryChange={setQuery}
|
|
234
|
-
>
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
The route handler decodes with `parseQuery`, so the encoder and the decoder cannot drift:
|
|
238
|
-
|
|
239
|
-
```ts
|
|
240
|
-
// app/api/orders/route.ts
|
|
241
|
-
import { parseQuery } from "@/components/DataViews";
|
|
242
|
-
|
|
243
|
-
export async function GET(request: Request) {
|
|
244
|
-
const { search, filters, sort, page, pageSize } = parseQuery(new URL(request.url));
|
|
245
|
-
// your matcher, your ORM
|
|
246
|
-
return Response.json({ rows, total });
|
|
247
|
-
}
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
`filters` is `Record<path, string[] | { kind: "number", min?, max? } | { kind: "date", from?, to? }>`.
|
|
251
|
-
How the constraints combine — AND across fields, OR within one, fuzzy or exact — is your matcher's
|
|
252
|
-
business. The component reports what was chosen and nothing more.
|
|
253
|
-
|
|
254
|
-
**Paging is scrolling.** There is no pager: hand over `onLoadMore` and **append** each page.
|
|
255
|
-
Whether there is more is derived from `rows.length < total`, so there is no flag to keep in sync.
|
|
256
|
-
|
|
257
|
-
```tsx
|
|
258
|
-
const { data, fetchNextPage, isPending, isFetchingNextPage } = useInfiniteQuery({
|
|
259
|
-
queryKey: ["orders", { ...query, page: undefined }], // not `page` — pageParam drives that
|
|
260
|
-
initialPageParam: 1,
|
|
261
|
-
queryFn: ({ pageParam }) =>
|
|
262
|
-
fetch(`/api/orders?${queryToParams({ ...query, page: pageParam })}`).then((r) => r.json()),
|
|
263
|
-
getNextPageParam: (last, pages) => {
|
|
264
|
-
const loaded = pages.reduce((n, p) => n + p.rows.length, 0);
|
|
265
|
-
return loaded < last.total ? pages.length + 1 : undefined;
|
|
266
|
-
},
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
<DataViews
|
|
270
|
-
rows={data?.pages.flatMap((p) => p.rows) ?? []}
|
|
271
|
-
total={data?.pages[0]?.total ?? 0}
|
|
272
|
-
loading={isPending}
|
|
273
|
-
onLoadMore={fetchNextPage}
|
|
274
|
-
loadingMore={isFetchingNextPage}
|
|
275
|
-
fields={FIELDS}
|
|
276
|
-
onQueryChange={setQuery}
|
|
277
|
-
/>
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
## Recipe 7 — A response nothing built-in fits
|
|
281
|
-
|
|
282
|
-
Two seams, in increasing order of commitment.
|
|
283
|
-
|
|
284
|
-
**Repaint a field** — the narrowest, and it applies in every view at once:
|
|
285
|
-
|
|
286
|
-
```ts
|
|
287
|
-
{ path: "health", label: "Health", render: (value, row) => <HealthPill value={Number(value)} row={row} /> }
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
**Add a view of your own.** `markView` registers it in the switcher beside the built-in four; it
|
|
291
|
-
reads the same context, loading state included:
|
|
292
|
-
|
|
293
|
-
```tsx
|
|
294
|
-
const GalleryView = markView(function GalleryView() {
|
|
295
|
-
const { rows, visibleFields, loading, getRowId } = useDataViewsData();
|
|
296
|
-
if (loading) return <SkeletonBar className="h-40" />;
|
|
297
|
-
return <div className="grid grid-cols-3 gap-3">{rows.map((row, i) => <Tile key={getRowId(row, i)} row={row} />)}</div>;
|
|
298
|
-
}, { defaultId: "gallery", defaultLabel: "Gallery" });
|
|
299
|
-
|
|
300
|
-
<DataViews …>
|
|
301
|
-
<DataViews.Table />
|
|
302
|
-
<GalleryView icon={<i className="ri-layout-grid-line" />} />
|
|
303
|
-
</DataViews>
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
## Gotchas
|
|
307
|
-
|
|
308
|
-
- **Nothing filters itself.** If the rows do not change, nothing on screen changes. That is the
|
|
309
|
-
contract, not a bug.
|
|
310
|
-
- **`total` is the server's count**, not `rows.length`. Scroll loading stops when
|
|
311
|
-
`rows.length >= total`, so a wrong `total` either stops early or loops.
|
|
312
|
-
- **Append, never replace**, when paging — replacing resets the list and the sentinel fires again.
|
|
313
|
-
- **Memoize `groups` and `nodes`.** They are rebuilt on every render otherwise, and both are
|
|
314
|
-
diffed.
|
|
315
|
-
- **A part exists because you rendered it.** There is no `views={{ … }}` map; wrap a view in a
|
|
316
|
-
condition to hide it, and the component switches away if it was open.
|
|
317
|
-
- **Booleans have no filter section.** Use a Yes/No `RadioList`, or `Filters.Custom`.
|
|
318
|
-
|
|
319
|
-
## Related
|
|
320
|
-
|
|
321
|
-
- [`DataViews` component reference](./index.md) — every part, prop and type
|
|
322
|
-
- [Build a DataViews screen](./guide.md) — the same ground as scenarios, start to finish
|
|
323
|
-
- [Migrating to the DataViews component](./migration.md) — if you are coming from
|
|
324
|
-
`DataViewsLayout`
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: DataViews example — Keyboard & RTL
|
|
3
|
-
description: Keyboard paths and the RTL mirror.
|
|
4
|
-
group: examples
|
|
5
|
-
component: DataViews
|
|
6
|
-
keywords: [data-views, example, examples, a11y, rtl]
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# DataViews example — Keyboard & RTL
|
|
10
|
-
|
|
11
|
-
Keyboard paths and the RTL mirror.
|
|
12
|
-
|
|
13
|
-
Complete and runnable — this is the page itself, not an excerpt. In the monorepo it lives at `apps/app/data-views/a11y-rtl/page.tsx`.
|
|
14
|
-
|
|
15
|
-
See the [component reference](../index.md) for what each prop does, or the [guide](../guide.md) for the same ground as scenarios.
|
|
16
|
-
|
|
17
|
-
```tsx
|
|
18
|
-
"use client";
|
|
19
|
-
|
|
20
|
-
import { useMemo, useState } from "react";
|
|
21
|
-
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
22
|
-
import { Filter, Settings } from "lucide-react";
|
|
23
|
-
import { Button } from "@/components/Button";
|
|
24
|
-
import { DataViews, emptyQuery, queryToParams, type SavedView } from "@/components/DataViews";
|
|
25
|
-
import { FormBuilder } from "@/components/FormBuilder";
|
|
26
|
-
import type {
|
|
27
|
-
DataViewsQuery,
|
|
28
|
-
FieldConfig,
|
|
29
|
-
Row,
|
|
30
|
-
RowGroup,
|
|
31
|
-
TreeNode,
|
|
32
|
-
} from "@/utils/dataViews/types";
|
|
33
|
-
import type { Themes } from "@/utils/types";
|
|
34
|
-
|
|
35
|
-
// ─── Data ─────────────────────────────────────────────────────────────────────
|
|
36
|
-
|
|
37
|
-
interface Order extends Row {
|
|
38
|
-
id: number;
|
|
39
|
-
customer: { name: string };
|
|
40
|
-
status: "Pending" | "Shipped" | "Delivered";
|
|
41
|
-
total: number;
|
|
42
|
-
createdAt: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const FIELDS: FieldConfig[] = [
|
|
46
|
-
{ path: "id", label: "Order #", type: "number" },
|
|
47
|
-
{ path: "customer.name", label: "Customer", type: "text" },
|
|
48
|
-
{ path: "brand.name", label: "Brand", type: "text" },
|
|
49
|
-
{ path: "status", label: "Status", type: "enum-badge", variants: { Pending: "yellow", Shipped: "blue", Delivered: "green" } },
|
|
50
|
-
{ path: "total", label: "Total", type: "currency", currency: "USD" },
|
|
51
|
-
{ path: "createdAt", label: "Created", type: "date-format", dateFormat: "YYYY-MM-DD" },
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
/** Arabic labels, so a right-to-left layout is legible rather than mirrored English. */
|
|
55
|
-
const ARABIC_FIELDS: FieldConfig[] = [
|
|
56
|
-
{ path: "id", label: "رقم الطلب", type: "number" },
|
|
57
|
-
{ path: "customer.name", label: "العميل", type: "text" },
|
|
58
|
-
{ path: "status", label: "الحالة", type: "enum-badge", variants: { Pending: "yellow", Shipped: "blue", Delivered: "green" } },
|
|
59
|
-
{ path: "total", label: "المجموع", type: "currency", currency: "USD" },
|
|
60
|
-
{ path: "createdAt", label: "التاريخ", type: "date-format", dateFormat: "YYYY-MM-DD" },
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
/** Dynamic sets — in a real app these come from the endpoint that also does the filtering. */
|
|
64
|
-
const CUSTOMER_OPTIONS = [
|
|
65
|
-
"Acme Inc.", "Globex Corp.", "Initech", "Umbrella",
|
|
66
|
-
"Hooli", "Stark Industries", "Wayne Enterprises", "Cyberdyne",
|
|
67
|
-
].map((v) => ({ label: v, value: v }));
|
|
68
|
-
|
|
69
|
-
const BRAND_OPTIONS = ["Bosch", "Makita", "DeWalt", "Hilti"].map((v) => ({ label: v, value: v }));
|
|
70
|
-
|
|
71
|
-
const PRIORITY_OPTIONS = ["High", "Medium", "Low"].map((v) => ({ label: v, value: v }));
|
|
72
|
-
|
|
73
|
-
const STATUS_OPTIONS = [
|
|
74
|
-
{ label: "Pending", value: "Pending" },
|
|
75
|
-
{ label: "Shipped", value: "Shipped" },
|
|
76
|
-
{ label: "Delivered", value: "Delivered" },
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The request this page makes. The querying itself happens in `app/api/orders/route.ts` —
|
|
81
|
-
* nothing on this page filters, sorts or pages anything, which is the split DataViews is built
|
|
82
|
-
* around.
|
|
83
|
-
*/
|
|
84
|
-
async function fetchOrders(q: DataViewsQuery): Promise<{ rows: Order[]; total: number }> {
|
|
85
|
-
const params = queryToParams(q);
|
|
86
|
-
const res = await fetch(`/api/orders?${params}`);
|
|
87
|
-
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
88
|
-
return res.json();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const groupByStatus = (rows: readonly Order[]): RowGroup[] =>
|
|
92
|
-
(["Pending", "Shipped", "Delivered"] as const).map((status) => ({
|
|
93
|
-
id: status,
|
|
94
|
-
label: status,
|
|
95
|
-
color: ({ Pending: "gray", Shipped: "blue", Delivered: "green" } as const)[status],
|
|
96
|
-
rows: rows.filter((row) => row.status === status),
|
|
97
|
-
}));
|
|
98
|
-
|
|
99
|
-
const nodesFromRows = (rows: readonly Order[]): TreeNode[] =>
|
|
100
|
-
rows.map((row) => ({ id: String(row.id), row, depth: 0, children: [] }));
|
|
101
|
-
|
|
102
|
-
// ─── Page ─────────────────────────────────────────────────────────────────────
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Keyboard: tab through it with the mouse down. A row with `onRowClick` takes a `tabIndex`, a
|
|
106
|
-
* button role and Enter/Space handling — press Enter on one and it selects. Without the handler a
|
|
107
|
-
* row stays a plain row and is skipped, which is right: a row that does nothing is not a tab stop.
|
|
108
|
-
*
|
|
109
|
-
* The tree handles `←`/`→` and Enter but not yet `↑`/`↓`, `Home`/`End` or roving tabindex, so
|
|
110
|
-
* every node is its own tab stop. Drag-and-drop has no keyboard equivalent at all — if moving
|
|
111
|
-
* records matters, give people a menu action that emits the same intent.
|
|
112
|
-
*
|
|
113
|
-
* Direction comes from the DOM, not a prop: the component is built from logical properties, so
|
|
114
|
-
* `dir="rtl"` moves the rail left and aligns the table to the start edge. `theme` sets
|
|
115
|
-
* `data-theme` — but the filter dropdowns and the date calendar portal to `document.body`, so
|
|
116
|
-
* they follow the *page's* theme rather than this one.
|
|
117
|
-
*/
|
|
118
|
-
export default function AccessibilityExample() {
|
|
119
|
-
const [rtl, setRtl] = useState(false);
|
|
120
|
-
const [theme, setTheme] = useState<Themes>("default");
|
|
121
|
-
|
|
122
|
-
const [query, setQuery] = useState(emptyQuery());
|
|
123
|
-
const [activated, setActivated] = useState<string | null>(null);
|
|
124
|
-
const [saved, setSaved] = useState<SavedView[]>([]);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const { data, isPending, fetchNextPage, isFetchingNextPage } = useInfiniteQuery({
|
|
128
|
-
// The key *is* the query: touch any part of it and TanStack refetches, and a response that
|
|
129
|
-
// has been superseded is discarded rather than landing on top of a newer one.
|
|
130
|
-
queryKey: ["a11y-orders", { ...query, page: undefined }],
|
|
131
|
-
queryFn: ({ pageParam }) => fetchOrders({ ...query, page: pageParam }),
|
|
132
|
-
initialPageParam: 1,
|
|
133
|
-
// Undefined means "no more" — which is what the component's `hasMore` resolves to.
|
|
134
|
-
getNextPageParam: (last, pages) => {
|
|
135
|
-
const loaded = pages.reduce((n, page) => n + page.rows.length, 0);
|
|
136
|
-
return loaded < last.total ? pages.length + 1 : undefined;
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Memoised because `data?.rows ?? []` is a new array on every render, which would make the
|
|
141
|
-
// `groups`/`nodes` memos below miss every time and hand the board a new array to diff.
|
|
142
|
-
const rows = useMemo(() => data?.pages.flatMap((page) => page.rows) ?? [], [data]);
|
|
143
|
-
const total = data?.pages[0]?.total ?? 0;
|
|
144
|
-
const groups = useMemo(() => groupByStatus(rows), [rows]);
|
|
145
|
-
const nodes = useMemo(() => nodesFromRows(rows), [rows]);
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
<div dir={rtl ? "rtl" : "ltr"} className="flex h-full min-h-0 flex-col p-4">
|
|
149
|
-
<DataViews
|
|
150
|
-
key={rtl ? "rtl" : "ltr"}
|
|
151
|
-
rows={rows}
|
|
152
|
-
fields={rtl ? ARABIC_FIELDS : FIELDS}
|
|
153
|
-
theme={theme}
|
|
154
|
-
total={total}
|
|
155
|
-
loading={isPending}
|
|
156
|
-
onLoadMore={fetchNextPage}
|
|
157
|
-
loadingMore={isFetchingNextPage}
|
|
158
|
-
onQueryChange={setQuery}
|
|
159
|
-
className="h-full"
|
|
160
|
-
>
|
|
161
|
-
<DataViews.Header title={rtl ? "الطلبات" : "Orders"}>
|
|
162
|
-
<DataViews.ViewSwitch />
|
|
163
|
-
<DataViews.Search />
|
|
164
|
-
<DataViews.Actions>
|
|
165
|
-
{/* Proof the keyboard path works: Enter on a focused row fires `onRowClick`. */}
|
|
166
|
-
<span
|
|
167
|
-
data-testid="activated"
|
|
168
|
-
className="typography-body-small-regular text-content-presentation-global-secondary"
|
|
169
|
-
>
|
|
170
|
-
{activated ? `row ${activated}` : "no row activated"}
|
|
171
|
-
</span>
|
|
172
|
-
{/* Two buttons rather than one toggle: a single button labelled with the current
|
|
173
|
-
direction is ambiguous — it reads as either the state or the action. */}
|
|
174
|
-
<Button variant="BluColStyle" size="M" onClick={() => setRtl(false)}>
|
|
175
|
-
LTR
|
|
176
|
-
</Button>
|
|
177
|
-
<Button variant="BluColStyle" size="M" onClick={() => setRtl(true)}>
|
|
178
|
-
RTL
|
|
179
|
-
</Button>
|
|
180
|
-
{(["default", "dark", "light"] as const).map((t) => (
|
|
181
|
-
<Button variant="BluColStyle"
|
|
182
|
-
size="M"
|
|
183
|
-
key={t}
|
|
184
|
-
onClick={() => setTheme(t)}
|
|
185
|
-
>
|
|
186
|
-
{t}
|
|
187
|
-
</Button>
|
|
188
|
-
))}
|
|
189
|
-
</DataViews.Actions>
|
|
190
|
-
<DataViews.PanelToggle />
|
|
191
|
-
</DataViews.Header>
|
|
192
|
-
|
|
193
|
-
{/* Enter on a focused row fires `onRowClick` — the visible proof the row is reachable
|
|
194
|
-
without a mouse. What to do about it is the app's call; here it is a readout. */}
|
|
195
|
-
<DataViews.Table selectable onRowClick={(_row, id) => setActivated(id)} />
|
|
196
|
-
<DataViews.Board
|
|
197
|
-
groups={groups}
|
|
198
|
-
titlePath="customer.name"
|
|
199
|
-
/>
|
|
200
|
-
{/* The pane's tabs are children, like every other part: pass none and there is no pane. */}
|
|
201
|
-
<DataViews.Tree nodes={nodes} labelPath="customer.name">
|
|
202
|
-
<DataViews.Tree.Table />
|
|
203
|
-
<DataViews.Tree.Cards />
|
|
204
|
-
</DataViews.Tree>
|
|
205
|
-
|
|
206
|
-
<DataViews.Panel>
|
|
207
|
-
<DataViews.Panel.Tab value="config" label="Config." icon={<Settings />}>
|
|
208
|
-
{/* Saving is the app's job — a view outlives the component. Restoring is not:
|
|
209
|
-
hand the snapshot back and selecting it puts everything back internally. */}
|
|
210
|
-
<DataViews.Panel.SavedViews
|
|
211
|
-
views={saved}
|
|
212
|
-
onSave={(snapshot) =>
|
|
213
|
-
setSaved((prev) => [
|
|
214
|
-
...prev,
|
|
215
|
-
{ id: `view-${prev.length + 1}`, label: `View ${prev.length + 1}`, snapshot },
|
|
216
|
-
])
|
|
217
|
-
}
|
|
218
|
-
/>
|
|
219
|
-
<DataViews.Panel.Columns />
|
|
220
|
-
<DataViews.Panel.Sort />
|
|
221
|
-
</DataViews.Panel.Tab>
|
|
222
|
-
|
|
223
|
-
<DataViews.Panel.Tab value="filters" label="Filters" icon={<Filter />}>
|
|
224
|
-
{/* The controls are FormBuilder fields — the same Select and Slider any form in
|
|
225
|
-
this library uses. Filters reads each child's name, label and bounds to learn
|
|
226
|
-
what it is; there is no second description of the form. */}
|
|
227
|
-
<DataViews.Filters
|
|
228
|
-
title={null}
|
|
229
|
-
className="border-b-0 p-0"
|
|
230
|
-
>
|
|
231
|
-
{/* One control per section type. Which one a field gets is decided by the data:
|
|
232
|
-
can the option set grow, and can the user pick more than one. */}
|
|
233
|
-
<FormBuilder.CheckboxGroup name="status" label="Status" options={STATUS_OPTIONS} />
|
|
234
|
-
<FormBuilder.RadioList name="priority" label="Priority" options={PRIORITY_OPTIONS} />
|
|
235
|
-
<FormBuilder.SearchableSelect
|
|
236
|
-
name="customer.name"
|
|
237
|
-
label="Customer"
|
|
238
|
-
options={CUSTOMER_OPTIONS}
|
|
239
|
-
/>
|
|
240
|
-
<FormBuilder.MultiSelect name="brand.name" label="Brand" options={BRAND_OPTIONS} />
|
|
241
|
-
<FormBuilder.Slider name="total" label="Total" range min={0} max={15000} step={100} />
|
|
242
|
-
<FormBuilder.DateRange name="createdAt" label="Created" />
|
|
243
|
-
</DataViews.Filters>
|
|
244
|
-
</DataViews.Panel.Tab>
|
|
245
|
-
</DataViews.Panel>
|
|
246
|
-
</DataViews>
|
|
247
|
-
</div>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
```
|