@tristan2828/ui-foundation 4.80.0 → 4.81.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 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` |
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` |
@@ -4,25 +4,25 @@
4
4
  ## Index
5
5
 
6
6
  - [The reference files](#the-reference-files) · lines 41–63
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–802
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–806
8
8
  - Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
9
9
  - Step 2: `npm run gen:api` · lines 115–116
10
10
  - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
11
11
  - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
12
12
  - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–689
14
- - Step 7: Register routes · lines 690–705
15
- - Step 8: Add Playwright specs for all three screens · lines 706–784
16
- - Step 9: Register the nav entry and route names · lines 785–799
17
- - Step 10: `npm run verify`. · lines 800–802
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 804–953
19
- - [The record view](#the-record-view) · lines 917–953
20
- - [What not to copy](#what-not-to-copy) · lines 955–981
21
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 983–1000
22
- - [Deleting](#deleting) · lines 1002–1031
23
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1033–1054
24
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1056–1065
25
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1068–1107
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–693
14
+ - Step 7: Register routes · lines 694–709
15
+ - Step 8: Add Playwright specs for all three screens · lines 710–788
16
+ - Step 9: Register the nav entry and route names · lines 789–803
17
+ - Step 10: `npm run verify`. · lines 804–806
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 808–960
19
+ - [The record view](#the-record-view) · lines 921–960
20
+ - [What not to copy](#what-not-to-copy) · lines 962–988
21
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 990–1007
22
+ - [Deleting](#deleting) · lines 1009–1038
23
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1040–1061
24
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1063–1072
25
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1075–1114
26
26
 
27
27
  <!-- /index -->
28
28
 
@@ -414,9 +414,12 @@ is a filled-in example while the Widgets demo is still here).
414
414
  plan's "View screen" section lists:
415
415
 
416
416
  - **Title and badges.** The plan's title field is the page's `<h1>`.
417
- Its badge fields sit beside it, each the same `Badge` and variant map
418
- as its table cell. Edit (a `Button` rendering a `Link` to
419
- `/<entity>/:id/edit`) and the delete action go in `actions`.
417
+ Its badge fields sit on its line, after it (`badges`), each the same
418
+ `Badge` and variant map as its table cell. Edit (a `Button`
419
+ rendering a `Link` to `/<entity>/:id/edit`) and the delete action go
420
+ in `actions`, Delete as an `IconAction` (`icon={Trash2Icon}
421
+ label="Delete" tone="destructive"`, the dialog's trigger through
422
+ `render`).
420
423
  - **The browser tab** reads the record's title once it loads
421
424
  ("Wireless Mouse · <app>"): `EntityView` sets it from `title`, and
422
425
  puts the nav's ("Widgets · <app>") back while loading, on an error
@@ -471,9 +474,10 @@ is a filled-in example while the Widgets demo is still here).
471
474
  of linked records, a done-count, from the shared lookups in
472
475
  `<entity>-format.ts`. Never re-derive one for the view.
473
476
  - **An empty value is passed through as it is** (`null`, `''`, or
474
- `list.length > 0 && …`), and `EntityView` shows the field's
475
- `emptyLabel`, the plan's "not set" label, never a blank. A yes/no is
476
- never empty: it reads Yes or No (cell pattern 12).
477
+ `list.length > 0 && …`), and `EntityView` shows a dash (read as "Not
478
+ set"), never a blank. A field's `emptyLabel` replaces it only where
479
+ words say more ("No budget yet"). A yes/no is never empty: it reads
480
+ Yes or No (cell pattern 12).
477
481
  - **A reference links to the referenced record's view** when that
478
482
  entity has one: the name, from the same lookup by id the table uses,
479
483
  inside `<Link to={`/<other>/${id}`}>`. Without a view, the plain name
@@ -548,8 +552,8 @@ is a filled-in example while the Widgets demo is still here).
548
552
  (under the record, or under the page whose note it's in).
549
553
  - **Notes worth taking on paper** (a visit's prep and questions, a
550
554
  guide, a checklist to tick by hand): mark each of those sections
551
- `print: true`. The header gets a Print notes button (`printLabel`
552
- renames it) that prints the marked sections alone, under the title
555
+ `print: true`. The header gets a Print notes icon (`printLabel`
556
+ renames its tooltip and name) that prints the marked sections alone, under the title
553
557
  and subtitle: no rail, no shell, no buttons, light paper in either
554
558
  theme, headings and bullets as written, nothing folded, tables
555
559
  ruled with room in their empty cells. `print: { answerSpace: true }`
@@ -926,8 +930,9 @@ view reaches them all. A record uses the parts it has, in this order:
926
930
  at once) and other status-like fields as badges, edited in place. A
927
931
  record with a face or a mark of its own (a person's avatar, a
928
932
  service's logo, a cover) puts it left of all that (`leading`, 4.76).
929
- `actions` holds Delete (soft, with Undo) and the record's own commands
930
- (Run, Print), never Edit.
933
+ `actions` holds the record's own commands in words (Run, New visit),
934
+ then Delete (soft, with Undo) as an `IconAction`, never Edit. Print
935
+ notes is an icon of EntityView's own.
931
936
  - **Strip**: the record's key numbers and ratings (`strip`, a
932
937
  `KeyStats`), each edited in place where it's shown.
933
938
  - **Sections**: with long text (notes, a body) `layout="rail"` and
@@ -943,9 +948,11 @@ view reaches them all. A record uses the parts it has, in this order:
943
948
  `?tab=`. Fewer groups stay one scroll, folded by headings. A record's
944
949
  Notes stay outside the tabs, above them, unless they are one tab's
945
950
  content; the rail and the strip never go in a tab.
946
- - **Rail fields beside their labels** (`railFields="beside"`, 4.76) for
947
- a rail of many short facts, so it reads as a list of pairs rather than
948
- a column of labels; keep labels to a word or two.
951
+ - **Rail fields beside their labels** (`railFields`, `beside` by
952
+ default since 4.81), so a rail of short facts reads as a list of pairs
953
+ rather than a column of labels; keep labels to a word or two.
954
+ - **Empty fields folded** (`emptyFields="fold"`, 4.81): each card shows
955
+ what's known, then "N empty" opens the rest, still edited in place.
949
956
  - **A big record's own parts** (a drawing, a player, a checklist of
950
957
  documents) are sections in the view, not a screen of their own.
951
958
 
@@ -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 44–111
7
- - [Glow](#glow) · lines 113–131
8
- - [Semantic tones](#semantic-tones) · lines 133–161
9
- - [The three badge styles](#the-three-badge-styles) · lines 163–180
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 182–211
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 213–226
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 228–272
13
- - [Categorical colour](#categorical-colour) · lines 274–344
14
- - [Heat scale](#heat-scale) · lines 346–407
15
- - [Depth ramps](#depth-ramps) · lines 409–487
16
- - [A stored colour](#a-stored-colour) · lines 489–537
17
- - [Shapes and sizes](#shapes-and-sizes) · lines 539–560
18
- - [Typography](#typography) · lines 562–682
19
- - [Written text (notes)](#written-text-notes) · lines 596–682
20
- - [Density](#density) · lines 684–770
21
- - [Rows on this device](#rows-on-this-device) · lines 743–770
22
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 772–886
23
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 888–965
24
- - [Notices](#notices) · lines 967–995
25
- - [A value over time](#a-value-over-time) · lines 997–1083
26
- - [Several values over time](#several-values-over-time) · lines 1046–1083
27
- - [A list as a board](#a-list-as-a-board) · lines 1085–1136
28
- - [A list as cards](#a-list-as-cards) · lines 1138–1184
29
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1186–1208
30
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1210–1254
31
- - [Picking at random](#picking-at-random) · lines 1256–1287
32
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1289–1356
33
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1358–1383
34
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1385–1431
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 empty value reads as `emptyLabel`** ("Not set"), in body type and
1204
- muted, never a blank or a dash.
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 opt-ins on `EntityView` (4.76), each for a record that needs it;
1213
- a record without them is as it was.
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="beside"`): the label in a 6 to
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
@@ -0,0 +1,5 @@
1
+ /** The empty text in the muted tone; the dash is read as "Not set". */
2
+ export declare function EmptyText({ text, className }: {
3
+ text?: string;
4
+ className?: string;
5
+ }): import("react").JSX.Element;
@@ -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: the plan's "not set" label. Defaults to "Not set". */
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 beside the title, as `<Badge>`s, or as the
119
- * control that changes one when the plan makes it a quick action (a
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
- /** The header's actions: an Edit button, a Delete with its confirm dialog. */
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
- /** The Print notes button's words, when a section is marked `print`. Defaults to "Print notes". */
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 above its
161
- * value (`stacked`, the default), or to its left (`beside`), falling back
162
- * to stacked where the rail is too narrow for both. Once the rail's
163
- * sections stack full width on a narrower screen, labels sit beside
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;
@@ -67,13 +67,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
67
67
  // switch. With no `tab` on any section, nothing changes.
68
68
  //
69
69
  // `leading`, left of the title: the record's mark or avatar, with the
70
- // title, subtitle and badges beside it at every width. `railFields`
71
- // `beside` puts a rail field's label to the left of its value, as in an
72
- // issue tracker's sidebar, stacked again where the rail's list is too
73
- // narrow for both.
74
- import { useEffect, useId, useState, useSyncExternalStore } from 'react';
70
+ // title, subtitle and badges beside it at every width. A rail field's
71
+ // label sits to the left of its value (`railFields`, `beside` by default
72
+ // since 4.81), as in an issue tracker's sidebar, stacked again where the
73
+ // rail's list is too narrow for both.
74
+ //
75
+ // The record page standard (4.81): `badges` sit on the title's line,
76
+ // wrapping under a long title; Print notes is an icon (`IconAction`, its
77
+ // words the tooltip and name); an empty value reads as a dash
78
+ // (`emptyText`), and `emptyFields="fold"` folds each fields card's empty
79
+ // ones behind an "N empty" toggle, still edited in place once opened.
80
+ import { createContext, useContext, useEffect, useId, useState, useSyncExternalStore } from 'react';
75
81
  import { Link, useLocation, useNavigate } from 'react-router';
76
- import { ArrowLeftIcon, SearchXIcon } from 'lucide-react';
82
+ import { ArrowLeftIcon, ChevronDownIcon, SearchXIcon } from 'lucide-react';
77
83
  import { cn } from 'cn';
78
84
  import { ErrorState } from './error-state.js';
79
85
  import { Button } from '../ui/button.js';
@@ -87,22 +93,22 @@ import { EditInPlaceContext } from './edit-in-place.js';
87
93
  import { EditInPlaceStore } from './edit-in-place-store.js';
88
94
  import { EditableList } from './editable-list.js';
89
95
  import { EditableValue, LeaveGuard } from './editable-value.js';
96
+ import { EmptyText } from './empty-value.js';
97
+ import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
90
98
  import { useRecordDialog } from './record-dialog-context.js';
91
99
  import { entityViewTabSlug } from '../../lib/entity-view-tab.js';
92
- const DEFAULT_EMPTY_LABEL = 'Not set';
93
- function isEmptyValue(value) {
94
- return (value === null ||
95
- value === undefined ||
96
- value === false ||
97
- value === '' ||
98
- (Array.isArray(value) && value.length === 0));
99
- }
100
+ // The view's empty text and whether fields cards fold their empty ones,
101
+ // for every section without threading them through each layout.
102
+ const EmptyContext = createContext({ text: EMPTY_DASH, fold: false });
100
103
  function BackLink({ back }) {
101
104
  return (_jsxs(Link, { to: back.to, className: "inline-flex w-fit items-center gap-1 rounded-sm type-label text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50", children: [_jsx(ArrowLeftIcon, { "aria-hidden": "true", className: "size-4" }), back.label] }));
102
105
  }
103
- function orEmptyLabel(value, emptyLabel) {
104
- return isEmptyValue(value) ? (_jsx("span", { className: "text-muted-foreground", children: emptyLabel ?? DEFAULT_EMPTY_LABEL })) : (value);
106
+ function OrEmpty({ value, emptyLabel }) {
107
+ const empty = useContext(EmptyContext);
108
+ return isEmptyValue(value) ? _jsx(EmptyText, { text: emptyLabel ?? empty.text }) : value;
105
109
  }
110
+ // A preset shows its own value unless the screen gives one.
111
+ const fieldValue = (field) => (field.value !== undefined ? field.value : field.edit?.shown);
106
112
  // Label beside value from `sm` up; below it (a phone) the label sits
107
113
  // above its value, so nothing is squeezed into a narrow second column. In
108
114
  // the rail the list's own width decides instead (a container query on the
@@ -117,13 +123,26 @@ const FIELD_ROW = {
117
123
  railBeside: '@2xs/fields:grid @2xs/fields:grid-cols-[minmax(--spacing(24),--spacing(28))_minmax(0,1fr)] @2xs/fields:items-baseline @2xs/fields:gap-4 @2xs/fields:py-2.5 @lg/fields:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] @lg/fields:gap-6',
118
124
  };
119
125
  function FieldRow({ field, place }) {
120
- // A preset shows its own value unless the screen gives one.
121
- const value = field.value !== undefined ? field.value : field.edit?.shown;
122
- return (_jsxs("div", { className: cn('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[place]), children: [_jsx("dt", { className: "type-label text-muted-foreground", children: field.label }), _jsx("dd", { className: "min-w-0 type-body break-words text-foreground", children: field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, children: orEmptyLabel(value, field.emptyLabel) })) : (orEmptyLabel(value, field.emptyLabel)) })] }));
126
+ const value = fieldValue(field);
127
+ return (_jsxs("div", { className: cn('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[place]), children: [_jsx("dt", { className: "type-label text-muted-foreground", children: field.label }), _jsx("dd", { className: "min-w-0 type-body break-words text-foreground", children: field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, children: _jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }) })) : (_jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel })) })] }));
128
+ }
129
+ // A fields card's rows. Folded (`emptyFields="fold"`), the filled fields
130
+ // show and the empty ones wait behind "N empty", which opens them in their
131
+ // places (the card's order kept) and then reads "Hide empty". Whether a
132
+ // field is empty is read on every render, so one filled elsewhere joins
133
+ // the card at once.
134
+ function FieldList({ fields, inRail, place }) {
135
+ const empty = useContext(EmptyContext);
136
+ const [open, setOpen] = useState(false);
137
+ const listId = useId();
138
+ const emptyCount = empty.fold ? fields.filter((field) => isEmptyValue(fieldValue(field))).length : 0;
139
+ const shown = emptyCount === 0 || open ? fields : fields.filter((field) => !isEmptyValue(fieldValue(field)));
140
+ return (_jsxs("div", { className: "flex flex-col gap-3", children: [shown.length > 0 && (_jsx("dl", { id: listId, className: cn('flex flex-col divide-y divide-border', inRail && '@container/fields'), children: shown.map((field) => (_jsx(FieldRow, { field: field, place: place }, field.label))) })), emptyCount > 0 && (_jsxs("button", { type: "button", "data-slot": "entity-view-empty-toggle", "aria-expanded": open, "aria-controls": shown.length > 0 ? listId : undefined, onClick: () => setOpen((was) => !was), className: "inline-flex w-fit items-center gap-1 rounded-sm type-label text-muted-foreground underline underline-offset-3 outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 pointer-coarse:min-h-11", children: [open ? 'Hide empty' : `${emptyCount} empty`, _jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('size-3.5 transition-transform', open && 'rotate-180') })] }))] }));
123
141
  }
124
- function ViewSection({ section, inRail = false, railFields = 'stacked', }) {
142
+ function ViewSection({ section, inRail = false, railFields = 'beside', }) {
125
143
  const headingId = useId();
126
- return (_jsx("section", { "aria-labelledby": headingId, children: _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx("h2", { id: headingId, className: "type-section-title text-foreground", children: section.title }) }), _jsx(CardContent, { children: 'fields' in section ? (_jsx("dl", { className: cn('flex flex-col divide-y divide-border', inRail && '@container/fields'), children: section.fields.map((field) => (_jsx(FieldRow, { field: field, place: !inRail ? 'page' : railFields === 'beside' ? 'railBeside' : 'rail' }, field.label))) })) : section.edit?.kind === 'list' ? (_jsxs("div", { className: "flex min-w-0 flex-col gap-2 type-body break-words text-foreground", children: [!isEmptyValue(section.content) && section.content, _jsx(EditableList, { label: section.title, edit: section.edit, emptyLabel: section.emptyLabel ?? DEFAULT_EMPTY_LABEL })] })) : (_jsx("div", { className: "min-w-0 type-body break-words text-foreground", children: section.edit ? (_jsx(EditableValue, { label: section.title, edit: section.edit, children: orEmptyLabel(section.content, section.emptyLabel) })) : (orEmptyLabel(section.content, section.emptyLabel)) })) })] }) }));
144
+ const empty = useContext(EmptyContext);
145
+ return (_jsx("section", { "aria-labelledby": headingId, children: _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx("h2", { id: headingId, className: "type-section-title text-foreground", children: section.title }) }), _jsx(CardContent, { children: 'fields' in section ? (_jsx(FieldList, { fields: section.fields, inRail: inRail, place: !inRail ? 'page' : railFields === 'beside' ? 'railBeside' : 'rail' })) : section.edit?.kind === 'list' ? (_jsxs("div", { className: "flex min-w-0 flex-col gap-2 type-body break-words text-foreground", children: [!isEmptyValue(section.content) && section.content, _jsx(EditableList, { label: section.title, edit: section.edit, emptyLabel: section.emptyLabel ?? empty.text })] })) : (_jsx("div", { className: "min-w-0 type-body break-words text-foreground", children: section.edit ? (_jsx(EditableValue, { label: section.title, edit: section.edit, children: _jsx(OrEmpty, { value: section.content, emptyLabel: section.emptyLabel }) })) : (_jsx(OrEmpty, { value: section.content, emptyLabel: section.emptyLabel })) })) })] }) }));
127
146
  }
128
147
  // The rail layout's columns. The view is a container, so the switch to
129
148
  // two columns follows the width the page actually has (the sidebar open
@@ -220,7 +239,7 @@ function MainTabs({ tabs, label }) {
220
239
  };
221
240
  return (_jsxs(Tabs, { value: selected, onValueChange: (value) => select(String(value)), "data-slot": "entity-view-tabs", className: "min-w-0 gap-6", children: [_jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-1 overflow-x-auto overflow-y-hidden border-b border-border p-0 [scrollbar-width:thin]", children: tabs.map((tab) => (_jsx(TabsTrigger, { value: tab.slug, className: "h-9 flex-none px-3 text-muted-foreground group-data-horizontal/tabs:after:bottom-0 pointer-coarse:h-11 dark:text-muted-foreground", children: tab.name }, tab.slug))) }), tabs.map((tab) => (_jsx(TabsContent, { value: tab.slug, keepMounted: true, className: "flex min-w-0 flex-col gap-6 [font-size:inherit]", children: tab.sections.map((section) => (_jsx(ViewSection, { section: section }, section.title))) }, tab.slug)))] }));
222
241
  }
223
- export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'column', mobileOrder = 'rail-first', railLabel, railFields = 'stacked', printLabel = 'Print notes', isLoading, error, onRetry, back, }) {
242
+ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'column', mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
224
243
  // Editing in place: one store per view, and the leave-page prompt only
225
244
  // while a field is open (or one is always editable).
226
245
  const [store] = useState(() => new EditInPlaceStore());
@@ -252,7 +271,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
252
271
  : { content: section.content, emptyLabel: section.emptyLabel }),
253
272
  answerSpace: typeof section.print === 'object' && section.print.answerSpace === true,
254
273
  }));
255
- const printButton = printSections.length > 0 && (_jsx(PrintNotes, { label: printLabel, title: title, subtitle: subtitle, sections: printSections }));
274
+ const printButton = printSections.length > 0 && (_jsx(PrintNotes, { label: printLabel, look: printLook, title: title, subtitle: subtitle, sections: printSections }));
256
275
  const railSections = sections.filter((section) => section.placement === 'rail');
257
276
  const mainSections = sections.filter((section) => section.placement !== 'rail');
258
277
  // Tabs: a main section's `tab` (a rail one's is ignored, in either layout).
@@ -262,7 +281,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
262
281
  const main = (_jsxs("div", { className: cn(RAIL_LAYOUT.main, railSections.length === 0 && RAIL_LAYOUT.mainAlone), children: [mainSections
263
282
  .filter((section) => !tabbed(section))
264
283
  .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
265
- return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsxs("div", { className: layout === 'rail' ? RAIL_LAYOUT.page : 'flex max-w-4xl flex-col gap-6', "data-state": "success", "data-layout": layout, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && _jsx(BackLink, { back: back }), _jsxs("header", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { className: "flex min-w-0 flex-1 items-start gap-3 sm:min-w-64 sm:gap-4", children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsx("h1", { id: dialog?.titleId, className: "type-page-title break-words text-foreground", children: titleEdit ? (_jsx(EditableValue, { label: titleEdit.label, edit: titleEdit, layout: "inline", className: "w-full", children: title })) : (title) }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle })), badges && _jsx("div", { className: "flex flex-wrap items-center gap-1.5", children: badges })] })] }), (actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] }))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), layout === 'rail' ? (_jsxs("div", { className: RAIL_LAYOUT.columns, children: [mobileOrder === 'main-first' && main, railSections.length > 0 && (_jsx(Rail, { label: railLabel ?? `${title ?? 'Record'} details`, sections: railSections, fields: railFields })), mobileOrder === 'rail-first' && main] })) : (_jsxs(_Fragment, { children: [sections
266
- .filter((section) => !tabbed(section))
267
- .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] })), footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }));
284
+ return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsxs("div", { className: layout === 'rail' ? RAIL_LAYOUT.page : 'flex max-w-4xl flex-col gap-6', "data-state": "success", "data-layout": layout, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && _jsx(BackLink, { back: back }), _jsxs("header", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { className: "flex min-w-0 flex-1 items-start gap-3 sm:min-w-64 sm:gap-4", children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: "min-w-0 max-w-full type-page-title break-words text-foreground", children: titleEdit ? (_jsx(EditableValue, { label: titleEdit.label, edit: titleEdit, layout: "inline", className: "w-full", children: title })) : (title) }), badges && (_jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), (actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] }))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), layout === 'rail' ? (_jsxs("div", { className: RAIL_LAYOUT.columns, children: [mobileOrder === 'main-first' && main, railSections.length > 0 && (_jsx(Rail, { label: railLabel ?? `${title ?? 'Record'} details`, sections: railSections, fields: railFields })), mobileOrder === 'rail-first' && main] })) : (_jsxs(_Fragment, { children: [sections
285
+ .filter((section) => !tabbed(section))
286
+ .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] })), footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }) }));
268
287
  }
@@ -0,0 +1,14 @@
1
+ import type { ComponentProps } from 'react';
2
+ import { Button } from '../ui/button.js';
3
+ import type { IconComponent } from './icon-component.js';
4
+ export type IconActionProps = Omit<ComponentProps<typeof Button>, 'children' | 'size' | 'aria-label'> & {
5
+ /** The action's icon, from the app's icon vocabulary (Lucide `Trash2Icon` for Delete). */
6
+ icon: IconComponent;
7
+ /** What the action does ("Delete", "Print notes"): its tooltip and accessible name. */
8
+ label: string;
9
+ /** `destructive` draws the icon in the destructive tone (Delete). Defaults to `default`. */
10
+ tone?: 'default' | 'destructive';
11
+ /** The button's size: `default` (36px, beside the header's other buttons) or `sm` (32px). */
12
+ size?: 'default' | 'sm';
13
+ };
14
+ export declare function IconAction({ icon: Icon, label, tone, size, variant, className, ...props }: IconActionProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from 'cn';
3
+ import { Button } from '../ui/button.js';
4
+ import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip.js';
5
+ export function IconAction({ icon: Icon, label, tone = 'default', size = 'default', variant = 'outline', className, ...props }) {
6
+ return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ...props, "data-slot": "icon-action", variant: variant, size: size === 'sm' ? 'icon-sm' : 'icon', "aria-label": label, className: className }), children: _jsx(Icon, { "aria-hidden": "true", className: cn('size-4', tone === 'destructive' && 'text-destructive-text') }) }), _jsx(TooltipContent, { children: label })] }));
7
+ }
@@ -1,13 +1,16 @@
1
1
  import type { ReactNode } from 'react';
2
+ import type { IconComponent } from './icon-component.js';
2
3
  export type KeyStat = {
3
4
  label: string;
4
5
  value: ReactNode;
5
6
  /** A few words under the value ("of 12", "since May"), in caption type. */
6
7
  hint?: ReactNode;
8
+ /** The concept's icon, drawn at 13px before the label (decorative: the label still says it). */
9
+ icon?: IconComponent;
7
10
  };
8
11
  export type KeyStatsProps = {
9
12
  stats: readonly KeyStat[];
10
- /** What an empty value reads as. Defaults to "Not set". */
13
+ /** What an empty value reads as. Defaults to a dash, read as "Not set". */
11
14
  emptyLabel?: string;
12
15
  className?: string;
13
16
  };
@@ -1,6 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn } from 'cn';
3
+ import { EmptyText } from './empty-value.js';
4
+ import { EMPTY_DASH } from '../../lib/empty-value.js';
3
5
  const isEmpty = (value) => value === null || value === undefined || value === false || value === '';
4
- export function KeyStats({ stats, emptyLabel = 'Not set', className }) {
5
- return (_jsx("dl", { "data-slot": "key-stats", className: cn('flex flex-wrap gap-x-8 gap-y-3 rounded-lg border border-border bg-card px-4 py-3 text-card-foreground', className), children: stats.map((stat) => (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("dt", { className: "type-caption text-muted-foreground", children: stat.label }), _jsx("dd", { className: "type-section-title tabular-nums break-words text-foreground", children: isEmpty(stat.value) ? _jsx("span", { className: "type-body text-muted-foreground", children: emptyLabel }) : stat.value }), stat.hint && _jsx("dd", { className: "type-caption text-muted-foreground", children: stat.hint })] }, stat.label))) }));
6
+ export function KeyStats({ stats, emptyLabel = EMPTY_DASH, className }) {
7
+ return (_jsx("dl", { "data-slot": "key-stats", className: cn('flex flex-wrap gap-x-8 gap-y-3 rounded-lg border border-border bg-card px-4 py-3 text-card-foreground', className), children: stats.map((stat) => {
8
+ const Icon = stat.icon;
9
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsxs("dt", { className: cn('type-caption text-muted-foreground', Icon && 'inline-flex items-center gap-1'), children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-3.25 shrink-0" }), stat.label] }), _jsx("dd", { className: "type-section-title tabular-nums break-words text-foreground", children: isEmpty(stat.value) ? _jsx(EmptyText, { text: emptyLabel, className: "type-body text-muted-foreground" }) : stat.value }), stat.hint && _jsx("dd", { className: "type-caption text-muted-foreground", children: stat.hint })] }, stat.label));
10
+ }) }));
6
11
  }
package/dist/index.d.ts CHANGED
@@ -14,7 +14,8 @@ export { type RowGroup } from './components/app/table-groups.js';
14
14
  export { byDay, type ByDayOptions } from './lib/group-by-day.js';
15
15
  export { EntityForm, type EntityFormProps } from './components/app/entity-form.js';
16
16
  export { KeyStats, type KeyStat, type KeyStatsProps } from './components/app/key-stats.js';
17
- export { EntityView, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
17
+ export { IconAction, type IconActionProps } from './components/app/icon-action.js';
18
+ export { EntityView, type EntityViewEmptyFields, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
18
19
  export { entityViewTabSlug } from './lib/entity-view-tab.js';
19
20
  export { usePrinting } from './components/app/print-context.js';
20
21
  export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ export {} from './components/app/table-groups.js';
18
18
  export { byDay } from './lib/group-by-day.js';
19
19
  export { EntityForm } from './components/app/entity-form.js';
20
20
  export { KeyStats } from './components/app/key-stats.js';
21
+ export { IconAction } from './components/app/icon-action.js';
21
22
  export { EntityView, } from './components/app/entity-view.js';
22
23
  export { entityViewTabSlug } from './lib/entity-view-tab.js';
23
24
  export { usePrinting } from './components/app/print-context.js';
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ /** The default empty text: an em dash, spoken as "Not set". */
3
+ export declare const EMPTY_DASH = "\u2014";
4
+ /**
5
+ * Whether a value counts as empty: `null`, `undefined`, `false`, `''` and
6
+ * an empty array, so `{tags.map(...)}` or `{email}` can be passed as is.
7
+ */
8
+ export declare function isEmptyValue(value: ReactNode): boolean;
@@ -0,0 +1,13 @@
1
+ /** The default empty text: an em dash, spoken as "Not set". */
2
+ export const EMPTY_DASH = '—';
3
+ /**
4
+ * Whether a value counts as empty: `null`, `undefined`, `false`, `''` and
5
+ * an empty array, so `{tags.map(...)}` or `{email}` can be passed as is.
6
+ */
7
+ export function isEmptyValue(value) {
8
+ return (value === null ||
9
+ value === undefined ||
10
+ value === false ||
11
+ value === '' ||
12
+ (Array.isArray(value) && value.length === 0));
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.80.0",
3
+ "version": "4.81.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {