@tristan2828/ui-foundation 4.81.0 → 4.83.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 +1 -1
- package/conventions/docs/add-an-entity.md +88 -24
- package/conventions/docs/cell-patterns.md +111 -50
- package/conventions/docs/entity-plan-template.md +3 -3
- package/dist/components/app/data-table.d.ts +36 -8
- package/dist/components/app/data-table.js +142 -90
- package/dist/components/app/editable-value.js +8 -10
- package/dist/components/app/form-dialog.d.ts +29 -0
- package/dist/components/app/form-dialog.js +42 -0
- package/dist/components/app/record-dialog-context.d.ts +17 -0
- package/dist/components/app/record-dialog-context.js +10 -0
- package/dist/components/app/record-dialog.d.ts +9 -2
- package/dist/components/app/record-dialog.js +36 -9
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/dialog.d.ts +32 -3
- package/dist/components/ui/dialog.js +63 -6
- package/dist/hooks/use-table-url-state.d.ts +19 -1
- package/dist/hooks/use-table-url-state.js +31 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/styles/theme.css +6 -0
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ than installing this by hand:
|
|
|
18
18
|
|
|
19
19
|
| Import | What |
|
|
20
20
|
|---|---|
|
|
21
|
-
| `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState` |
|
|
21
|
+
| `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
|
|
22
22
|
| `@tristan2828/ui-foundation/ui/<name>` | shadcn primitives: badge, button, calendar, card, checkbox, combobox, dialog, empty, field, input, input-group, label, popover, select, separator, sheet, sidebar, skeleton, sonner, spinner, switch, table, textarea, tooltip |
|
|
23
23
|
| `@tristan2828/ui-foundation/gateway` | `safeFetch`, `toAppError`, `networkError` — for an app's `src/api/gateway/` only |
|
|
24
24
|
| `@tristan2828/ui-foundation/mocks` | MSW: `authHandlers`, `environmentHandlers`, `resetMockAuth`, `getMockCurrentUser`, `MOCK_USER`, `exposeMswForE2E` |
|
|
@@ -3,26 +3,27 @@
|
|
|
3
3
|
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
4
|
## Index
|
|
5
5
|
|
|
6
|
-
- [The reference files](#the-reference-files) · lines
|
|
7
|
-
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines
|
|
8
|
-
- Step 1: Add `<Entity>` to `openapi.yaml` · lines
|
|
9
|
-
- Step 2: `npm run gen:api` · lines
|
|
10
|
-
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines
|
|
11
|
-
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines
|
|
12
|
-
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines
|
|
13
|
-
- Step 6: Copy the reference files, one for one, not just the two screens · lines
|
|
14
|
-
- Step 7: Register routes · lines
|
|
15
|
-
- Step 8: Add Playwright specs for all three screens · lines
|
|
16
|
-
- Step 9: Register the nav entry and route names · lines
|
|
17
|
-
- Step 10: `npm run verify`. · lines
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines
|
|
19
|
-
- [The record view](#the-record-view) · lines
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
6
|
+
- [The reference files](#the-reference-files) · lines 42–64
|
|
7
|
+
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 66–807
|
|
8
|
+
- Step 1: Add `<Entity>` to `openapi.yaml` · lines 108–115
|
|
9
|
+
- Step 2: `npm run gen:api` · lines 116–117
|
|
10
|
+
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 118–129
|
|
11
|
+
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 130–139
|
|
12
|
+
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 140–144
|
|
13
|
+
- Step 6: Copy the reference files, one for one, not just the two screens · lines 145–694
|
|
14
|
+
- Step 7: Register routes · lines 695–710
|
|
15
|
+
- Step 8: Add Playwright specs for all three screens · lines 711–789
|
|
16
|
+
- Step 9: Register the nav entry and route names · lines 790–804
|
|
17
|
+
- Step 10: `npm run verify`. · lines 805–807
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 809–1024
|
|
19
|
+
- [The record view](#the-record-view) · lines 958–997
|
|
20
|
+
- [Dialogs](#dialogs) · lines 999–1024
|
|
21
|
+
- [What not to copy](#what-not-to-copy) · lines 1026–1052
|
|
22
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1054–1071
|
|
23
|
+
- [Deleting](#deleting) · lines 1073–1102
|
|
24
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1104–1125
|
|
25
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1127–1136
|
|
26
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1139–1178
|
|
26
27
|
|
|
27
28
|
<!-- /index -->
|
|
28
29
|
|
|
@@ -97,8 +98,8 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
97
98
|
cell pattern 18, "In a table's rows": each field's cell an
|
|
98
99
|
`EditableValue` over the shared control from `<entity>-fields.tsx` and
|
|
99
100
|
`useEdit<Entity>Field`, `InlineCreate` in the toolbar for create, a
|
|
100
|
-
delete row action with its confirm dialog, and `width="
|
|
101
|
-
plan's List screen says so. There's no reference file in the template
|
|
101
|
+
delete row action with its confirm dialog, and `width="full"` only if
|
|
102
|
+
the plan's List screen says so. There's no reference file in the template
|
|
102
103
|
for this shape; the pattern's code is the reference. Its specs: each
|
|
103
104
|
cell kind saves, a refusal stays in its cell, one cell at a time, the
|
|
104
105
|
leave prompt, create (Enter, a blank name, a taken one), delete, and
|
|
@@ -881,6 +882,42 @@ the dialog.
|
|
|
881
882
|
{ path: '<parents>/:id/edit', element: <<Parent>FormRoute /> }, // a sibling, not a child
|
|
882
883
|
```
|
|
883
884
|
|
|
885
|
+
**A new record over its list** (4.82), for a create form of up to about
|
|
886
|
+
8 fields (a longer one is its own page, `<entity>/new` beside the list as
|
|
887
|
+
above): the list's `new` child route, named by `newPath`, is a
|
|
888
|
+
`FormDialog` over the list, from the list's New button
|
|
889
|
+
(`<RecordLink to="/<entity>/new">` or `useOpenRecord()`) and from a deep
|
|
890
|
+
link alike. Closing goes back to the list as a record's dialog does, and
|
|
891
|
+
after the save `useNewRecordDialog().openRecord(to)` opens the new record
|
|
892
|
+
over the same list, in the form's history entry.
|
|
893
|
+
|
|
894
|
+
```tsx
|
|
895
|
+
{
|
|
896
|
+
path: '<entity>',
|
|
897
|
+
element: <RecordDialogRoute list={<<Entity>sTableRoute />} label="<Entity>" newPath="new" />,
|
|
898
|
+
children: [
|
|
899
|
+
{ path: 'new', element: <New<Entity>Route /> },
|
|
900
|
+
{ path: ':id', element: <<Entity>ViewRoute /> },
|
|
901
|
+
],
|
|
902
|
+
},
|
|
903
|
+
|
|
904
|
+
// New<Entity>Route: the form's own fields and react-hook-form, in FormDialog (no `open`).
|
|
905
|
+
const created = useNewRecordDialog()
|
|
906
|
+
<FormDialog
|
|
907
|
+
title="New <entity>"
|
|
908
|
+
submitLabel="Add <entity>"
|
|
909
|
+
onSubmit={form.handleSubmit(async (values) => {
|
|
910
|
+
const saved = await create.mutateAsync(values)
|
|
911
|
+
created?.openRecord(`/<entity>/${saved.id}`)
|
|
912
|
+
})}
|
|
913
|
+
isSubmitting={create.isPending}
|
|
914
|
+
submitError={create.error}
|
|
915
|
+
dirty={form.formState.isDirty}
|
|
916
|
+
>
|
|
917
|
+
…fields…
|
|
918
|
+
</FormDialog>
|
|
919
|
+
```
|
|
920
|
+
|
|
884
921
|
- **The row opens it**: a click on the row, Enter on it, ↑/↓ between
|
|
885
922
|
rows. So does a click on a link in the row to the record's own address
|
|
886
923
|
(the name cell can stay a plain `<Link>`), and in a card layout a click
|
|
@@ -959,6 +996,33 @@ view reaches them all. A record uses the parts it has, in this order:
|
|
|
959
996
|
Edit and its form page stay only for a field the view can't edit in
|
|
960
997
|
place yet; the plan says which, and the gap is raised for the package.
|
|
961
998
|
|
|
999
|
+
### Dialogs
|
|
1000
|
+
|
|
1001
|
+
Every dialog is one of three widths, `DialogContent`'s `size` (4.82):
|
|
1002
|
+
|
|
1003
|
+
| `size` | Width | On a phone (under 48rem) | Use it for |
|
|
1004
|
+
| --- | --- | --- | --- |
|
|
1005
|
+
| `confirm` | 420px | a sheet from the bottom, the buttons full width, the action above Cancel | a question with two answers: a delete, "Discard your changes?" |
|
|
1006
|
+
| `form` | 640px | the whole screen, the title and buttons pinned | a small form (`FormDialog`, which is this size) |
|
|
1007
|
+
| `record` | 1,120px | full width, the rail under the main column | a record over its list (`RecordDialogRoute`, which is this size) |
|
|
1008
|
+
|
|
1009
|
+
- **Never a width of its own** (`sm:max-w-…` on `DialogContent`). A
|
|
1010
|
+
confirm's buttons go in `DialogFooter`, Cancel first, so the phone's
|
|
1011
|
+
sheet stacks the action on top.
|
|
1012
|
+
- **A dialog with something typed asks before it closes**:
|
|
1013
|
+
`DialogContent dirty` (react-hook-form's `formState.isDirty`) makes Esc,
|
|
1014
|
+
✕, a click outside and Cancel ask "Discard your changes?" first;
|
|
1015
|
+
nothing typed, nothing asked. Closing it from code after a save
|
|
1016
|
+
(`open={false}`) never asks. `DiscardChangesDialog` is that prompt on
|
|
1017
|
+
its own, for any other way of leaving with something unsaved.
|
|
1018
|
+
- **A form in a dialog is a `FormDialog`**: the title, the fields
|
|
1019
|
+
scrolling between it and the pinned Cancel and Add, a failed save as a
|
|
1020
|
+
destructive `Notice` above the buttons with Try again, and `dirty`.
|
|
1021
|
+
Opened from a page with `open`/`onOpenChange`; as a list's `new` route
|
|
1022
|
+
with neither (above).
|
|
1023
|
+
- **Always a dialog, never a side panel**, except a phone's filters
|
|
1024
|
+
(a bottom sheet of controls for the list behind it).
|
|
1025
|
+
|
|
962
1026
|
## What not to copy
|
|
963
1027
|
|
|
964
1028
|
- `widget-quick-actions.tsx`, its `quick action: …` specs and
|
|
@@ -970,8 +1034,8 @@ place yet; the plan says which, and the gap is raised for the package.
|
|
|
970
1034
|
the in-place a11y block unless the plan has an `Edit in place` line,
|
|
971
1035
|
and then only for the fields it names.
|
|
972
1036
|
|
|
973
|
-
- `width="
|
|
974
|
-
`Width:
|
|
1037
|
+
- `width="full"` on `DataTable` unless the plan's List screen says
|
|
1038
|
+
`Width: full` (`content`, the default, is right for almost every list).
|
|
975
1039
|
- The saved-views row in `widgets-table.tsx` (`VIEWS`, the "Saved views"
|
|
976
1040
|
button group and `visibleColumns`) unless the plan's List screen lists
|
|
977
1041
|
saved views. When it does, copy it: `useTableUrlState`'s third argument
|
|
@@ -3,42 +3,43 @@
|
|
|
3
3
|
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
4
|
## Index
|
|
5
5
|
|
|
6
|
-
- [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines
|
|
7
|
-
- [1. Plain text](#1-plain-text) · lines
|
|
8
|
-
- [2. Icon + label](#2-icon--label) · lines
|
|
9
|
-
- [3. Icon in a badge](#3-icon-in-a-badge) · lines
|
|
10
|
-
- [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines
|
|
11
|
-
- [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines
|
|
12
|
-
- [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines
|
|
13
|
-
- [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines
|
|
14
|
-
- [7. Link as an outline button](#7-link-as-an-outline-button) · lines
|
|
15
|
-
- [8. Date, relative](#8-date-relative) · lines
|
|
16
|
-
- [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines
|
|
17
|
-
- [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines
|
|
18
|
-
- [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines
|
|
19
|
-
- [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines
|
|
20
|
-
- [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines
|
|
21
|
-
- [12. Boolean](#12-boolean) · lines
|
|
22
|
-
- [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines
|
|
23
|
-
- [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines
|
|
24
|
-
- [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines
|
|
25
|
-
- [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines
|
|
26
|
-
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines
|
|
27
|
-
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines
|
|
28
|
-
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines
|
|
30
|
-
- [Presets: one line per field](#presets-one-line-per-field) · lines
|
|
31
|
-
- [Several fields edited as one](#several-fields-edited-as-one) · lines
|
|
32
|
-
- [A link and its label](#a-link-and-its-label) · lines
|
|
33
|
-
- [A list of sub-items](#a-list-of-sub-items) · lines
|
|
34
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
35
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
36
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
37
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
38
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
39
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
40
|
-
- [
|
|
41
|
-
- [
|
|
6
|
+
- [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 71–90
|
|
7
|
+
- [1. Plain text](#1-plain-text) · lines 92–145
|
|
8
|
+
- [2. Icon + label](#2-icon--label) · lines 147–170
|
|
9
|
+
- [3. Icon in a badge](#3-icon-in-a-badge) · lines 172–185
|
|
10
|
+
- [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 187–264
|
|
11
|
+
- [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines 212–264
|
|
12
|
+
- [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 266–279
|
|
13
|
+
- [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 281–293
|
|
14
|
+
- [7. Link as an outline button](#7-link-as-an-outline-button) · lines 295–316
|
|
15
|
+
- [8. Date, relative](#8-date-relative) · lines 318–355
|
|
16
|
+
- [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 357–405
|
|
17
|
+
- [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 375–405
|
|
18
|
+
- [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 407–457
|
|
19
|
+
- [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 425–457
|
|
20
|
+
- [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 459–499
|
|
21
|
+
- [12. Boolean](#12-boolean) · lines 501–531
|
|
22
|
+
- [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 533–569
|
|
23
|
+
- [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 553–569
|
|
24
|
+
- [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 571–588
|
|
25
|
+
- [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 590–699
|
|
26
|
+
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 616–699
|
|
27
|
+
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 701–736
|
|
28
|
+
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 738–811
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 813–1456
|
|
30
|
+
- [Presets: one line per field](#presets-one-line-per-field) · lines 1098–1156
|
|
31
|
+
- [Several fields edited as one](#several-fields-edited-as-one) · lines 1158–1194
|
|
32
|
+
- [A link and its label](#a-link-and-its-label) · lines 1196–1220
|
|
33
|
+
- [A list of sub-items](#a-list-of-sub-items) · lines 1222–1355
|
|
34
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1357–1442
|
|
35
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1444–1456
|
|
36
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1458–1524
|
|
37
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1526–1590
|
|
38
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1592–1690
|
|
39
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1692–1721
|
|
40
|
+
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1723–1761
|
|
41
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1763–1839
|
|
42
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1841–1864
|
|
42
43
|
|
|
43
44
|
<!-- /index -->
|
|
44
45
|
|
|
@@ -126,6 +127,23 @@ cell, a card's line or a caption with `<Markdown inline>`, not the block
|
|
|
126
127
|
- It's for one line. Long text is notes, the block `<Markdown>` on the
|
|
127
128
|
record's view.
|
|
128
129
|
|
|
130
|
+
**Long text in a list's column: `meta.clip`.** A column whose values run
|
|
131
|
+
long (a description, a note, a path) is cut to one line, so one long value
|
|
132
|
+
can't make the whole table thousands of pixels wide:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
{ id: 'notes', header: 'Notes', meta: { clip: true }, cell: ({ row }) => row.original.notes }
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- One line, cut at `meta.maxWidth` (`'24rem'` unless set, and never over
|
|
139
|
+
60% of the table's area, so a phone keeps room for the name) with an
|
|
140
|
+
ellipsis.
|
|
141
|
+
- The whole text shows in a tooltip on hover and on focus: a cell that's
|
|
142
|
+
actually cut takes a tab stop, one that fits takes none. A screen reader
|
|
143
|
+
reads the whole text either way, and the record shows it too.
|
|
144
|
+
- `meta.maxWidth` alone caps the column and lets its text wrap, for a
|
|
145
|
+
value worth reading whole in the row.
|
|
146
|
+
|
|
129
147
|
## 2. Icon + label
|
|
130
148
|
|
|
131
149
|
A single-value enum where a glyph speeds up scanning but the word still
|
|
@@ -1376,7 +1394,7 @@ column and no edit route.
|
|
|
1376
1394
|
(`schema`), and a refusal (a taken name's 422) shows under the box.
|
|
1377
1395
|
- **Delete** stays a row action: a trash button in a pinned last column
|
|
1378
1396
|
(`pinLastColumn`), with its confirm dialog.
|
|
1379
|
-
- **
|
|
1397
|
+
- **Width:** the default, `width="content"` (below), keeps the row's cells
|
|
1380
1398
|
and its delete together on a wide screen.
|
|
1381
1399
|
|
|
1382
1400
|
```tsx
|
|
@@ -1425,15 +1443,17 @@ entity yet.
|
|
|
1425
1443
|
|
|
1426
1444
|
### A table of a few short columns: `width="content"`
|
|
1427
1445
|
|
|
1428
|
-
On a wide screen a table of
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1446
|
+
On a wide screen a table of a few short columns (a name, a colour, a
|
|
1447
|
+
count, its delete) spread across the page puts the row's actions far
|
|
1448
|
+
from its name. `width="content"`, the default since 4.83 (it was an
|
|
1449
|
+
opt-in from 80rem), sizes the table and its pagination to its columns at
|
|
1450
|
+
every width, never under 36rem (or the whole width, when that's less),
|
|
1451
|
+
with empty space at the right; the toolbar keeps the whole width, so its
|
|
1452
|
+
controls sit in the same place on every list. A table wider than its
|
|
1453
|
+
area scrolls sideways inside it. While it's loading, empty or failed
|
|
1454
|
+
after a load, it keeps the width it last had, so paging and filtering
|
|
1455
|
+
don't move it; only the first load can. `width="full"` takes the whole
|
|
1456
|
+
width, the look before 4.83; a card layout always does.
|
|
1437
1457
|
|
|
1438
1458
|
## 19. Stage circle for an ordered status
|
|
1439
1459
|
|
|
@@ -1678,10 +1698,11 @@ current one. `DataTable`'s `highlightRow` returns true for it.
|
|
|
1678
1698
|
<DataTable highlightRow={(book) => book.id === nextUpId} … />
|
|
1679
1699
|
```
|
|
1680
1700
|
|
|
1681
|
-
- **A wash of info on every cell**, over
|
|
1682
|
-
columns' opaque backgrounds (`--table-highlight`, pre-mixed onto
|
|
1683
|
-
page), and a bar in `info-text` at the row's start, so it reads
|
|
1684
|
-
colour too.
|
|
1701
|
+
- **A wash of info on every cell**, over a stripe (`striped`) and the
|
|
1702
|
+
pinned columns' opaque backgrounds (`--table-highlight`, pre-mixed onto
|
|
1703
|
+
the page), and a bar in `info-text` at the row's start, so it reads
|
|
1704
|
+
without colour too. The pointer's hover (pattern 24) leaves it as it
|
|
1705
|
+
is, so "next up" never reads as the hovered row. Still **say why in the row** (a "Next up" word or badge):
|
|
1685
1706
|
the wash says "look here", not what it is.
|
|
1686
1707
|
- **Muted text inside it is darkened for you.** `muted-foreground`
|
|
1687
1708
|
measures 4.09:1 on the wash, under 4.5:1, and no lighter wash fixes it
|
|
@@ -1699,6 +1720,46 @@ current one. `DataTable`'s `highlightRow` returns true for it.
|
|
|
1699
1720
|
the token check in both themes; `e2e/data-table.spec.ts` checks every
|
|
1700
1721
|
cell wears the wash.
|
|
1701
1722
|
|
|
1723
|
+
## 24. A list's rows: hover, lines, rows per page
|
|
1724
|
+
|
|
1725
|
+
What every `DataTable` does by default since 4.83 (the list page
|
|
1726
|
+
standard), and the two choices it leaves an app.
|
|
1727
|
+
|
|
1728
|
+
- **The row under the pointer** lights whole: every cell, pinned ones
|
|
1729
|
+
included, in `--table-hover` (the muted fill, solid), with a 3px bar in
|
|
1730
|
+
`--primary` on its first cell. Muted text inside it takes the darker
|
|
1731
|
+
grey a highlighted row's does (4.34:1 would be under 4.5 in light). A
|
|
1732
|
+
row that opens a record (`opens` with a dialog, a page or the panel, or
|
|
1733
|
+
`onRowClick`) takes the hand cursor; a row edited in place
|
|
1734
|
+
(`opens={{ kind: 'rows' }}`) gets the same highlight and keeps the
|
|
1735
|
+
arrow. A highlighted row (pattern 22) and the panel's picked row keep
|
|
1736
|
+
their own look.
|
|
1737
|
+
- **No zebra stripes:** rows are told apart by the line under each.
|
|
1738
|
+
`striped` brings the stripes back for an app that wants them. Tables in
|
|
1739
|
+
notes keep theirs (4.67.1).
|
|
1740
|
+
- **Rows per page:** a menu in the pagination bar, from
|
|
1741
|
+
`useTableUrlState`, which keeps the pick in the URL (`?size=`) and on
|
|
1742
|
+
this device:
|
|
1743
|
+
|
|
1744
|
+
```tsx
|
|
1745
|
+
const { page, setPage, pageSize, pageSizes, setPageSize } = useTableUrlState(FILTERS, MULTI, VIEWS, {
|
|
1746
|
+
pageSizeStorageKey: 'my-app:recipes:page-size', // defaults: pageSizes [25, 50, 100], defaultPageSize 50
|
|
1747
|
+
})
|
|
1748
|
+
const query = useRecipes({ page, pageSize, ... })
|
|
1749
|
+
<DataTable page={page} pageSize={pageSize} onPageChange={setPage}
|
|
1750
|
+
pageSizes={pageSizes} onPageSizeChange={setPageSize} … />
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
A pick returns to page 1. A size in the URL or storage that isn't one
|
|
1754
|
+
of `pageSizes` is ignored, so `?size=100000` can't ask the server for
|
|
1755
|
+
everything. Without `pageSizes` and `onPageSizeChange` the bar has no
|
|
1756
|
+
menu, as before.
|
|
1757
|
+
- The fixtures' `app/DataTable` ListLook, ListLookInRows and
|
|
1758
|
+
ListLookStriped stories hold all of it (with a `meta.clip` Notes
|
|
1759
|
+
column, pattern 1), under axe and the token check in both themes;
|
|
1760
|
+
`e2e/data-table.spec.ts` "list look" checks the hover on every cell,
|
|
1761
|
+
the cursors, the stripes, the tooltip, the widths and the menu.
|
|
1762
|
+
|
|
1702
1763
|
## 23. A Group menu, and a record read beside the list
|
|
1703
1764
|
|
|
1704
1765
|
A working list (tasks, chores, a backlog) is read two ways besides its
|
|
@@ -143,9 +143,9 @@ per list; delete the section if there are none.
|
|
|
143
143
|
| All tasks | none | dueDate asc | |
|
|
144
144
|
| Bugs | kind = bug | dueDate asc | title, severity, assignee, dueDate |
|
|
145
145
|
|
|
146
|
-
- Width (optional): `
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
- Width (optional): `full` for a table that should take the whole page.
|
|
147
|
+
Leave it out for the default, as wide as the columns need (cell pattern
|
|
148
|
+
18, "`width="content"`").
|
|
149
149
|
- Anything else the table must show or do:
|
|
150
150
|
|
|
151
151
|
## View screen
|
|
@@ -12,6 +12,18 @@ export type SortingState = {
|
|
|
12
12
|
declare module '@tanstack/table-core' {
|
|
13
13
|
interface ColumnMeta<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
|
|
14
14
|
align?: 'center' | 'right';
|
|
15
|
+
/**
|
|
16
|
+
* Long text on one line (DataTable): cut at `maxWidth` with an ellipsis,
|
|
17
|
+
* the whole text in a tooltip on hover and on focus (a cut cell takes a
|
|
18
|
+
* tab stop, so the keyboard reaches it too). Screen readers read it whole.
|
|
19
|
+
*/
|
|
20
|
+
clip?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The widest the column's content gets, as a CSS length: `'24rem'`
|
|
23
|
+
* unless set, with `clip` (and never over 60% of the table's area, for
|
|
24
|
+
* a phone). Without `clip`, the content wraps at it.
|
|
25
|
+
*/
|
|
26
|
+
maxWidth?: string;
|
|
15
27
|
}
|
|
16
28
|
}
|
|
17
29
|
export type DataTableProps<TData extends Record<string, unknown>> = {
|
|
@@ -22,6 +34,14 @@ export type DataTableProps<TData extends Record<string, unknown>> = {
|
|
|
22
34
|
page: number;
|
|
23
35
|
pageSize: number;
|
|
24
36
|
onPageChange: (page: number) => void;
|
|
37
|
+
/**
|
|
38
|
+
* The rows-per-page choices (`[25, 50, 100]`), drawn as a menu in the
|
|
39
|
+
* pagination bar with `onPageSizeChange`: useTableUrlState's `pageSizes`,
|
|
40
|
+
* `pageSize` and `setPageSize`, which keep the pick in the URL and on this
|
|
41
|
+
* device (`pageSizeStorageKey`). Left out, the bar has no menu.
|
|
42
|
+
*/
|
|
43
|
+
pageSizes?: readonly number[];
|
|
44
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
25
45
|
sorting: SortingState;
|
|
26
46
|
onSortingChange: (sorting: SortingState) => void;
|
|
27
47
|
isLoading: boolean;
|
|
@@ -65,15 +85,23 @@ export type DataTableProps<TData extends Record<string, unknown>> = {
|
|
|
65
85
|
*/
|
|
66
86
|
visibleColumns?: readonly string[];
|
|
67
87
|
/**
|
|
68
|
-
* `
|
|
69
|
-
* the
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
88
|
+
* `content` (the default, 4.83): the table and its pagination are as wide
|
|
89
|
+
* as the columns need, at least 36rem (or the whole width, when that's
|
|
90
|
+
* less), with empty space at the right, so a name stays close to its
|
|
91
|
+
* values at any screen size; wider than the area, the table scrolls
|
|
92
|
+
* sideways in it. The toolbar keeps the whole width, so its controls
|
|
93
|
+
* don't move between lists. While loading, empty or failed after a
|
|
94
|
+
* load, it keeps the width it last had, so paging and filtering don't
|
|
95
|
+
* move it (only the first load can). `full`: the table takes the whole
|
|
96
|
+
* width too (the default before 4.83). A card layout takes the whole
|
|
97
|
+
* width either way.
|
|
75
98
|
*/
|
|
76
99
|
width?: DataTableWidth;
|
|
100
|
+
/**
|
|
101
|
+
* Zebra stripes on the body rows (every other row tinted), as before
|
|
102
|
+
* 4.83. Off by default: rows are told apart by the line under each.
|
|
103
|
+
*/
|
|
104
|
+
striped?: boolean;
|
|
77
105
|
/**
|
|
78
106
|
* Rows under headings: each row's group (`byDay(field)` for a feed or a
|
|
79
107
|
* log). Rows keep the server's order, and a heading row spanning every
|
|
@@ -294,4 +322,4 @@ export type DataTableTotals = {
|
|
|
294
322
|
*/
|
|
295
323
|
cells?: Partial<Record<string, ReactNode>>;
|
|
296
324
|
};
|
|
297
|
-
export declare function DataTable<TData extends Record<string, unknown>>({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, }: DataTableProps<TData>): import("react").JSX.Element;
|
|
325
|
+
export declare function DataTable<TData extends Record<string, unknown>>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, }: DataTableProps<TData>): import("react").JSX.Element;
|