@tristan2828/ui-foundation 4.92.0 → 4.94.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/conventions/docs/add-an-entity.md +24 -12
- package/conventions/docs/cell-patterns.md +21 -17
- package/conventions/docs/design-language.md +122 -33
- package/dist/components/app/editable-value.js +6 -1
- package/dist/components/app/entity-view.js +3 -15
- package/dist/components/app/equal-items.d.ts +102 -0
- package/dist/components/app/equal-items.js +156 -0
- package/dist/components/app/field-rows.d.ts +11 -0
- package/dist/components/app/field-rows.js +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
- Step 8: Add Playwright specs for all three screens · lines 736–814
|
|
16
16
|
- Step 9: Register the nav entry and route names · lines 815–829
|
|
17
17
|
- Step 10: `npm run verify`. · lines 830–832
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines 834–
|
|
19
|
-
- [The record view](#the-record-view) · lines 983–
|
|
20
|
-
- [Forms](#forms) · lines
|
|
21
|
-
- [Dialogs](#dialogs) · lines
|
|
22
|
-
- [Toasts and feedback](#toasts-and-feedback) · lines
|
|
23
|
-
- [What not to copy](#what-not-to-copy) · lines
|
|
24
|
-
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines
|
|
25
|
-
- [Deleting](#deleting) · lines
|
|
26
|
-
- [Fields only a script writes](#fields-only-a-script-writes) · lines
|
|
27
|
-
- [Searching one part of the app](#searching-one-part-of-the-app) · lines
|
|
28
|
-
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 834–1153
|
|
19
|
+
- [The record view](#the-record-view) · lines 983–1031
|
|
20
|
+
- [Forms](#forms) · lines 1033–1085
|
|
21
|
+
- [Dialogs](#dialogs) · lines 1087–1112
|
|
22
|
+
- [Toasts and feedback](#toasts-and-feedback) · lines 1114–1153
|
|
23
|
+
- [What not to copy](#what-not-to-copy) · lines 1155–1181
|
|
24
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1183–1200
|
|
25
|
+
- [Deleting](#deleting) · lines 1202–1233
|
|
26
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1235–1256
|
|
27
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1258–1267
|
|
28
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1270–1312
|
|
29
29
|
|
|
30
30
|
<!-- /index -->
|
|
31
31
|
|
|
@@ -1015,6 +1015,15 @@ view reaches them all. A record uses the parts it has, in this order:
|
|
|
1015
1015
|
rather than a column of labels; keep labels to a word or two.
|
|
1016
1016
|
- **Empty fields folded** (`emptyFields="fold"`, 4.81): each card shows
|
|
1017
1017
|
what's known, then "N empty" opens the rest, still edited in place.
|
|
1018
|
+
- **A few equal things** (a plan's phases, a price at each store, a
|
|
1019
|
+
handful of options) are one `EqualItems` (4.93) in a section, one look
|
|
1020
|
+
per set: `cards` for little to say about each, `table` for things
|
|
1021
|
+
compared on the same values, `featured` when one is current or best,
|
|
1022
|
+
`panels` when each has several details (design-language.md "A few
|
|
1023
|
+
equal things"). Never hand-made cards or a grid of their own. An item
|
|
1024
|
+
edited or removed on its own carries its editor as `content` and its
|
|
1025
|
+
Edit and Remove as `actions` (4.94), `wide` while the editor is open;
|
|
1026
|
+
never an editor put in a field's value.
|
|
1018
1027
|
- **A big record's own parts** (a drawing, a player, a checklist of
|
|
1019
1028
|
documents) are sections in the view, not a screen of their own.
|
|
1020
1029
|
|
|
@@ -1273,7 +1282,10 @@ Four more things an app sets for AI chats (4.71), each in
|
|
|
1273
1282
|
must be found exactly once (missing, or found twice, is a refusal that
|
|
1274
1283
|
says so and saves nothing), or `append` adds text on a new line at the
|
|
1275
1284
|
end. It saves and logs as `update` does, so a long note isn't sent back
|
|
1276
|
-
whole to change a line.
|
|
1285
|
+
whole to change a line. A table's widths comment (design-language.md
|
|
1286
|
+
"Written text (notes)") is hidden from every read answer and kept
|
|
1287
|
+
in what's stored, so an edit never drops it (4.94); `search` leaves
|
|
1288
|
+
out a record whose only match is inside it. Each must be a text field of `update_schema`
|
|
1277
1289
|
and not `script_only`; the backend refuses to start otherwise.
|
|
1278
1290
|
- **The server's instructions** a chat gets when it connects:
|
|
1279
1291
|
`register_entities(ENTITIES, instructions="…")` (or
|
|
@@ -26,22 +26,22 @@
|
|
|
26
26
|
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 618–701
|
|
27
27
|
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 703–738
|
|
28
28
|
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 740–813
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines 815–
|
|
30
|
-
- [Presets: one line per field](#presets-one-line-per-field) · lines
|
|
31
|
-
- [Several fields edited as one](#several-fields-edited-as-one) · lines
|
|
32
|
-
- [A link and its label](#a-link-and-its-label) · lines
|
|
33
|
-
- [A list of sub-items](#a-list-of-sub-items) · lines
|
|
34
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
35
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
36
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
37
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
38
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
39
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
40
|
-
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines
|
|
41
|
-
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines
|
|
42
|
-
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines
|
|
43
|
-
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines
|
|
44
|
-
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 815–1493
|
|
30
|
+
- [Presets: one line per field](#presets-one-line-per-field) · lines 1125–1193
|
|
31
|
+
- [Several fields edited as one](#several-fields-edited-as-one) · lines 1195–1231
|
|
32
|
+
- [A link and its label](#a-link-and-its-label) · lines 1233–1257
|
|
33
|
+
- [A list of sub-items](#a-list-of-sub-items) · lines 1259–1392
|
|
34
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1394–1479
|
|
35
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1481–1493
|
|
36
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1495–1561
|
|
37
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1563–1627
|
|
38
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1629–1727
|
|
39
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1729–1758
|
|
40
|
+
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1760–1798
|
|
41
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1800–1876
|
|
42
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1878–1901
|
|
43
|
+
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1903–1989
|
|
44
|
+
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 1991–2027
|
|
45
45
|
|
|
46
46
|
<!-- /index -->
|
|
47
47
|
|
|
@@ -849,7 +849,11 @@ on that tint, since muted on `bg-muted` is under 4.5:1; the package does
|
|
|
849
849
|
it, so an app just uses `text-muted-foreground` as anywhere else. On a
|
|
850
850
|
touch screen the pencil always shows. A click anywhere on the value opens it, except on a
|
|
851
851
|
link inside it (a reference to a record with a view, a link in the
|
|
852
|
-
notes), which still navigates.
|
|
852
|
+
notes), which still navigates. The tint reaches 0.375rem past the value
|
|
853
|
+
on each side without moving it, and never wraps it: a short title or
|
|
854
|
+
badge edited in place (`layout="inline"`) stays on one line, and a long
|
|
855
|
+
one wraps between words within its column (4.94; before, a title like
|
|
856
|
+
"Dr. Example" broke over two lines).
|
|
853
857
|
|
|
854
858
|
**In a field list, the row is the target** (4.88, `look="row"`, which
|
|
855
859
|
EntityView's field rows use). The row wears the list's row hover, the
|
|
@@ -3,38 +3,39 @@
|
|
|
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
|
-
- [Parts of the page standards](#parts-of-the-page-standards) · lines
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [A record's
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
- [
|
|
37
|
-
- [
|
|
6
|
+
- [Palettes](#palettes) · lines 48–155
|
|
7
|
+
- [Glow](#glow) · lines 157–176
|
|
8
|
+
- [Semantic tones](#semantic-tones) · lines 178–206
|
|
9
|
+
- [The three badge styles](#the-three-badge-styles) · lines 208–225
|
|
10
|
+
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 227–256
|
|
11
|
+
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 258–271
|
|
12
|
+
- [Logos and brand marks](#logos-and-brand-marks) · lines 273–317
|
|
13
|
+
- [Categorical colour](#categorical-colour) · lines 319–389
|
|
14
|
+
- [Heat scale](#heat-scale) · lines 391–452
|
|
15
|
+
- [Depth ramps](#depth-ramps) · lines 454–539
|
|
16
|
+
- [A stored colour](#a-stored-colour) · lines 541–589
|
|
17
|
+
- [Shapes and sizes](#shapes-and-sizes) · lines 591–612
|
|
18
|
+
- [Typography](#typography) · lines 614–736
|
|
19
|
+
- [Written text (notes)](#written-text-notes) · lines 648–736
|
|
20
|
+
- [Density](#density) · lines 738–831
|
|
21
|
+
- [Rows on this device](#rows-on-this-device) · lines 804–831
|
|
22
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 833–947
|
|
23
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 949–1026
|
|
24
|
+
- [Notices](#notices) · lines 1028–1056
|
|
25
|
+
- [A value over time](#a-value-over-time) · lines 1058–1144
|
|
26
|
+
- [Several values over time](#several-values-over-time) · lines 1107–1144
|
|
27
|
+
- [A list as a board](#a-list-as-a-board) · lines 1146–1197
|
|
28
|
+
- [A list as cards](#a-list-as-cards) · lines 1199–1245
|
|
29
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1247–1276
|
|
30
|
+
- [Parts of the page standards](#parts-of-the-page-standards) · lines 1278–1321
|
|
31
|
+
- [A few equal things](#a-few-equal-things) · lines 1323–1407
|
|
32
|
+
- [An overview page](#an-overview-page) · lines 1409–1472
|
|
33
|
+
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1473–1511
|
|
34
|
+
- [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1513–1558
|
|
35
|
+
- [Picking at random](#picking-at-random) · lines 1560–1591
|
|
36
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1593–1660
|
|
37
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1662–1687
|
|
38
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1689–1762
|
|
38
39
|
|
|
39
40
|
<!-- /index -->
|
|
40
41
|
|
|
@@ -685,7 +686,9 @@ least), a column's menu has Narrower, Wider, Fit to content and Fit all
|
|
|
685
686
|
columns, and a double-click on the edge fits it again. The width is kept
|
|
686
687
|
in the Markdown as a comment after the table, naming its columns
|
|
687
688
|
(`<!-- table widths: Item=140, Cost=72 -->`), which `<Markdown>` and the
|
|
688
|
-
editor read and never show
|
|
689
|
+
editor read and never show; nor do the backend's MCP read tools (4.94:
|
|
690
|
+
`fetch`, `list`, `search`, and `update`'s answer), while `edit_text` and
|
|
691
|
+
`update` keep it in what's stored. A column named nowhere fits its words. A
|
|
689
692
|
phone ignores the widths and can't set them; on paper they scale to the
|
|
690
693
|
page.
|
|
691
694
|
|
|
@@ -1317,6 +1320,92 @@ Every one is measured with axe and the glyph check in both themes
|
|
|
1317
1320
|
(fixtures `app/ValueList`, `ListHeader`, `Timeline`, `NeedsYou`,
|
|
1318
1321
|
`Freshness`, `PartEmpty`).
|
|
1319
1322
|
|
|
1323
|
+
## A few equal things
|
|
1324
|
+
|
|
1325
|
+
`EqualItems` (4.93, record standard R10): a small set of equal, related
|
|
1326
|
+
things inside a record (a plan's phases, the stores a price is compared
|
|
1327
|
+
at, a handful of options), one data shape in four looks. A record picks
|
|
1328
|
+
one look per set; a fifth is asked for first.
|
|
1329
|
+
|
|
1330
|
+
```tsx
|
|
1331
|
+
<EqualItems
|
|
1332
|
+
label="Phases"
|
|
1333
|
+
look="featured"
|
|
1334
|
+
featuredId={currentPhaseId}
|
|
1335
|
+
items={phases.map((phase) => ({
|
|
1336
|
+
id: String(phase.id),
|
|
1337
|
+
title: phase.name,
|
|
1338
|
+
state: { label: 'Current', tone: 'info' },
|
|
1339
|
+
fields: [{ label: 'Weeks', value: phase.weeks }, { label: 'Focus', value: phase.focus }],
|
|
1340
|
+
}))}
|
|
1341
|
+
/>
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
| `look` | Draws | Use it when |
|
|
1345
|
+
|---|---|---|
|
|
1346
|
+
| `cards` (the default) | a row of equal cards that wraps, one column on a phone; label and value on one line, no rules | a few things with little to say about each |
|
|
1347
|
+
| `table` | one compact row per item, the title as its row header, a column per field label (first-seen order), a dash where an item has none; scrolls sideways in its own box on a phone | things compared on the same values (a price at each store) |
|
|
1348
|
+
| `featured` | the item `featuredId` names in full, in a card with the accent border, then the rest as toggles that open in place | one is current or best (a program's phases) |
|
|
1349
|
+
| `panels` | a panel per item side by side, its title and state in a muted band, every detail labelled above its value; stacked on a phone | each has several details and must read as separate |
|
|
1350
|
+
|
|
1351
|
+
- **A state is a badge**, the outline style in its tone (`state: 'Planned'`
|
|
1352
|
+
is the neutral one; `{ label, tone }` with `info`, `success`, `warning`
|
|
1353
|
+
or `destructive`). Most states stay neutral ("Mapping an enum to tones").
|
|
1354
|
+
- **A field is the record's row**: the label in label type and muted, the
|
|
1355
|
+
value in body type; an empty value is the record's dash, read as "Not
|
|
1356
|
+
set". `featured` uses the rail's beside rows (field-rows.ts).
|
|
1357
|
+
- **Featured's toggles** are buttons inside headings at the items' level:
|
|
1358
|
+
Enter or Space opens one, Tab moves to the next, several can be open,
|
|
1359
|
+
`aria-expanded` says which. Never a link; `defaultOpenIds` opens some at
|
|
1360
|
+
first.
|
|
1361
|
+
- **Empty**: no items reads `emptyText` ("Nothing yet"), an item with no
|
|
1362
|
+
fields `noFieldsText` ("No details"). `label` names the set for a screen
|
|
1363
|
+
reader (the list's name, the table's caption); titles are `h3` under a
|
|
1364
|
+
section's `h2` (`headingLevel`).
|
|
1365
|
+
|
|
1366
|
+
**An item's own content and actions** (4.94). When an item holds more
|
|
1367
|
+
than label/value rows (an editor of several fields, a note, a chart), it
|
|
1368
|
+
carries them itself, never as a field's value, where the label/value grid
|
|
1369
|
+
squeezes them into its narrow value column:
|
|
1370
|
+
|
|
1371
|
+
```tsx
|
|
1372
|
+
items={stores.map((store) => ({
|
|
1373
|
+
id: store.id,
|
|
1374
|
+
title: store.name,
|
|
1375
|
+
fields: editing === store.id ? undefined : [{ label: 'Price', value: store.price }],
|
|
1376
|
+
content: editing === store.id && <StoreEditor store={store} onDone={stopEditing} />,
|
|
1377
|
+
wide: editing === store.id,
|
|
1378
|
+
actions: (
|
|
1379
|
+
<>
|
|
1380
|
+
<IconAction icon={PencilIcon} label={`Edit ${store.name}`} size="sm" variant="ghost" onClick={() => edit(store.id)} />
|
|
1381
|
+
<IconAction icon={Trash2Icon} label={`Remove ${store.name}`} tone="destructive" size="sm" variant="ghost" onClick={() => remove(store.id)} />
|
|
1382
|
+
</>
|
|
1383
|
+
),
|
|
1384
|
+
}))}
|
|
1385
|
+
```
|
|
1386
|
+
|
|
1387
|
+
- **`content`** goes under the item's fields at the item's full width (in
|
|
1388
|
+
`table`, a row of its own under the item's, as wide as the table's box
|
|
1389
|
+
and held in view while a phone scrolls the table sideways). An item with
|
|
1390
|
+
content and no fields reads no "No details".
|
|
1391
|
+
- **`actions`** are the item's own buttons, at the end of its title line;
|
|
1392
|
+
in `featured` beside the toggle, never inside its button; in `table` a
|
|
1393
|
+
last column, named `actionsColumn` ("Actions") for a screen reader. Icon
|
|
1394
|
+
actions (`IconAction`, a tooltip and a name each) named for the item
|
|
1395
|
+
("Edit Corner Hardware"), as the record standard's header draws them.
|
|
1396
|
+
A Remove that loses data asks first, as any delete does
|
|
1397
|
+
(add-an-entity.md "Deleting").
|
|
1398
|
+
- **`wide`** gives the item the whole row of `cards` or `panels`, for
|
|
1399
|
+
content that needs it: set it while the item's editor is open. The
|
|
1400
|
+
items keep their order; the others wrap around it.
|
|
1401
|
+
- **Editing one item swaps its fields for its editor** (the content), then
|
|
1402
|
+
back on Save or Cancel. The set's other items stay as they are.
|
|
1403
|
+
|
|
1404
|
+
Measured with axe, the token check and the glyph check in both themes and
|
|
1405
|
+
every palette (fixtures `app/EqualItems`, "Content and actions" among
|
|
1406
|
+
them), and from the keyboard and at a phone's width in
|
|
1407
|
+
`e2e/equal-items.spec.ts`.
|
|
1408
|
+
|
|
1320
1409
|
## An overview page
|
|
1321
1410
|
|
|
1322
1411
|
The overview standard (4.89): a module's first page when it has three
|
|
@@ -237,7 +237,12 @@ export function EditableField({ label, edit, children, layout = 'block', look =
|
|
|
237
237
|
const row = look === 'row';
|
|
238
238
|
return (_jsxs("span", { "data-slot": "editable-value", "data-look": look, onClick: onShownClick, className: cn('group/editable relative cursor-text items-start gap-1',
|
|
239
239
|
// A row: the row (editRowClass) wears the hover, not the value.
|
|
240
|
-
!row && '-mx-1.5 rounded-md px-1.5 transition-colors hover:bg-muted has-[[data-edit]:focus-visible]:bg-muted',
|
|
240
|
+
!row && '-mx-1.5 rounded-md px-1.5 transition-colors hover:bg-muted has-[[data-edit]:focus-visible]:bg-muted',
|
|
241
|
+
// Inline, the cap is its column plus the 0.75rem the negative
|
|
242
|
+
// margins give back: a parent sized to its content (a title on
|
|
243
|
+
// its line) is sized to the margin box, 0.75rem under the box,
|
|
244
|
+
// and `max-w-full` then wrapped a short value mid-word (4.94).
|
|
245
|
+
layout === 'block' ? 'flex w-full' : cn('inline-flex align-top', row ? 'max-w-full' : 'max-w-[calc(100%+0.75rem)]'), className), children: [_jsxs("span", { className: cn('min-w-0 flex-1', !row &&
|
|
241
246
|
'group-hover/editable:[&_.text-muted-foreground]:text-foreground group-has-[[data-edit]:focus-visible]/editable:[&_.text-muted-foreground]:text-foreground'), children: [children !== undefined ? children : edit.shown, _jsx("span", { role: "status", "data-slot": "editable-value-saved", className: "ml-2 inline-flex items-center gap-1 align-baseline type-caption text-success-text empty:hidden", children: justSaved && (_jsxs(_Fragment, { children: [_jsx(CheckIcon, { "aria-hidden": "true", className: "size-3.5" }), "Saved"] })) })] }), _jsx(Button, { ref: editButton, "data-edit": "", type: "button", variant: "ghost", size: "icon-xs", "aria-label": `Edit ${label}`, onClick: start, className: cn('shrink-0 text-muted-foreground opacity-0 focus-visible:opacity-100 pointer-coarse:opacity-100', row ? 'group-hover/edit-row:opacity-100 hover:bg-transparent max-md:opacity-100' : 'group-hover/editable:opacity-100'), children: row ? (_jsxs(_Fragment, { children: [_jsx(PencilIcon, { className: "max-md:hidden pointer-coarse:hidden" }), _jsx(ChevronRightIcon, { className: "hidden max-md:block pointer-coarse:block" })] })) : (_jsx(PencilIcon, {})) })] }));
|
|
242
247
|
}
|
|
243
248
|
// Always editable, before the store has it (the first render): the saved value.
|
|
@@ -97,6 +97,7 @@ import { EditableValue, LeaveGuard } from './editable-value.js';
|
|
|
97
97
|
import { EmptyText } from './empty-value.js';
|
|
98
98
|
import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
|
|
99
99
|
import { useRecordDialog } from './record-dialog-context.js';
|
|
100
|
+
import { FIELD_LABEL, FIELD_ROW, FIELD_ROW_BASE, FIELD_VALUE } from './field-rows.js';
|
|
100
101
|
import { PageTrail } from './page-trail.js';
|
|
101
102
|
import { usePageTrail } from './page-trail-context.js';
|
|
102
103
|
import { entityViewTabSlug } from '../../lib/entity-view-tab.js';
|
|
@@ -119,25 +120,12 @@ function OrEmpty({ value, emptyLabel }) {
|
|
|
119
120
|
}
|
|
120
121
|
// A preset shows its own value unless the screen gives one.
|
|
121
122
|
const fieldValue = (field) => (field.value !== undefined ? field.value : field.edit?.shown);
|
|
122
|
-
// Label beside value from `sm` up; below it (a phone) the label sits
|
|
123
|
-
// above its value, so nothing is squeezed into a narrow second column. In
|
|
124
|
-
// the rail the list's own width decides instead (a container query on the
|
|
125
|
-
// <dl>): label above value in the narrow rail, beside it once the rail's
|
|
126
|
-
// sections stack full width under the header.
|
|
127
|
-
// `railFields="beside"` (4.76) puts them side by side in the rail too,
|
|
128
|
-
// from an 18rem list (a rail card beside the main column is ~19rem
|
|
129
|
-
// inside), with a narrower label column, and stacked below that.
|
|
130
|
-
const FIELD_ROW = {
|
|
131
|
-
page: 'sm:grid sm:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] sm:gap-6',
|
|
132
|
-
rail: '@lg/fields:grid @lg/fields:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] @lg/fields:gap-6',
|
|
133
|
-
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',
|
|
134
|
-
};
|
|
135
123
|
function FieldRow({ field, place }) {
|
|
136
124
|
const value = fieldValue(field);
|
|
137
125
|
// An editable row is the target as a whole (4.88, F15/F18): the list's
|
|
138
126
|
// row hover, its pencil at the end, a chevron on a phone.
|
|
139
127
|
const editable = Boolean(field.edit);
|
|
140
|
-
return (_jsxs("div", { className: cn(
|
|
128
|
+
return (_jsxs("div", { className: cn(FIELD_ROW_BASE, FIELD_ROW[place], editable && cn(editRowClass, '-mx-2 px-2 first:pt-2 last:pb-2')), onClick: editable ? onEditRowClick : undefined, children: [_jsx("dt", { className: FIELD_LABEL, children: field.label }), _jsx("dd", { className: FIELD_VALUE, children: field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, look: "row", children: _jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }) })) : (_jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel })) })] }));
|
|
141
129
|
}
|
|
142
130
|
// A fields card's rows. Folded (`emptyFields="fold"`), the filled fields
|
|
143
131
|
// show and the empty ones wait behind "N empty", which opens them in their
|
|
@@ -298,7 +286,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
|
|
|
298
286
|
const main = (_jsxs("div", { className: cn(RAIL_LAYOUT.main, railSections.length === 0 && RAIL_LAYOUT.mainAlone), children: [mainSections
|
|
299
287
|
.filter((section) => !tabbed(section))
|
|
300
288
|
.map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
|
|
301
|
-
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 && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _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",
|
|
289
|
+
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 && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _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", 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
|
|
302
290
|
.filter((section) => !tabbed(section))
|
|
303
291
|
.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 }))] }) }) }));
|
|
304
292
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/** Which look a set of equal items takes. */
|
|
3
|
+
export type EqualItemsLook = 'cards' | 'table' | 'featured' | 'panels';
|
|
4
|
+
/**
|
|
5
|
+
* A state's tone, from design-language.md "Semantic tones": `neutral` (the
|
|
6
|
+
* default) for most values, a colour only where the state means good,
|
|
7
|
+
* bad or worth a look. Drawn as the outline badge of that tone.
|
|
8
|
+
*/
|
|
9
|
+
export type EqualItemTone = 'neutral' | 'info' | 'success' | 'warning' | 'destructive';
|
|
10
|
+
/** A small status ("Current", "Done", "Planned") and its tone. */
|
|
11
|
+
export type EqualItemState = {
|
|
12
|
+
label: string;
|
|
13
|
+
/** Defaults to `neutral`. */
|
|
14
|
+
tone?: EqualItemTone;
|
|
15
|
+
};
|
|
16
|
+
/** One labelled value of an item. */
|
|
17
|
+
export type EqualItemField = {
|
|
18
|
+
/** The label: a word or two. In the `table` look, its column's heading. */
|
|
19
|
+
label: string;
|
|
20
|
+
/** The value, formatted as the screen's cells are. Empty reads as a dash. */
|
|
21
|
+
value: ReactNode;
|
|
22
|
+
};
|
|
23
|
+
/** One of the equal things. */
|
|
24
|
+
export type EqualItem = {
|
|
25
|
+
/** Unique in the list; a stored id when there is one. */
|
|
26
|
+
id: string;
|
|
27
|
+
/** Its name ("Phase 2", "Plus"). Plain text: it names the item's toggle and row. */
|
|
28
|
+
title: string;
|
|
29
|
+
/** A small status, as a badge: words alone are a neutral one. */
|
|
30
|
+
state?: string | EqualItemState;
|
|
31
|
+
/** Its details, in order. None (and no `content`) reads as `noFieldsText`. */
|
|
32
|
+
fields?: readonly EqualItemField[];
|
|
33
|
+
/**
|
|
34
|
+
* Anything of the app's, under the fields at the item's full width (an
|
|
35
|
+
* editor of several fields, a note): never squeezed into the label/value
|
|
36
|
+
* grid. In the `table` look, a row of its own under the item's.
|
|
37
|
+
*/
|
|
38
|
+
content?: ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* The item's own buttons (Edit, Remove), small and named for the item
|
|
41
|
+
* ("Edit Phase 2"): at the end of its title line, beside a featured
|
|
42
|
+
* toggle's button (never inside it), or the `table` look's last column.
|
|
43
|
+
*/
|
|
44
|
+
actions?: ReactNode;
|
|
45
|
+
/** The whole row in the `cards` and `panels` looks (an editor open in it). */
|
|
46
|
+
wide?: boolean;
|
|
47
|
+
};
|
|
48
|
+
export type EqualItemsProps = {
|
|
49
|
+
items: readonly EqualItem[];
|
|
50
|
+
/** Defaults to `cards`. */
|
|
51
|
+
look?: EqualItemsLook;
|
|
52
|
+
/**
|
|
53
|
+
* For `look="featured"`: the item shown in full. Defaults to the first
|
|
54
|
+
* one; an id that matches none falls back to the first too.
|
|
55
|
+
*/
|
|
56
|
+
featuredId?: string;
|
|
57
|
+
/**
|
|
58
|
+
* For `look="featured"`: the other items open when it first shows.
|
|
59
|
+
* Each toggle opens and closes on its own after that.
|
|
60
|
+
*/
|
|
61
|
+
defaultOpenIds?: readonly string[];
|
|
62
|
+
/** The set's name for screen readers ("Phases"); the table's caption. */
|
|
63
|
+
label: string;
|
|
64
|
+
/** The items' heading level: 3 (the default) under a section's h2. */
|
|
65
|
+
headingLevel?: 3 | 4 | 5;
|
|
66
|
+
/** For `look="table"`: the first column's heading. Defaults to "Name". */
|
|
67
|
+
titleColumn?: string;
|
|
68
|
+
/** For `look="table"`: the state column's heading. Defaults to "Status". */
|
|
69
|
+
stateColumn?: string;
|
|
70
|
+
/** For `look="table"`: the actions column's heading, for screen readers. Defaults to "Actions". */
|
|
71
|
+
actionsColumn?: string;
|
|
72
|
+
/** What no items says. Defaults to "Nothing yet". */
|
|
73
|
+
emptyText?: string;
|
|
74
|
+
/** What an item with no fields says. Defaults to "No details". */
|
|
75
|
+
noFieldsText?: string;
|
|
76
|
+
className?: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* A few equal, related things inside a record view (record page standard
|
|
80
|
+
* R10): one data shape, four looks.
|
|
81
|
+
*
|
|
82
|
+
* ```tsx
|
|
83
|
+
* <EqualItems
|
|
84
|
+
* label="Phases"
|
|
85
|
+
* look="featured"
|
|
86
|
+
* featuredId="p2"
|
|
87
|
+
* items={[
|
|
88
|
+
* { id: 'p1', title: 'Phase 1', state: { label: 'Done', tone: 'success' }, fields: [{ label: 'Weeks', value: '1–4' }] },
|
|
89
|
+
* { id: 'p2', title: 'Phase 2', state: { label: 'Current', tone: 'info' }, fields: [{ label: 'Weeks', value: '5–8' }] },
|
|
90
|
+
* { id: 'p3', title: 'Phase 3', state: 'Planned', fields: [{ label: 'Weeks', value: '9–12' }] },
|
|
91
|
+
* ]}
|
|
92
|
+
* />
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* `cards` for a few things with little to say about each, `table` for
|
|
96
|
+
* things compared on the same values, `featured` when one is current or
|
|
97
|
+
* best, `panels` when each has several details and must read as separate
|
|
98
|
+
* (design-language.md "A few equal things"). An item's own `content` (an
|
|
99
|
+
* editor) goes under its fields at full width, its `actions` (Edit, Remove)
|
|
100
|
+
* at its title line's end; `wide` gives it the whole row of cards or panels.
|
|
101
|
+
*/
|
|
102
|
+
export declare function EqualItems({ items, look, featuredId, defaultOpenIds, label, headingLevel, titleColumn, stateColumn, actionsColumn, emptyText, noFieldsText, className, }: EqualItemsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// A few equal things in a record (record page standard R10): the phases of
|
|
3
|
+
// a plan, the stores a price is compared at, a handful of options. One data
|
|
4
|
+
// shape, four looks, each the record picks for what it shows:
|
|
5
|
+
//
|
|
6
|
+
// - `cards`: a row of equal cards that wraps (one column on a phone), each
|
|
7
|
+
// its title, its state as a badge and its fields as short label/value
|
|
8
|
+
// lines.
|
|
9
|
+
// For a few things with little to say about each.
|
|
10
|
+
// - `table`: one compact row per item, a column per field label. For
|
|
11
|
+
// things compared on the same values.
|
|
12
|
+
// - `featured`: the item `featuredId` names (the current one, the best one)
|
|
13
|
+
// in full, then the others as toggles that open in place, one or several
|
|
14
|
+
// at a time. Never navigation.
|
|
15
|
+
// - `panels`: a panel per item side by side, every detail labelled above
|
|
16
|
+
// its value, stacking on a phone. For things with several details each
|
|
17
|
+
// that need to read as separate.
|
|
18
|
+
//
|
|
19
|
+
// The parts are the record's own: a state is a `Badge` in the outline
|
|
20
|
+
// style (design-language.md "The three badge styles"), a field is the
|
|
21
|
+
// rail's label/value row (field-rows.ts, as EntityView draws it), an empty
|
|
22
|
+
// value is the record's dash, read as "Not set". It owns its empty states:
|
|
23
|
+
// no items reads `emptyText` ("Nothing yet"), an item with no fields
|
|
24
|
+
// `noFieldsText` ("No details").
|
|
25
|
+
//
|
|
26
|
+
// An item can carry its own parts too (4.94): `content`, anything of the
|
|
27
|
+
// app's (an editor of several fields, a note, a chart), drawn under its
|
|
28
|
+
// fields at the item's full width, never in the label/value grid; and
|
|
29
|
+
// `actions`, its own buttons (Edit, Remove), at the end of its title line,
|
|
30
|
+
// or the table's last column. `wide` gives an item the whole row in
|
|
31
|
+
// `cards` and `panels`, for content that needs it (an editor open).
|
|
32
|
+
import { Fragment, useState } from 'react';
|
|
33
|
+
import { ChevronDownIcon } from 'lucide-react';
|
|
34
|
+
import { cn } from 'cn';
|
|
35
|
+
import { Badge } from '../ui/badge.js';
|
|
36
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible.js';
|
|
37
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../ui/table.js';
|
|
38
|
+
import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
|
|
39
|
+
import { EmptyText } from './empty-value.js';
|
|
40
|
+
import { FIELD_LABEL, FIELD_ROW, FIELD_ROW_BASE, FIELD_VALUE } from './field-rows.js';
|
|
41
|
+
const TONE_BADGE = {
|
|
42
|
+
neutral: 'outline',
|
|
43
|
+
info: 'outline-info',
|
|
44
|
+
success: 'outline-success',
|
|
45
|
+
warning: 'outline-warning',
|
|
46
|
+
destructive: 'outline-destructive',
|
|
47
|
+
};
|
|
48
|
+
const stateOf = (state) => state === undefined || state === '' ? undefined : typeof state === 'string' ? { label: state } : state;
|
|
49
|
+
function StateBadge({ state }) {
|
|
50
|
+
const value = stateOf(state);
|
|
51
|
+
if (!value)
|
|
52
|
+
return null;
|
|
53
|
+
return (_jsx(Badge, { "data-slot": "equal-item-state", variant: TONE_BADGE[value.tone ?? 'neutral'], children: value.label }));
|
|
54
|
+
}
|
|
55
|
+
function Value({ value }) {
|
|
56
|
+
return isEmptyValue(value) ? _jsx(EmptyText, { text: EMPTY_DASH }) : value;
|
|
57
|
+
}
|
|
58
|
+
// The item's fields. `beside` is the rail's rows (field-rows.ts): the
|
|
59
|
+
// label left of its value from an 18rem list (a featured item, an open
|
|
60
|
+
// toggle), stacked in a narrower one. `stacked` keeps every label above its
|
|
61
|
+
// value (panels). `compact` is a card's: label and value on one line, no
|
|
62
|
+
// rules between, for a few short facts.
|
|
63
|
+
function Fields({ fields, noFieldsText, rows, }) {
|
|
64
|
+
if (!fields || fields.length === 0) {
|
|
65
|
+
return _jsx("p", { className: "type-body text-muted-foreground", children: noFieldsText });
|
|
66
|
+
}
|
|
67
|
+
if (rows === 'compact') {
|
|
68
|
+
return (_jsx("dl", { "data-slot": "equal-item-fields", className: "grid grid-cols-[minmax(0,auto)_minmax(0,1fr)] items-baseline gap-x-3 gap-y-1.5", children: fields.map((field, index) => (_jsxs("div", { className: "contents", children: [_jsx("dt", { className: cn(FIELD_LABEL, 'break-words'), children: field.label }), _jsx("dd", { className: FIELD_VALUE, children: _jsx(Value, { value: field.value }) })] }, `${field.label}-${index}`))) }));
|
|
69
|
+
}
|
|
70
|
+
return (_jsx("dl", { "data-slot": "equal-item-fields", className: "@container/fields flex flex-col divide-y divide-border", children: fields.map((field, index) => (_jsxs("div", { className: cn(FIELD_ROW_BASE, rows === 'beside' && FIELD_ROW.railBeside), children: [_jsx("dt", { className: FIELD_LABEL, children: field.label }), _jsx("dd", { className: FIELD_VALUE, children: _jsx(Value, { value: field.value }) })] }, `${field.label}-${index}`))) }));
|
|
71
|
+
}
|
|
72
|
+
const hasPart = (part) => part !== undefined && part !== null && part !== false;
|
|
73
|
+
function Actions({ actions, className }) {
|
|
74
|
+
if (!hasPart(actions))
|
|
75
|
+
return null;
|
|
76
|
+
return (_jsx("div", { "data-slot": "equal-item-actions", className: cn('flex shrink-0 flex-wrap items-center justify-end gap-1', className), children: actions }));
|
|
77
|
+
}
|
|
78
|
+
// The title and its state, then the item's actions at the line's end.
|
|
79
|
+
function Title({ item, level, className }) {
|
|
80
|
+
const Heading = `h${level}`;
|
|
81
|
+
const withActions = hasPart(item.actions);
|
|
82
|
+
const heading = (_jsxs("div", { className: cn('flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1', withActions ? 'flex-1' : className), children: [_jsx(Heading, { className: "min-w-0 type-body font-semibold break-words text-foreground", children: item.title }), _jsx(StateBadge, { state: item.state })] }));
|
|
83
|
+
if (!withActions)
|
|
84
|
+
return heading;
|
|
85
|
+
return (_jsxs("div", { className: cn('flex min-w-0 items-start gap-2', className), children: [heading, _jsx(Actions, { actions: item.actions, className: "-my-1" })] }));
|
|
86
|
+
}
|
|
87
|
+
// An item's body: its fields, then its own content at full width. Content
|
|
88
|
+
// alone needs no fields, and reads no "No details".
|
|
89
|
+
function Body({ item, noFieldsText, rows, }) {
|
|
90
|
+
if (!hasPart(item.content))
|
|
91
|
+
return _jsx(Fields, { fields: item.fields, noFieldsText: noFieldsText, rows: rows });
|
|
92
|
+
return (_jsxs(_Fragment, { children: [item.fields && item.fields.length > 0 && _jsx(Fields, { fields: item.fields, noFieldsText: noFieldsText, rows: rows }), _jsx("div", { "data-slot": "equal-item-content", className: "min-w-0", children: item.content })] }));
|
|
93
|
+
}
|
|
94
|
+
function Cards({ items, label, level, noFieldsText }) {
|
|
95
|
+
return (_jsx("ul", { "aria-label": label, className: "grid grid-cols-[repeat(auto-fill,minmax(min(100%,14rem),1fr))] gap-3", children: items.map((item) => (_jsxs("li", { "data-slot": "equal-item", "data-wide": item.wide ? '' : undefined, className: cn('flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-card p-4 text-card-foreground', item.wide && 'col-span-full'), children: [_jsx(Title, { item: item, level: level }), _jsx(Body, { item: item, noFieldsText: noFieldsText, rows: "compact" })] }, item.id))) }));
|
|
96
|
+
}
|
|
97
|
+
function Panels({ items, label, level, noFieldsText }) {
|
|
98
|
+
return (_jsx("ul", { "aria-label": label, className: "grid grid-cols-1 gap-3 sm:grid-cols-[repeat(auto-fit,minmax(14rem,1fr))]", children: items.map((item) => (_jsxs("li", { "data-slot": "equal-item", "data-wide": item.wide ? '' : undefined, className: cn('flex min-w-0 flex-col overflow-hidden rounded-lg border border-border bg-card text-card-foreground', item.wide && 'col-span-full'), children: [_jsx(Title, { item: item, level: level, className: "border-b border-border bg-muted/40 px-4 py-3" }), _jsx("div", { className: "flex flex-col gap-3 px-4 py-3", children: _jsx(Body, { item: item, noFieldsText: noFieldsText, rows: "stacked" }) })] }, item.id))) }));
|
|
99
|
+
}
|
|
100
|
+
// One column per field label, in the order the items first give them; an
|
|
101
|
+
// item without one reads as a dash there. The title is each row's header.
|
|
102
|
+
function ItemsTable({ items, label, titleColumn, stateColumn, actionsColumn, }) {
|
|
103
|
+
const columns = [];
|
|
104
|
+
for (const item of items)
|
|
105
|
+
for (const field of item.fields ?? [])
|
|
106
|
+
if (!columns.includes(field.label))
|
|
107
|
+
columns.push(field.label);
|
|
108
|
+
const hasState = items.some((item) => stateOf(item.state));
|
|
109
|
+
const hasActions = items.some((item) => hasPart(item.actions));
|
|
110
|
+
const span = 1 + (hasState ? 1 : 0) + columns.length + (hasActions ? 1 : 0);
|
|
111
|
+
return (_jsx("div", { "data-slot": "equal-items-table", className: "@container/equal-table rounded-lg border border-border bg-card text-card-foreground", children: _jsxs(Table, { children: [_jsx("caption", { className: "sr-only", children: label }), _jsx(TableHeader, { children: _jsxs(TableRow, { className: "hover:bg-transparent", children: [_jsx(TableHead, { scope: "col", className: "type-label text-muted-foreground", children: titleColumn }), hasState && (_jsx(TableHead, { scope: "col", className: "type-label text-muted-foreground", children: stateColumn })), columns.map((column) => (_jsx(TableHead, { scope: "col", className: "type-label text-muted-foreground", children: column }, column))), hasActions && (_jsx(TableHead, { scope: "col", children: _jsx("span", { className: "sr-only", children: actionsColumn }) }))] }) }), _jsx(TableBody, { className: "[&_tr:nth-child(even)]:bg-transparent", children: items.map((item) => (_jsxs(Fragment, { children: [_jsxs(TableRow, { "data-slot": "equal-item", className: cn(hasPart(item.content) && 'border-b-0'), children: [_jsx(TableHead, { scope: "row", className: "h-auto min-w-28 py-(--table-cell-py) font-semibold sm:min-w-40 break-words whitespace-normal", children: item.title }), hasState && (_jsx(TableCell, { children: stateOf(item.state) ? _jsx(StateBadge, { state: item.state }) : _jsx(EmptyText, { text: EMPTY_DASH }) })), columns.map((column) => (_jsx(TableCell, { className: "type-body tabular-nums", children: _jsx(Value, { value: item.fields?.find((field) => field.label === column)?.value }) }, column))), hasActions && (_jsx(TableCell, { className: "w-0 py-1", children: _jsx(Actions, { actions: item.actions, className: "flex-nowrap" }) }))] }), hasPart(item.content) && (_jsx(TableRow, { "data-slot": "equal-item-content-row", className: "hover:bg-transparent", children: _jsx(TableCell, { colSpan: span, className: "pt-0 whitespace-normal", children: _jsx("div", { "data-slot": "equal-item-content", className: "sticky left-(--table-cell-px) w-[calc(100cqw-var(--table-cell-px)*2)] min-w-0", children: item.content }) }) }))] }, item.id))) })] }) }));
|
|
112
|
+
}
|
|
113
|
+
function Featured({ items, label, level, noFieldsText, featuredId, defaultOpenIds, }) {
|
|
114
|
+
const featured = items.find((item) => item.id === featuredId) ?? items[0];
|
|
115
|
+
const rest = items.filter((item) => item !== featured);
|
|
116
|
+
return (_jsxs("div", { role: "group", "aria-label": label, className: "flex flex-col gap-3", children: [_jsxs("section", { "data-slot": "equal-item", "data-featured": "", "aria-label": featured.title, className: "flex min-w-0 flex-col gap-3 rounded-lg border border-primary bg-card p-4 text-card-foreground", children: [_jsx(Title, { item: featured, level: level }), _jsx(Body, { item: featured, noFieldsText: noFieldsText, rows: "beside" })] }), rest.length > 0 && (_jsx("ul", { className: "flex flex-col divide-y divide-border rounded-lg border border-border bg-card text-card-foreground", children: rest.map((item) => (_jsx(FeaturedToggle, { item: item, level: level, noFieldsText: noFieldsText, defaultOpen: defaultOpenIds?.includes(item.id) ?? false }, item.id))) }))] }));
|
|
117
|
+
}
|
|
118
|
+
// A heading holding its button (the disclosure pattern): Enter and Space
|
|
119
|
+
// open and close it, Tab moves on to the next, and the button says
|
|
120
|
+
// whether it's open. Each opens on its own, so several can be open.
|
|
121
|
+
function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
|
|
122
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
123
|
+
const Heading = `h${level}`;
|
|
124
|
+
return (_jsx("li", { "data-slot": "equal-item", children: _jsxs(Collapsible, { open: open, onOpenChange: setOpen, children: [_jsxs("div", { className: "flex min-w-0 items-center", children: [_jsx(Heading, { className: "m-0 min-w-0 flex-1", children: _jsxs(CollapsibleTrigger, { "data-slot": "equal-item-toggle", className: "flex min-h-11 w-full items-center gap-2 px-4 py-2 text-left outline-none hover:bg-muted/50 focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset", children: [_jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('size-4 shrink-0 text-muted-foreground transition-transform', !open && '-rotate-90') }), _jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1", children: [_jsx("span", { className: "min-w-0 type-body font-semibold break-words text-foreground", children: item.title }), _jsx(StateBadge, { state: item.state })] })] }) }), _jsx(Actions, { actions: item.actions, className: "pr-4" })] }), _jsx(CollapsibleContent, { className: "flex flex-col gap-3 px-4 pt-1 pb-4 pl-10", children: _jsx(Body, { item: item, noFieldsText: noFieldsText, rows: "beside" }) })] }) }));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A few equal, related things inside a record view (record page standard
|
|
128
|
+
* R10): one data shape, four looks.
|
|
129
|
+
*
|
|
130
|
+
* ```tsx
|
|
131
|
+
* <EqualItems
|
|
132
|
+
* label="Phases"
|
|
133
|
+
* look="featured"
|
|
134
|
+
* featuredId="p2"
|
|
135
|
+
* items={[
|
|
136
|
+
* { id: 'p1', title: 'Phase 1', state: { label: 'Done', tone: 'success' }, fields: [{ label: 'Weeks', value: '1–4' }] },
|
|
137
|
+
* { id: 'p2', title: 'Phase 2', state: { label: 'Current', tone: 'info' }, fields: [{ label: 'Weeks', value: '5–8' }] },
|
|
138
|
+
* { id: 'p3', title: 'Phase 3', state: 'Planned', fields: [{ label: 'Weeks', value: '9–12' }] },
|
|
139
|
+
* ]}
|
|
140
|
+
* />
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* `cards` for a few things with little to say about each, `table` for
|
|
144
|
+
* things compared on the same values, `featured` when one is current or
|
|
145
|
+
* best, `panels` when each has several details and must read as separate
|
|
146
|
+
* (design-language.md "A few equal things"). An item's own `content` (an
|
|
147
|
+
* editor) goes under its fields at full width, its `actions` (Edit, Remove)
|
|
148
|
+
* at its title line's end; `wide` gives it the whole row of cards or panels.
|
|
149
|
+
*/
|
|
150
|
+
export function EqualItems({ items, look = 'cards', featuredId, defaultOpenIds, label, headingLevel = 3, titleColumn = 'Name', stateColumn = 'Status', actionsColumn = 'Actions', emptyText = 'Nothing yet', noFieldsText = 'No details', className, }) {
|
|
151
|
+
if (items.length === 0) {
|
|
152
|
+
return (_jsx("p", { "data-slot": "equal-items", "data-look": look, "data-state": "empty", className: cn('type-body text-muted-foreground', className), children: emptyText }));
|
|
153
|
+
}
|
|
154
|
+
const shared = { items, label, level: headingLevel, noFieldsText };
|
|
155
|
+
return (_jsx("div", { "data-slot": "equal-items", "data-look": look, className: cn('min-w-0', className), children: look === 'table' ? (_jsx(ItemsTable, { items: items, label: label, titleColumn: titleColumn, stateColumn: stateColumn, actionsColumn: actionsColumn })) : look === 'featured' ? (_jsx(Featured, { ...shared, featuredId: featuredId, defaultOpenIds: defaultOpenIds })) : look === 'panels' ? (_jsx(Panels, { ...shared })) : (_jsx(Cards, { ...shared })) }));
|
|
156
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const FIELD_ROW: {
|
|
2
|
+
page: string;
|
|
3
|
+
rail: string;
|
|
4
|
+
railBeside: string;
|
|
5
|
+
};
|
|
6
|
+
/** A row's own spacing, before its place's grid. */
|
|
7
|
+
export declare const FIELD_ROW_BASE = "flex flex-col gap-1 py-3 first:pt-0 last:pb-0";
|
|
8
|
+
/** The label (`<dt>`): label type, muted. */
|
|
9
|
+
export declare const FIELD_LABEL = "type-label text-muted-foreground";
|
|
10
|
+
/** The value (`<dd>`): body type, foreground, long words broken. */
|
|
11
|
+
export declare const FIELD_VALUE = "min-w-0 type-body break-words text-foreground";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// A record's label/value rows, shared by EntityView's fields cards and
|
|
2
|
+
// EqualItems (record standard R10), so a fact reads the same wherever a
|
|
3
|
+
// record shows it.
|
|
4
|
+
//
|
|
5
|
+
// Label beside value from `sm` up; below it (a phone) the label sits
|
|
6
|
+
// above its value, so nothing is squeezed into a narrow second column. In
|
|
7
|
+
// the rail the list's own width decides instead (a container query on the
|
|
8
|
+
// <dl>): label above value in the narrow rail, beside it once the rail's
|
|
9
|
+
// sections stack full width under the header.
|
|
10
|
+
// `railFields="beside"` (4.76) puts them side by side in the rail too,
|
|
11
|
+
// from an 18rem list (a rail card beside the main column is ~19rem
|
|
12
|
+
// inside), with a narrower label column, and stacked below that. Each
|
|
13
|
+
// container query needs an `@container/fields` on the <dl>.
|
|
14
|
+
export const FIELD_ROW = {
|
|
15
|
+
page: 'sm:grid sm:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] sm:gap-6',
|
|
16
|
+
rail: '@lg/fields:grid @lg/fields:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] @lg/fields:gap-6',
|
|
17
|
+
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',
|
|
18
|
+
};
|
|
19
|
+
/** A row's own spacing, before its place's grid. */
|
|
20
|
+
export const FIELD_ROW_BASE = 'flex flex-col gap-1 py-3 first:pt-0 last:pb-0';
|
|
21
|
+
/** The label (`<dt>`): label type, muted. */
|
|
22
|
+
export const FIELD_LABEL = 'type-label text-muted-foreground';
|
|
23
|
+
/** The value (`<dd>`): body type, foreground, long words broken. */
|
|
24
|
+
export const FIELD_VALUE = 'min-w-0 type-body break-words text-foreground';
|
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export { Notice, type NoticeProps, type NoticeTone } from './components/app/noti
|
|
|
71
71
|
export { ValueList, type ValueListItem, type ValueListProps } from './components/app/value-list.js';
|
|
72
72
|
export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, } from './components/app/list-header.js';
|
|
73
73
|
export { Timeline, type TimelineItem, type TimelineProps } from './components/app/timeline.js';
|
|
74
|
+
export { EqualItems, type EqualItem, type EqualItemField, type EqualItemState, type EqualItemTone, type EqualItemsLook, type EqualItemsProps, } from './components/app/equal-items.js';
|
|
74
75
|
export { NeedsYou, type NeedsYouItem, type NeedsYouProps, type NeedsYouTone } from './components/app/needs-you.js';
|
|
75
76
|
export { Freshness, type FreshnessProps } from './components/app/freshness.js';
|
|
76
77
|
export { isStale } from './lib/freshness.js';
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,7 @@ export { Notice } from './components/app/notice.js';
|
|
|
75
75
|
export { ValueList } from './components/app/value-list.js';
|
|
76
76
|
export { ListHeader, } from './components/app/list-header.js';
|
|
77
77
|
export { Timeline } from './components/app/timeline.js';
|
|
78
|
+
export { EqualItems, } from './components/app/equal-items.js';
|
|
78
79
|
export { NeedsYou } from './components/app/needs-you.js';
|
|
79
80
|
export { Freshness } from './components/app/freshness.js';
|
|
80
81
|
export { isStale } from './lib/freshness.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.94.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": {
|