@tristan2828/ui-foundation 4.80.0 → 4.82.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 +104 -33
- package/conventions/docs/design-language.md +85 -36
- package/dist/components/app/editable-value.js +8 -10
- package/dist/components/app/empty-value.d.ts +5 -0
- package/dist/components/app/empty-value.js +11 -0
- package/dist/components/app/entity-view-print.d.ts +3 -1
- package/dist/components/app/entity-view-print.js +3 -2
- package/dist/components/app/entity-view.d.ts +43 -12
- package/dist/components/app/entity-view.js +45 -26
- package/dist/components/app/form-dialog.d.ts +29 -0
- package/dist/components/app/form-dialog.js +42 -0
- package/dist/components/app/icon-action.d.ts +14 -0
- package/dist/components/app/icon-action.js +7 -0
- package/dist/components/app/key-stats.d.ts +4 -1
- package/dist/components/app/key-stats.js +7 -2
- 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/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/lib/empty-value.d.ts +8 -0
- package/dist/lib/empty-value.js +13 -0
- package/package.json +1 -1
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`), `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
|
|
|
@@ -414,9 +415,12 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
414
415
|
plan's "View screen" section lists:
|
|
415
416
|
|
|
416
417
|
- **Title and badges.** The plan's title field is the page's `<h1>`.
|
|
417
|
-
Its badge fields sit
|
|
418
|
-
as its table cell. Edit (a `Button`
|
|
419
|
-
`/<entity>/:id/edit`) and the delete action go
|
|
418
|
+
Its badge fields sit on its line, after it (`badges`), each the same
|
|
419
|
+
`Badge` and variant map as its table cell. Edit (a `Button`
|
|
420
|
+
rendering a `Link` to `/<entity>/:id/edit`) and the delete action go
|
|
421
|
+
in `actions`, Delete as an `IconAction` (`icon={Trash2Icon}
|
|
422
|
+
label="Delete" tone="destructive"`, the dialog's trigger through
|
|
423
|
+
`render`).
|
|
420
424
|
- **The browser tab** reads the record's title once it loads
|
|
421
425
|
("Wireless Mouse · <app>"): `EntityView` sets it from `title`, and
|
|
422
426
|
puts the nav's ("Widgets · <app>") back while loading, on an error
|
|
@@ -471,9 +475,10 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
471
475
|
of linked records, a done-count, from the shared lookups in
|
|
472
476
|
`<entity>-format.ts`. Never re-derive one for the view.
|
|
473
477
|
- **An empty value is passed through as it is** (`null`, `''`, or
|
|
474
|
-
`list.length > 0 && …`), and `EntityView` shows
|
|
475
|
-
|
|
476
|
-
|
|
478
|
+
`list.length > 0 && …`), and `EntityView` shows a dash (read as "Not
|
|
479
|
+
set"), never a blank. A field's `emptyLabel` replaces it only where
|
|
480
|
+
words say more ("No budget yet"). A yes/no is never empty: it reads
|
|
481
|
+
Yes or No (cell pattern 12).
|
|
477
482
|
- **A reference links to the referenced record's view** when that
|
|
478
483
|
entity has one: the name, from the same lookup by id the table uses,
|
|
479
484
|
inside `<Link to={`/<other>/${id}`}>`. Without a view, the plain name
|
|
@@ -548,8 +553,8 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
548
553
|
(under the record, or under the page whose note it's in).
|
|
549
554
|
- **Notes worth taking on paper** (a visit's prep and questions, a
|
|
550
555
|
guide, a checklist to tick by hand): mark each of those sections
|
|
551
|
-
`print: true`. The header gets a Print notes
|
|
552
|
-
renames
|
|
556
|
+
`print: true`. The header gets a Print notes icon (`printLabel`
|
|
557
|
+
renames its tooltip and name) that prints the marked sections alone, under the title
|
|
553
558
|
and subtitle: no rail, no shell, no buttons, light paper in either
|
|
554
559
|
theme, headings and bullets as written, nothing folded, tables
|
|
555
560
|
ruled with room in their empty cells. `print: { answerSpace: true }`
|
|
@@ -877,6 +882,42 @@ the dialog.
|
|
|
877
882
|
{ path: '<parents>/:id/edit', element: <<Parent>FormRoute /> }, // a sibling, not a child
|
|
878
883
|
```
|
|
879
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
|
+
|
|
880
921
|
- **The row opens it**: a click on the row, Enter on it, ↑/↓ between
|
|
881
922
|
rows. So does a click on a link in the row to the record's own address
|
|
882
923
|
(the name cell can stay a plain `<Link>`), and in a card layout a click
|
|
@@ -926,8 +967,9 @@ view reaches them all. A record uses the parts it has, in this order:
|
|
|
926
967
|
at once) and other status-like fields as badges, edited in place. A
|
|
927
968
|
record with a face or a mark of its own (a person's avatar, a
|
|
928
969
|
service's logo, a cover) puts it left of all that (`leading`, 4.76).
|
|
929
|
-
`actions` holds
|
|
930
|
-
(
|
|
970
|
+
`actions` holds the record's own commands in words (Run, New visit),
|
|
971
|
+
then Delete (soft, with Undo) as an `IconAction`, never Edit. Print
|
|
972
|
+
notes is an icon of EntityView's own.
|
|
931
973
|
- **Strip**: the record's key numbers and ratings (`strip`, a
|
|
932
974
|
`KeyStats`), each edited in place where it's shown.
|
|
933
975
|
- **Sections**: with long text (notes, a body) `layout="rail"` and
|
|
@@ -943,15 +985,44 @@ view reaches them all. A record uses the parts it has, in this order:
|
|
|
943
985
|
`?tab=`. Fewer groups stay one scroll, folded by headings. A record's
|
|
944
986
|
Notes stay outside the tabs, above them, unless they are one tab's
|
|
945
987
|
content; the rail and the strip never go in a tab.
|
|
946
|
-
- **Rail fields beside their labels** (`railFields
|
|
947
|
-
a rail of
|
|
948
|
-
a column of labels; keep labels to a word or two.
|
|
988
|
+
- **Rail fields beside their labels** (`railFields`, `beside` by
|
|
989
|
+
default since 4.81), so a rail of short facts reads as a list of pairs
|
|
990
|
+
rather than a column of labels; keep labels to a word or two.
|
|
991
|
+
- **Empty fields folded** (`emptyFields="fold"`, 4.81): each card shows
|
|
992
|
+
what's known, then "N empty" opens the rest, still edited in place.
|
|
949
993
|
- **A big record's own parts** (a drawing, a player, a checklist of
|
|
950
994
|
documents) are sections in the view, not a screen of their own.
|
|
951
995
|
|
|
952
996
|
Edit and its form page stay only for a field the view can't edit in
|
|
953
997
|
place yet; the plan says which, and the gap is raised for the package.
|
|
954
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
|
+
|
|
955
1026
|
## What not to copy
|
|
956
1027
|
|
|
957
1028
|
- `widget-quick-actions.tsx`, its `quick action: …` specs and
|
|
@@ -3,35 +3,36 @@
|
|
|
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
|
-
- [Palettes](#palettes) · lines
|
|
7
|
-
- [Glow](#glow) · lines
|
|
8
|
-
- [Semantic tones](#semantic-tones) · lines
|
|
9
|
-
- [The three badge styles](#the-three-badge-styles) · lines
|
|
10
|
-
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines
|
|
11
|
-
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines
|
|
12
|
-
- [Logos and brand marks](#logos-and-brand-marks) · lines
|
|
13
|
-
- [Categorical colour](#categorical-colour) · lines
|
|
14
|
-
- [Heat scale](#heat-scale) · lines
|
|
15
|
-
- [Depth ramps](#depth-ramps) · lines
|
|
16
|
-
- [A stored colour](#a-stored-colour) · lines
|
|
17
|
-
- [Shapes and sizes](#shapes-and-sizes) · lines
|
|
18
|
-
- [Typography](#typography) · lines
|
|
19
|
-
- [Written text (notes)](#written-text-notes) · lines
|
|
20
|
-
- [Density](#density) · lines
|
|
21
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
22
|
-
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines
|
|
23
|
-
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines
|
|
24
|
-
- [Notices](#notices) · lines
|
|
25
|
-
- [A value over time](#a-value-over-time) · lines
|
|
26
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
27
|
-
- [A list as a board](#a-list-as-a-board) · lines
|
|
28
|
-
- [A list as cards](#a-list-as-cards) · lines
|
|
29
|
-
- [Key numbers on a record](#key-numbers-on-a-record) · lines
|
|
30
|
-
- [A record's
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [
|
|
34
|
-
- [
|
|
6
|
+
- [Palettes](#palettes) · lines 45–112
|
|
7
|
+
- [Glow](#glow) · lines 114–132
|
|
8
|
+
- [Semantic tones](#semantic-tones) · lines 134–162
|
|
9
|
+
- [The three badge styles](#the-three-badge-styles) · lines 164–181
|
|
10
|
+
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 183–212
|
|
11
|
+
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 214–227
|
|
12
|
+
- [Logos and brand marks](#logos-and-brand-marks) · lines 229–273
|
|
13
|
+
- [Categorical colour](#categorical-colour) · lines 275–345
|
|
14
|
+
- [Heat scale](#heat-scale) · lines 347–408
|
|
15
|
+
- [Depth ramps](#depth-ramps) · lines 410–488
|
|
16
|
+
- [A stored colour](#a-stored-colour) · lines 490–538
|
|
17
|
+
- [Shapes and sizes](#shapes-and-sizes) · lines 540–561
|
|
18
|
+
- [Typography](#typography) · lines 563–683
|
|
19
|
+
- [Written text (notes)](#written-text-notes) · lines 597–683
|
|
20
|
+
- [Density](#density) · lines 685–771
|
|
21
|
+
- [Rows on this device](#rows-on-this-device) · lines 744–771
|
|
22
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 773–887
|
|
23
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 889–966
|
|
24
|
+
- [Notices](#notices) · lines 968–996
|
|
25
|
+
- [A value over time](#a-value-over-time) · lines 998–1084
|
|
26
|
+
- [Several values over time](#several-values-over-time) · lines 1047–1084
|
|
27
|
+
- [A list as a board](#a-list-as-a-board) · lines 1086–1137
|
|
28
|
+
- [A list as cards](#a-list-as-cards) · lines 1139–1185
|
|
29
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1187–1216
|
|
30
|
+
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1218–1256
|
|
31
|
+
- [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1258–1303
|
|
32
|
+
- [Picking at random](#picking-at-random) · lines 1305–1336
|
|
33
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1338–1405
|
|
34
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1407–1432
|
|
35
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1434–1480
|
|
35
36
|
|
|
36
37
|
<!-- /index -->
|
|
37
38
|
|
|
@@ -1192,7 +1193,7 @@ row under the header, across the page at every width.
|
|
|
1192
1193
|
```tsx
|
|
1193
1194
|
<EntityView
|
|
1194
1195
|
subtitle={<EditableValue label="Goal" edit={goals} layout="inline">{goal}</EditableValue>}
|
|
1195
|
-
strip={<KeyStats stats={[{ label: 'Done', value: '7', hint: 'of 12' }, { label: 'Next step', value: formatPlainDate(next) }]} />}
|
|
1196
|
+
strip={<KeyStats stats={[{ label: 'Done', icon: HashIcon, value: '7', hint: 'of 12' }, { label: 'Next step', icon: CalendarClockIcon, value: formatPlainDate(next) }]} />}
|
|
1196
1197
|
… />
|
|
1197
1198
|
```
|
|
1198
1199
|
|
|
@@ -1200,24 +1201,71 @@ row under the header, across the page at every width.
|
|
|
1200
1201
|
value in the section title's size and tabular figures, a `hint`
|
|
1201
1202
|
under it in caption type. One bordered card, the figures side by side,
|
|
1202
1203
|
wrapping on a phone. A `<dl>`, so each label is read with its value.
|
|
1203
|
-
- **An
|
|
1204
|
-
|
|
1204
|
+
- **An icon with the word** (`icon`, 4.81): the concept's icon at 13px
|
|
1205
|
+
before the label, in the label's muted tone, one icon per meaning
|
|
1206
|
+
across the app (Lucide: a date `CalendarIcon`, next and review on
|
|
1207
|
+
`CalendarClockIcon`, when and length `ClockIcon`, a count `HashIcon`,
|
|
1208
|
+
status `CircleDotIcon`, price `DollarSignIcon`). The word stays; the
|
|
1209
|
+
icon is decorative. Never an icon alone in the strip.
|
|
1210
|
+
- **An empty value reads as a dash** (`emptyLabel`, 4.81; "Not set"
|
|
1211
|
+
before), in body type and muted, read by a screen reader as "Not set".
|
|
1212
|
+
Never a blank.
|
|
1205
1213
|
- **Three to five.** It's what the page is for at a glance; anything
|
|
1206
1214
|
more is a section's label/value rows.
|
|
1207
1215
|
- **`subtitle`** is the line under the title: what the record is for,
|
|
1208
1216
|
in muted body type, editable in place like any value.
|
|
1209
1217
|
|
|
1218
|
+
## A record's header and empty values
|
|
1219
|
+
|
|
1220
|
+
The record page standard (4.81): the same header on every record, the
|
|
1221
|
+
data on each its own.
|
|
1222
|
+
|
|
1223
|
+
```tsx
|
|
1224
|
+
<EntityView
|
|
1225
|
+
title={name}
|
|
1226
|
+
badges={<><StatusSelect … /><Badge variant="outline">Wholesale</Badge></>}
|
|
1227
|
+
subtitle={summary}
|
|
1228
|
+
actions={<><Button variant="outline"><PlusIcon />New order</Button><DeleteSupplier … /></>}
|
|
1229
|
+
emptyFields="fold"
|
|
1230
|
+
… />
|
|
1231
|
+
// Delete: <DialogTrigger render={<IconAction icon={Trash2Icon} label="Delete" tone="destructive" />} />
|
|
1232
|
+
```
|
|
1233
|
+
|
|
1234
|
+
- **The title's line**: the title, then the status and badges after it
|
|
1235
|
+
(12px apart, 6px between badges), centred on the title's line; a title
|
|
1236
|
+
too long for both pushes them to the next line, starting under it.
|
|
1237
|
+
`subtitle` is the line below, in muted body type.
|
|
1238
|
+
- **Actions**: the record's own commands in words (New visit, Mark
|
|
1239
|
+
done), then the universal ones as `IconAction`s: Print notes
|
|
1240
|
+
(`printer`, EntityView's own) and Delete (`trash-2`, the destructive
|
|
1241
|
+
tone). Each is a square outline button at the header's 36px with its
|
|
1242
|
+
words as both its tooltip and its accessible name. Icon alone is for
|
|
1243
|
+
the universal actions only (Delete, Print notes, Copy link, Pin, Open
|
|
1244
|
+
site, Restore, Open full page, Close, More); everything else keeps its
|
|
1245
|
+
word. `printLook="words"` keeps Print notes as a button with its words.
|
|
1246
|
+
- **An empty value** reads as a dash (`emptyText`, default `'—'`), in the
|
|
1247
|
+
muted text tone, read by a screen reader as "Not set": the same on
|
|
1248
|
+
every field, the presets' included. A field's own `emptyLabel` still
|
|
1249
|
+
wins where words say more than a dash ("No budget yet").
|
|
1250
|
+
- **Folded empties** (`emptyFields="fold"`): each fields card lists its
|
|
1251
|
+
filled fields, then a muted, underlined "N empty" with a down chevron
|
|
1252
|
+
under them opens the rest in their places, each still edited in place,
|
|
1253
|
+
and reads "Hide empty" (the chevron up) while open. A card with
|
|
1254
|
+
nothing empty has no toggle; one with nothing filled has the toggle
|
|
1255
|
+
alone. A value set elsewhere moves its field into the card at once.
|
|
1256
|
+
The fold is per card and isn't remembered.
|
|
1257
|
+
|
|
1210
1258
|
## A record's tabs, mark and rail
|
|
1211
1259
|
|
|
1212
|
-
Three
|
|
1213
|
-
|
|
1260
|
+
Three settings on `EntityView` (4.76): tabs and a mark, each for a
|
|
1261
|
+
record that needs it, and rail fields beside their labels, the default
|
|
1262
|
+
since 4.81.
|
|
1214
1263
|
|
|
1215
1264
|
```tsx
|
|
1216
1265
|
<EntityView
|
|
1217
1266
|
layout="rail"
|
|
1218
1267
|
mobileOrder="main-first"
|
|
1219
1268
|
leading={<img src={photo} alt="" className="size-12 rounded-full object-cover" />}
|
|
1220
|
-
railFields="beside"
|
|
1221
1269
|
sections={[
|
|
1222
1270
|
{ title: 'Summary', placement: 'rail', fields },
|
|
1223
1271
|
{ title: 'Notes', content: <Markdown>{notes}</Markdown> },
|
|
@@ -1247,7 +1295,8 @@ a record without them is as it was.
|
|
|
1247
1295
|
the title names the record (`alt=""`, `aria-hidden`); initials in
|
|
1248
1296
|
foreground on `bg-muted`, an icon in muted foreground on the card
|
|
1249
1297
|
with its border. "Logos and brand marks" above holds for a logo here.
|
|
1250
|
-
- **Rail fields beside** (`railFields
|
|
1298
|
+
- **Rail fields beside** (`railFields`, `beside` by default since 4.81;
|
|
1299
|
+
`stacked` puts each label above its value): the label in a 6 to
|
|
1251
1300
|
7rem column left of its value, baseline-aligned, rows a little tighter
|
|
1252
1301
|
than stacked. Where the rail's list is under 18rem (a phone narrower
|
|
1253
1302
|
than ~350px) it stacks as before, and once the rail stacks full width
|
|
@@ -23,7 +23,7 @@ import { useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, use
|
|
|
23
23
|
import { useBlocker } from 'react-router';
|
|
24
24
|
import { cn } from 'cn';
|
|
25
25
|
import { Button } from '../ui/button.js';
|
|
26
|
-
import {
|
|
26
|
+
import { DiscardChangesDialog } from '../ui/dialog.js';
|
|
27
27
|
import { FieldError } from '../ui/field.js';
|
|
28
28
|
import { Spinner } from '../ui/spinner.js';
|
|
29
29
|
import { EditInPlaceContext } from './edit-in-place.js';
|
|
@@ -278,16 +278,14 @@ export function LeaveGuard({ store }) {
|
|
|
278
278
|
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
279
279
|
};
|
|
280
280
|
}, [dirty, store]);
|
|
281
|
-
return (_jsx(
|
|
282
|
-
if (open)
|
|
283
|
-
return;
|
|
281
|
+
return (_jsx(DiscardChangesDialog, { open: blocker.state === 'blocked' && (!savesOnLeave || saveFailed), description: "A field you're editing hasn't been saved. Leaving now loses what you typed.", "data-leave-guard": "", onKeepEditing: () => {
|
|
284
282
|
setSaveFailed(false);
|
|
285
283
|
if (blocker.state === 'blocked')
|
|
286
284
|
blocker.reset();
|
|
287
|
-
},
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
}, onDiscard: () => {
|
|
286
|
+
store.discard();
|
|
287
|
+
setSaveFailed(false);
|
|
288
|
+
if (blocker.state === 'blocked')
|
|
289
|
+
blocker.proceed();
|
|
290
|
+
} }));
|
|
293
291
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// What an empty value reads as on a record (form standard 22.2, #F17): a
|
|
3
|
+
// dash in the muted text tone, everywhere, with "Not set" as what a screen
|
|
4
|
+
// reader says for it. Words given instead ("No budget yet") read as they
|
|
5
|
+
// are. EntityView, its strip (KeyStats) and the inPlace presets' fields all
|
|
6
|
+
// show it.
|
|
7
|
+
import { EMPTY_DASH } from '../../lib/empty-value.js';
|
|
8
|
+
/** The empty text in the muted tone; the dash is read as "Not set". */
|
|
9
|
+
export function EmptyText({ text = EMPTY_DASH, className }) {
|
|
10
|
+
return (_jsx("span", { "data-slot": "empty-value", className: className ?? 'text-muted-foreground', children: text === EMPTY_DASH ? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: EMPTY_DASH }), _jsx("span", { className: "sr-only", children: "Not set" })] })) : (text) }));
|
|
11
|
+
}
|
|
@@ -16,8 +16,10 @@ export type EntityViewPrintSection = {
|
|
|
16
16
|
* The copy mounts, then the browser's print dialog opens on it; it goes
|
|
17
17
|
* when the dialog closes (`afterprint`).
|
|
18
18
|
*/
|
|
19
|
-
export declare function PrintNotes({ label, title, subtitle, sections, }: {
|
|
19
|
+
export declare function PrintNotes({ label, look, title, subtitle, sections, }: {
|
|
20
20
|
label: string;
|
|
21
|
+
/** An icon with `label` as its tooltip and name (the default), or a button with its words. */
|
|
22
|
+
look?: 'icon' | 'words';
|
|
21
23
|
title?: string;
|
|
22
24
|
subtitle?: ReactNode;
|
|
23
25
|
sections: EntityViewPrintSection[];
|
|
@@ -19,6 +19,7 @@ import { useEffect, useState } from 'react';
|
|
|
19
19
|
import { createPortal } from 'react-dom';
|
|
20
20
|
import { PrinterIcon } from 'lucide-react';
|
|
21
21
|
import { Button } from '../ui/button.js';
|
|
22
|
+
import { IconAction } from './icon-action.js';
|
|
22
23
|
import { PrintingContext } from './print-context.js';
|
|
23
24
|
function isEmpty(value) {
|
|
24
25
|
return value === null || value === undefined || value === false || value === '' || (Array.isArray(value) && value.length === 0);
|
|
@@ -34,7 +35,7 @@ function PrintedNotes({ title, subtitle, sections }) {
|
|
|
34
35
|
* The copy mounts, then the browser's print dialog opens on it; it goes
|
|
35
36
|
* when the dialog closes (`afterprint`).
|
|
36
37
|
*/
|
|
37
|
-
export function PrintNotes({ label, title, subtitle, sections, }) {
|
|
38
|
+
export function PrintNotes({ label, look = 'icon', title, subtitle, sections, }) {
|
|
38
39
|
// How many times it's been pressed since the copy last went: a press
|
|
39
40
|
// while one is up (a browser that never said the dialog closed) prints
|
|
40
41
|
// it again rather than doing nothing.
|
|
@@ -47,5 +48,5 @@ export function PrintNotes({ label, title, subtitle, sections, }) {
|
|
|
47
48
|
window.print();
|
|
48
49
|
return () => window.removeEventListener('afterprint', done);
|
|
49
50
|
}, [printing]);
|
|
50
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Button, { variant: "outline", onClick: () => setPrinting((count) => count + 1), children: [_jsx(PrinterIcon, {}), label] }), printing > 0 && _jsx(PrintedNotes, { title: title, subtitle: subtitle, sections: sections })] }));
|
|
51
|
+
return (_jsxs(_Fragment, { children: [look === 'icon' ? (_jsx(IconAction, { icon: PrinterIcon, label: label, onClick: () => setPrinting((count) => count + 1) })) : (_jsxs(Button, { variant: "outline", onClick: () => setPrinting((count) => count + 1), children: [_jsx(PrinterIcon, {}), label] })), printing > 0 && _jsx(PrintedNotes, { title: title, subtitle: subtitle, sections: sections })] }));
|
|
51
52
|
}
|
|
@@ -9,7 +9,7 @@ export type EntityViewField = {
|
|
|
9
9
|
* so `{tags.map(...)}` or `{email}` can be passed as they are.
|
|
10
10
|
*/
|
|
11
11
|
value?: ReactNode;
|
|
12
|
-
/** What an empty value reads as
|
|
12
|
+
/** What an empty value reads as, for this field. Defaults to the view's `emptyText` (a dash). */
|
|
13
13
|
emptyLabel?: string;
|
|
14
14
|
/**
|
|
15
15
|
* Editable in place: `editInPlace({...})`, or a ready-made `inPlace`
|
|
@@ -86,6 +86,12 @@ export type EntityViewMobileOrder = 'rail-first' | 'main-first';
|
|
|
86
86
|
* where the rail's list is narrower than 18rem (a small phone).
|
|
87
87
|
*/
|
|
88
88
|
export type EntityViewRailFields = 'stacked' | 'beside';
|
|
89
|
+
/**
|
|
90
|
+
* What a fields card does with its empty fields: `show` (the default),
|
|
91
|
+
* each with the empty text; `fold`, the filled ones first and an
|
|
92
|
+
* "N empty" toggle that opens the rest, still edited in place.
|
|
93
|
+
*/
|
|
94
|
+
export type EntityViewEmptyFields = 'show' | 'fold';
|
|
89
95
|
export type EntityViewProps = {
|
|
90
96
|
/** The record's name or title, the page's <h1>, and the browser tab's once it loads (`documentTitle`). */
|
|
91
97
|
title?: string;
|
|
@@ -115,12 +121,17 @@ export type EntityViewProps = {
|
|
|
115
121
|
*/
|
|
116
122
|
subtitle?: ReactNode;
|
|
117
123
|
/**
|
|
118
|
-
* A few status-like values
|
|
119
|
-
* control that changes one when the plan makes it a quick
|
|
120
|
-
* status `Select`, a yes/no `Switch`).
|
|
124
|
+
* A few status-like values on the title's line, after it, as `<Badge>`s,
|
|
125
|
+
* or as the control that changes one when the plan makes it a quick
|
|
126
|
+
* action (a status `Select`, a yes/no `Switch`). A title too long for
|
|
127
|
+
* them on its line pushes them to the next; `subtitle` stays below.
|
|
121
128
|
*/
|
|
122
129
|
badges?: ReactNode;
|
|
123
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* The header's actions: the record's own commands in words (New visit,
|
|
132
|
+
* Mark done), then the universal ones as an `<IconAction>` (Delete, with
|
|
133
|
+
* its confirm dialog, `tone="destructive"`). They follow Print notes.
|
|
134
|
+
*/
|
|
124
135
|
actions?: ReactNode;
|
|
125
136
|
/**
|
|
126
137
|
* A state that decides what you do with the record, said before
|
|
@@ -152,18 +163,38 @@ export type EntityViewProps = {
|
|
|
152
163
|
* ignores it.
|
|
153
164
|
*/
|
|
154
165
|
mobileOrder?: EntityViewMobileOrder;
|
|
155
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* The Print notes action's words, when a section is marked `print`: its
|
|
168
|
+
* tooltip and accessible name as an icon, its text as `words`. Defaults
|
|
169
|
+
* to "Print notes".
|
|
170
|
+
*/
|
|
156
171
|
printLabel?: string;
|
|
172
|
+
/** Print notes as an icon (`icon`, the default since 4.81) or a button with its words (`words`). */
|
|
173
|
+
printLook?: 'icon' | 'words';
|
|
157
174
|
/** The rail's landmark name (its `<aside>`). Defaults to the title + " details". */
|
|
158
175
|
railLabel?: string;
|
|
159
176
|
/**
|
|
160
|
-
* In the `rail` layout, a rail section's fields: each label
|
|
161
|
-
* value (`
|
|
162
|
-
*
|
|
163
|
-
* sections stack full width on a narrower
|
|
164
|
-
* values either way.
|
|
177
|
+
* In the `rail` layout, a rail section's fields: each label to the left
|
|
178
|
+
* of its value (`beside`, the default since 4.81), falling back to
|
|
179
|
+
* stacked where the rail is too narrow for both, or above it
|
|
180
|
+
* (`stacked`). Once the rail's sections stack full width on a narrower
|
|
181
|
+
* screen, labels sit beside values either way.
|
|
165
182
|
*/
|
|
166
183
|
railFields?: EntityViewRailFields;
|
|
184
|
+
/**
|
|
185
|
+
* Empty fields in a fields card (the rail's and the main column's):
|
|
186
|
+
* shown with the empty text (`show`, the default), or folded (`fold`):
|
|
187
|
+
* the card lists its filled fields, then "N empty" opens the rest in
|
|
188
|
+
* their places, each still edited in place. A value set elsewhere moves
|
|
189
|
+
* its field into the card.
|
|
190
|
+
*/
|
|
191
|
+
emptyFields?: EntityViewEmptyFields;
|
|
192
|
+
/**
|
|
193
|
+
* What an empty value reads as across the view (a field's or a block's
|
|
194
|
+
* own `emptyLabel` wins): a dash by default, in the muted tone, read
|
|
195
|
+
* by a screen reader as "Not set".
|
|
196
|
+
*/
|
|
197
|
+
emptyText?: string;
|
|
167
198
|
isLoading: boolean;
|
|
168
199
|
/** A `notfound` error (including another user's record) shows "Not found" and a way back, never a retry. */
|
|
169
200
|
error?: AppError | null;
|
|
@@ -174,4 +205,4 @@ export type EntityViewProps = {
|
|
|
174
205
|
label: string;
|
|
175
206
|
};
|
|
176
207
|
};
|
|
177
|
-
export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, mobileOrder, railLabel, railFields, printLabel, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|
|
208
|
+
export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|