@tristan2828/ui-foundation 4.91.0 → 4.93.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.
@@ -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–1144
19
- - [The record view](#the-record-view) · lines 983–1022
20
- - [Forms](#forms) · lines 1024–1076
21
- - [Dialogs](#dialogs) · lines 1078–1103
22
- - [Toasts and feedback](#toasts-and-feedback) · lines 1105–1144
23
- - [What not to copy](#what-not-to-copy) · lines 1146–1172
24
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1174–1191
25
- - [Deleting](#deleting) · lines 1193–1224
26
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1226–1247
27
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1249–1258
28
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1261–1300
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 834–1150
19
+ - [The record view](#the-record-view) · lines 983–1028
20
+ - [Forms](#forms) · lines 1030–1082
21
+ - [Dialogs](#dialogs) · lines 1084–1109
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1111–1150
23
+ - [What not to copy](#what-not-to-copy) · lines 1152–1178
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1180–1197
25
+ - [Deleting](#deleting) · lines 1199–1230
26
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1232–1253
27
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1255–1264
28
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1267–1306
29
29
 
30
30
  <!-- /index -->
31
31
 
@@ -1015,6 +1015,12 @@ 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.
1018
1024
  - **A big record's own parts** (a drawing, a player, a checklist of
1019
1025
  documents) are sections in the view, not a screen of their own.
1020
1026
 
@@ -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 47–114
7
- - [Glow](#glow) · lines 116–134
8
- - [Semantic tones](#semantic-tones) · lines 136–164
9
- - [The three badge styles](#the-three-badge-styles) · lines 166–183
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 185–214
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 216–229
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 231–275
13
- - [Categorical colour](#categorical-colour) · lines 277–347
14
- - [Heat scale](#heat-scale) · lines 349–410
15
- - [Depth ramps](#depth-ramps) · lines 412–495
16
- - [A stored colour](#a-stored-colour) · lines 497–545
17
- - [Shapes and sizes](#shapes-and-sizes) · lines 547–568
18
- - [Typography](#typography) · lines 570–690
19
- - [Written text (notes)](#written-text-notes) · lines 604–690
20
- - [Density](#density) · lines 692–785
21
- - [Rows on this device](#rows-on-this-device) · lines 758–785
22
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 787–901
23
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 903–980
24
- - [Notices](#notices) · lines 982–1010
25
- - [A value over time](#a-value-over-time) · lines 1012–1098
26
- - [Several values over time](#several-values-over-time) · lines 1061–1098
27
- - [A list as a board](#a-list-as-a-board) · lines 1100–1151
28
- - [A list as cards](#a-list-as-cards) · lines 1153–1199
29
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1201–1230
30
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1232–1275
31
- - [An overview page](#an-overview-page) · lines 1277–1340
32
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1341–1379
33
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1381–1426
34
- - [Picking at random](#picking-at-random) · lines 1428–1459
35
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1461–1528
36
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1530–1555
37
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1557–1630
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–734
19
+ - [Written text (notes)](#written-text-notes) · lines 648–734
20
+ - [Density](#density) · lines 736–829
21
+ - [Rows on this device](#rows-on-this-device) · lines 802–829
22
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 831–945
23
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 947–1024
24
+ - [Notices](#notices) · lines 1026–1054
25
+ - [A value over time](#a-value-over-time) · lines 1056–1142
26
+ - [Several values over time](#several-values-over-time) · lines 1105–1142
27
+ - [A list as a board](#a-list-as-a-board) · lines 1144–1195
28
+ - [A list as cards](#a-list-as-cards) · lines 1197–1243
29
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1245–1274
30
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1276–1319
31
+ - [A few equal things](#a-few-equal-things) · lines 1321–1366
32
+ - [An overview page](#an-overview-page) · lines 1368–1431
33
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1432–1470
34
+ - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1472–1517
35
+ - [Picking at random](#picking-at-random) · lines 1519–1550
36
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1552–1619
37
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1621–1646
38
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1648–1721
38
39
 
39
40
  <!-- /index -->
40
41
 
@@ -46,9 +47,9 @@ composites don't grow that way; they are built against a real app's screen.
46
47
 
47
48
  ## Palettes
48
49
 
49
- A palette is an app's own dark look: its surfaces, text, accent and a
50
- second colour, chosen once for every app the foundation serves. There
51
- are four, in the order they were ranked:
50
+ A palette is an app's own look: its surfaces, text, accent and a
51
+ second colour. Four dark ones were chosen once for every app the
52
+ foundation serves, in the order they were ranked:
52
53
 
53
54
  | Name | `palette` | Accent | Second colour |
54
55
  |---|---|---|---|
@@ -57,24 +58,60 @@ are four, in the order they were ranked:
57
58
  | Graphite and Periwinkle | `graphite-periwinkle` | periwinkle on neutral grey | lilac |
58
59
  | Violet | `violet` | violet | magenta |
59
60
 
61
+ And one light one, which an app opts into by name (`LIGHT_PALETTES`):
62
+
63
+ | Name | `palette` | Surface | Text and accent |
64
+ |---|---|---|---|
65
+ | Palm LCD | `palm-lcd` | a Palm OS LCD's green, flat (cards are the same green) | dark ink; ink is also the primary fill and the field border |
66
+
60
67
  **How an app picks one.** `<FoundationProviders palette="indigo-cyan">`
61
68
  names the app's default. Add `palettePicker` and the app shell's header
62
- offers all four (with swatches); the one picked is remembered on that
63
- device, and a new device starts on the default. `usePalette()` reads the
64
- palette on screen. Without `palette`, nothing changes: light and dark
65
- follow the system, with the toggle in the header.
66
-
67
- **A palette is dark only.** With one, the theme is forced dark and the
68
- shell has no light/dark toggle. The light theme stays for apps without a
69
- palette. Printed notes still print light: the print override beats a
70
- palette's block.
69
+ offers the four dark ones (with swatches); the one picked is remembered
70
+ on that device, and a new device starts on the default. `usePalette()`
71
+ reads the palette on screen. Without `palette`, nothing changes: light and
72
+ dark follow the system, with the toggle in the header.
73
+
74
+ **A palette forces its theme.** A dark palette forces the dark theme and
75
+ the shell has no light/dark toggle. The light theme stays for apps
76
+ without a palette, and for Palm LCD. Printed notes still print light:
77
+ the print override beats a palette's block.
78
+
79
+ **Palm LCD is opt-in.** An app gets it only by naming it:
80
+ `<FoundationProviders palette="palm-lcd">`. It forces the light theme, so
81
+ the shell has no toggle. It is never in the picker: `palettePicker` is
82
+ ignored beside it, and so is a palette a device saved before. It has no
83
+ [glow](#glow). Everything is still a semantic token, so the app's code
84
+ uses no raw colours:
85
+
86
+ - **Surfaces.** `--background`, `--card` and `--popover` are the LCD green
87
+ (`#c9d1b2`). `--muted`, `--secondary` and `--accent` are a step darker.
88
+ - **Ink.** `--foreground` is the mockup's ink (`#1d2416`, 10.1:1).
89
+ `--primary` and `--ring` are ink too, with the green on the primary fill,
90
+ as a pressed button looks on the device.
91
+ - **Dimmed text.** `--muted-foreground` is `#464e39`, 5.50:1. The mockup's
92
+ `#5c6650` measured 3.82, under 4.5.
93
+ - **The dotted rules between rows.** The colour is a token: `--rule` and
94
+ `--border` are the LCD's line colour (`#a3ad8f`). The style is the
95
+ app's, a Tailwind border utility: `border-b border-dotted border-rule`.
96
+ A table's own rows wear the colour, solid.
97
+ - **Status text and links.** Status text is a quarter darker than the
98
+ mockup's green, rust and blue, so it still reads on its own tinted wash
99
+ (7.0:1 or more on the green). `--link` is the mockup's blue.
100
+ - **Glyphs and fills.** The light theme's categorical slots, heat steps
101
+ and depth steps were tuned for white, and measure 1.5 to 3 on the
102
+ green. Palm LCD has its own set, each darker than about oklch 0.57, so
103
+ it clears 3:1 on both greens. It keeps the light theme's floors for how
104
+ far apart they must look. Each depth ramp holds its Palm LCD slot's
105
+ hue and gets darker at every step, as in light ([Depth ramps](#depth-ramps)).
106
+ Every heat and depth fill takes white text.
71
107
 
72
108
  **Where it lives.** `styles/theme.css`: each palette's colours as
73
109
  primitives (`--palette-<name>-*`, ratios beside them), and one block per
74
- palette, `.dark[data-palette="<name>"]`, that sets only what differs from
75
- `.dark`. `data-palette` goes on `<html>`, so popups portaled to `<body>`
76
- wear it too. An installed app's colours follow it with
77
- `pwa({ palette })`.
110
+ palette that sets only what differs from its theme:
111
+ `.dark[data-palette="<name>"]` for the four, and `[data-palette="palm-lcd"]`,
112
+ on top of `:root`, for Palm LCD. `data-palette` goes on `<html>`, so popups
113
+ portaled to `<body>` wear it too. An installed app's colours follow it with
114
+ `pwa({ palette })`. For Palm LCD that is the ink and the green.
78
115
 
79
116
  **Why some tokens aren't the guide's colour as written.**
80
117
 
@@ -101,23 +138,28 @@ wear it too. An installed app's colours follow it with
101
138
  palette has, so it is kept as designed; axe doesn't check borders.
102
139
 
103
140
  The package's `e2e/fixtures-visual.spec.ts` runs every primitive,
104
- composite and tone story through axe in each palette, and measures every
105
- glyph, categorical slot and heat step against each palette's page and
106
- card.
141
+ composite and tone story through axe in each palette (Palm LCD in light,
142
+ the others in dark), and measures every glyph, categorical slot, heat
143
+ step and depth step against each palette's page and card.
144
+ `tests/category-slots.test.ts`, `heat-scale.test.ts` and
145
+ `depth-ramps.test.ts` hold Palm LCD's own shades to the light theme's
146
+ floors.
107
147
 
108
148
  **An app's own axe specs** check its palettes instead of light and dark:
109
149
  `defineA11ySuite({ …, palettes: ['indigo-cyan'] })` (and
110
150
  `defineDataEnvironmentBannerSuite`'s `palettes`) saves each as the
111
- device's choice before the page loads and checks it dark. Pass the app's
112
- default on every spec and `PALETTES` on the one that covers the shell.
113
- Without `palettes`, a palette app's light run fails: there is no light
114
- theme to find.
151
+ device's choice before the page loads and checks it in the theme it
152
+ forces: dark, or light for `palettes: ['palm-lcd']`. Pass the app's
153
+ default on every spec and, with the picker, `PALETTES` on the one that
154
+ covers the shell. Without `palettes`, a dark palette app's light run
155
+ fails: there is no light theme to find.
115
156
 
116
157
  ## Glow
117
158
 
118
- Under a palette only, from `--primary` so each palette glows in its own
119
- accent; an app without a palette never gets it. Everything else stays
120
- flat: no glow at the top of the page.
159
+ Under a dark palette only, from `--primary` so each palette glows in its
160
+ own accent. An app without a palette never gets it, and nor does Palm
161
+ LCD, the light one. Everything else stays flat: no glow at the top of the
162
+ page.
121
163
 
122
164
  - **The primary button** (Button's default variant) on hover, keyboard
123
165
  focus and press: one soft layer of the accent (`--primary-glow`: 38px
@@ -489,7 +531,9 @@ slot, as a fill and as a cell, against the page and a card in each.
489
531
  slot, the order of lightness, the distance between neighbours (ΔE 8, and
490
532
  6 with deuteranopia and protanopia), the distance from the neutral greys
491
533
  (6), text on every fill and every step against every palette's card and
492
- raised surface, and fails if a change to `theme.css` breaks one.
534
+ raised surface, and fails if a change to `theme.css` breaks one. Palm LCD,
535
+ the light palette, has its own ramps on the same rules (its slot's hue,
536
+ darker at every step, ΔE 6 from its own greys).
493
537
  `SideBySide` shows both themes at once, each ramp beside its theme's
494
538
  muted greys, under normal vision and simulated deuteranopia and
495
539
  protanopia.
@@ -1274,6 +1318,53 @@ Every one is measured with axe and the glyph check in both themes
1274
1318
  (fixtures `app/ValueList`, `ListHeader`, `Timeline`, `NeedsYou`,
1275
1319
  `Freshness`, `PartEmpty`).
1276
1320
 
1321
+ ## A few equal things
1322
+
1323
+ `EqualItems` (4.93, record standard R10): a small set of equal, related
1324
+ things inside a record (a plan's phases, the stores a price is compared
1325
+ at, a handful of options), one data shape in four looks. A record picks
1326
+ one look per set; a fifth is asked for first.
1327
+
1328
+ ```tsx
1329
+ <EqualItems
1330
+ label="Phases"
1331
+ look="featured"
1332
+ featuredId={currentPhaseId}
1333
+ items={phases.map((phase) => ({
1334
+ id: String(phase.id),
1335
+ title: phase.name,
1336
+ state: { label: 'Current', tone: 'info' },
1337
+ fields: [{ label: 'Weeks', value: phase.weeks }, { label: 'Focus', value: phase.focus }],
1338
+ }))}
1339
+ />
1340
+ ```
1341
+
1342
+ | `look` | Draws | Use it when |
1343
+ |---|---|---|
1344
+ | `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 |
1345
+ | `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) |
1346
+ | `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) |
1347
+ | `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 |
1348
+
1349
+ - **A state is a badge**, the outline style in its tone (`state: 'Planned'`
1350
+ is the neutral one; `{ label, tone }` with `info`, `success`, `warning`
1351
+ or `destructive`). Most states stay neutral ("Mapping an enum to tones").
1352
+ - **A field is the record's row**: the label in label type and muted, the
1353
+ value in body type; an empty value is the record's dash, read as "Not
1354
+ set". `featured` uses the rail's beside rows (field-rows.ts).
1355
+ - **Featured's toggles** are buttons inside headings at the items' level:
1356
+ Enter or Space opens one, Tab moves to the next, several can be open,
1357
+ `aria-expanded` says which. Never a link; `defaultOpenIds` opens some at
1358
+ first.
1359
+ - **Empty**: no items reads `emptyText` ("Nothing yet"), an item with no
1360
+ fields `noFieldsText` ("No details"). `label` names the set for a screen
1361
+ reader (the list's name, the table's caption); titles are `h3` under a
1362
+ section's `h2` (`headingLevel`).
1363
+
1364
+ Measured with axe, the token check and the glyph check in both themes and
1365
+ every palette (fixtures `app/EqualItems`), and from the keyboard and at a
1366
+ phone's width in `e2e/equal-items.spec.ts`.
1367
+
1277
1368
  ## An overview page
1278
1369
 
1279
1370
  The overview standard (4.89): a module's first page when it has three
@@ -46,15 +46,15 @@ function CloseMobileSidebarOnNavigate() {
46
46
  }, [key, setOpenMobile]);
47
47
  return null;
48
48
  }
49
- // The header's look control: an app with a palette is always dark, so it
50
- // has no light/dark toggle, and with the picker on it gets the look menu
49
+ // The header's look control: an app with a palette is always dark (or,
50
+ // with a light palette, always light), so it has no light/dark toggle, and with the picker on it gets the look menu
51
51
  // in its place (design-language.md "Palettes"). With the rows picker the
52
52
  // same menu offers the table rows (design-language.md "Density"); an app
53
53
  // without a palette keeps its toggle beside it.
54
54
  function LookControl() {
55
55
  const { palette, picker } = usePalette();
56
56
  const rows = useRows();
57
- const pickPalette = palette && picker ? palette : null;
57
+ const pickPalette = picker && isPaletteName(palette) ? palette : null;
58
58
  return (_jsxs(_Fragment, { children: [!palette && _jsx(ThemeToggle, {}), (pickPalette || rows.picker) && _jsx(LookMenu, { palette: pickPalette })] }));
59
59
  }
60
60
  // Each palette's swatch is its own background with its accent and second
@@ -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('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[place], editable && cn(editRowClass, '-mx-2 px-2 first:pt-2 last:pb-2')), onClick: editable ? onEditRowClick : undefined, 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, look: "row", children: _jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }) })) : (_jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel })) })] }));
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
@@ -0,0 +1,84 @@
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 reads as `noFieldsText`. */
32
+ fields?: readonly EqualItemField[];
33
+ };
34
+ export type EqualItemsProps = {
35
+ items: readonly EqualItem[];
36
+ /** Defaults to `cards`. */
37
+ look?: EqualItemsLook;
38
+ /**
39
+ * For `look="featured"`: the item shown in full. Defaults to the first
40
+ * one; an id that matches none falls back to the first too.
41
+ */
42
+ featuredId?: string;
43
+ /**
44
+ * For `look="featured"`: the other items open when it first shows.
45
+ * Each toggle opens and closes on its own after that.
46
+ */
47
+ defaultOpenIds?: readonly string[];
48
+ /** The set's name for screen readers ("Phases"); the table's caption. */
49
+ label: string;
50
+ /** The items' heading level: 3 (the default) under a section's h2. */
51
+ headingLevel?: 3 | 4 | 5;
52
+ /** For `look="table"`: the first column's heading. Defaults to "Name". */
53
+ titleColumn?: string;
54
+ /** For `look="table"`: the state column's heading. Defaults to "Status". */
55
+ stateColumn?: string;
56
+ /** What no items says. Defaults to "Nothing yet". */
57
+ emptyText?: string;
58
+ /** What an item with no fields says. Defaults to "No details". */
59
+ noFieldsText?: string;
60
+ className?: string;
61
+ };
62
+ /**
63
+ * A few equal, related things inside a record view (record page standard
64
+ * R10): one data shape, four looks.
65
+ *
66
+ * ```tsx
67
+ * <EqualItems
68
+ * label="Phases"
69
+ * look="featured"
70
+ * featuredId="p2"
71
+ * items={[
72
+ * { id: 'p1', title: 'Phase 1', state: { label: 'Done', tone: 'success' }, fields: [{ label: 'Weeks', value: '1–4' }] },
73
+ * { id: 'p2', title: 'Phase 2', state: { label: 'Current', tone: 'info' }, fields: [{ label: 'Weeks', value: '5–8' }] },
74
+ * { id: 'p3', title: 'Phase 3', state: 'Planned', fields: [{ label: 'Weeks', value: '9–12' }] },
75
+ * ]}
76
+ * />
77
+ * ```
78
+ *
79
+ * `cards` for a few things with little to say about each, `table` for
80
+ * things compared on the same values, `featured` when one is current or
81
+ * best, `panels` when each has several details and must read as separate
82
+ * (design-language.md "A few equal things").
83
+ */
84
+ export declare function EqualItems({ items, look, featuredId, defaultOpenIds, label, headingLevel, titleColumn, stateColumn, emptyText, noFieldsText, className, }: EqualItemsProps): import("react").JSX.Element;
@@ -0,0 +1,127 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } 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
+ import { useState } from 'react';
26
+ import { ChevronDownIcon } from 'lucide-react';
27
+ import { cn } from 'cn';
28
+ import { Badge } from '../ui/badge.js';
29
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible.js';
30
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../ui/table.js';
31
+ import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
32
+ import { EmptyText } from './empty-value.js';
33
+ import { FIELD_LABEL, FIELD_ROW, FIELD_ROW_BASE, FIELD_VALUE } from './field-rows.js';
34
+ const TONE_BADGE = {
35
+ neutral: 'outline',
36
+ info: 'outline-info',
37
+ success: 'outline-success',
38
+ warning: 'outline-warning',
39
+ destructive: 'outline-destructive',
40
+ };
41
+ const stateOf = (state) => state === undefined || state === '' ? undefined : typeof state === 'string' ? { label: state } : state;
42
+ function StateBadge({ state }) {
43
+ const value = stateOf(state);
44
+ if (!value)
45
+ return null;
46
+ return (_jsx(Badge, { "data-slot": "equal-item-state", variant: TONE_BADGE[value.tone ?? 'neutral'], children: value.label }));
47
+ }
48
+ function Value({ value }) {
49
+ return isEmptyValue(value) ? _jsx(EmptyText, { text: EMPTY_DASH }) : value;
50
+ }
51
+ // The item's fields. `beside` is the rail's rows (field-rows.ts): the
52
+ // label left of its value from an 18rem list (a featured item, an open
53
+ // toggle), stacked in a narrower one. `stacked` keeps every label above its
54
+ // value (panels). `compact` is a card's: label and value on one line, no
55
+ // rules between, for a few short facts.
56
+ function Fields({ fields, noFieldsText, rows, }) {
57
+ if (!fields || fields.length === 0) {
58
+ return _jsx("p", { className: "type-body text-muted-foreground", children: noFieldsText });
59
+ }
60
+ if (rows === 'compact') {
61
+ 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}`))) }));
62
+ }
63
+ 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}`))) }));
64
+ }
65
+ function Title({ item, level, className }) {
66
+ const Heading = `h${level}`;
67
+ return (_jsxs("div", { className: cn('flex min-w-0 flex-wrap items-center gap-x-2 gap-y-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 })] }));
68
+ }
69
+ function Cards({ items, label, level, noFieldsText }) {
70
+ 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", className: "flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-card p-4 text-card-foreground", children: [_jsx(Title, { item: item, level: level }), _jsx(Fields, { fields: item.fields, noFieldsText: noFieldsText, rows: "compact" })] }, item.id))) }));
71
+ }
72
+ function Panels({ items, label, level, noFieldsText }) {
73
+ 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", className: "flex min-w-0 flex-col overflow-hidden rounded-lg border border-border bg-card text-card-foreground", children: [_jsx(Title, { item: item, level: level, className: "border-b border-border bg-muted/40 px-4 py-3" }), _jsx("div", { className: "px-4 py-3", children: _jsx(Fields, { fields: item.fields, noFieldsText: noFieldsText, rows: "stacked" }) })] }, item.id))) }));
74
+ }
75
+ // One column per field label, in the order the items first give them; an
76
+ // item without one reads as a dash there. The title is each row's header.
77
+ function ItemsTable({ items, label, titleColumn, stateColumn, }) {
78
+ const columns = [];
79
+ for (const item of items)
80
+ for (const field of item.fields ?? [])
81
+ if (!columns.includes(field.label))
82
+ columns.push(field.label);
83
+ const hasState = items.some((item) => stateOf(item.state));
84
+ return (_jsx("div", { "data-slot": "equal-items-table", className: "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)))] }) }), _jsx(TableBody, { className: "[&_tr:nth-child(even)]:bg-transparent", children: items.map((item) => (_jsxs(TableRow, { "data-slot": "equal-item", 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)))] }, item.id))) })] }) }));
85
+ }
86
+ function Featured({ items, label, level, noFieldsText, featuredId, defaultOpenIds, }) {
87
+ const featured = items.find((item) => item.id === featuredId) ?? items[0];
88
+ const rest = items.filter((item) => item !== featured);
89
+ 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(Fields, { fields: featured.fields, 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))) }))] }));
90
+ }
91
+ // A heading holding its button (the disclosure pattern): Enter and Space
92
+ // open and close it, Tab moves on to the next, and the button says
93
+ // whether it's open. Each opens on its own, so several can be open.
94
+ function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
95
+ const [open, setOpen] = useState(defaultOpen);
96
+ const Heading = `h${level}`;
97
+ return (_jsx("li", { "data-slot": "equal-item", children: _jsxs(Collapsible, { open: open, onOpenChange: setOpen, children: [_jsx(Heading, { className: "m-0", 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(CollapsibleContent, { className: "px-4 pt-1 pb-4 pl-10", children: _jsx(Fields, { fields: item.fields, noFieldsText: noFieldsText, rows: "beside" }) })] }) }));
98
+ }
99
+ /**
100
+ * A few equal, related things inside a record view (record page standard
101
+ * R10): one data shape, four looks.
102
+ *
103
+ * ```tsx
104
+ * <EqualItems
105
+ * label="Phases"
106
+ * look="featured"
107
+ * featuredId="p2"
108
+ * items={[
109
+ * { id: 'p1', title: 'Phase 1', state: { label: 'Done', tone: 'success' }, fields: [{ label: 'Weeks', value: '1–4' }] },
110
+ * { id: 'p2', title: 'Phase 2', state: { label: 'Current', tone: 'info' }, fields: [{ label: 'Weeks', value: '5–8' }] },
111
+ * { id: 'p3', title: 'Phase 3', state: 'Planned', fields: [{ label: 'Weeks', value: '9–12' }] },
112
+ * ]}
113
+ * />
114
+ * ```
115
+ *
116
+ * `cards` for a few things with little to say about each, `table` for
117
+ * things compared on the same values, `featured` when one is current or
118
+ * best, `panels` when each has several details and must read as separate
119
+ * (design-language.md "A few equal things").
120
+ */
121
+ export function EqualItems({ items, look = 'cards', featuredId, defaultOpenIds, label, headingLevel = 3, titleColumn = 'Name', stateColumn = 'Status', emptyText = 'Nothing yet', noFieldsText = 'No details', className, }) {
122
+ if (items.length === 0) {
123
+ return (_jsx("p", { "data-slot": "equal-items", "data-look": look, "data-state": "empty", className: cn('type-body text-muted-foreground', className), children: emptyText }));
124
+ }
125
+ const shared = { items, label, level: headingLevel, noFieldsText };
126
+ 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 })) : look === 'featured' ? (_jsx(Featured, { ...shared, featuredId: featuredId, defaultOpenIds: defaultOpenIds })) : look === 'panels' ? (_jsx(Panels, { ...shared })) : (_jsx(Cards, { ...shared })) }));
127
+ }
@@ -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';