@tristan2828/ui-foundation 4.92.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.
- package/conventions/docs/add-an-entity.md +17 -11
- package/conventions/docs/design-language.md +80 -32
- package/dist/components/app/entity-view.js +2 -14
- package/dist/components/app/equal-items.d.ts +84 -0
- package/dist/components/app/equal-items.js +127 -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–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
|
|
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–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
|
|
|
@@ -1317,6 +1318,53 @@ Every one is measured with axe and the glyph check in both themes
|
|
|
1317
1318
|
(fixtures `app/ValueList`, `ListHeader`, `Timeline`, `NeedsYou`,
|
|
1318
1319
|
`Freshness`, `PartEmpty`).
|
|
1319
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
|
+
|
|
1320
1368
|
## An overview page
|
|
1321
1369
|
|
|
1322
1370
|
The overview standard (4.89): a module's first page when it has three
|
|
@@ -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
|
|
@@ -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';
|
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.93.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": {
|