@tristan2828/ui-foundation 4.75.0 → 4.76.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 +20 -9
- package/conventions/docs/design-language.md +73 -26
- package/dist/components/app/entity-view.d.ts +31 -1
- package/dist/components/app/entity-view.js +77 -10
- package/dist/components/ui/tabs.d.ts +10 -0
- package/dist/components/ui/tabs.js +28 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/lib/entity-view-tab.d.ts +2 -0
- package/dist/lib/entity-view-tab.js +11 -0
- package/package.json +1 -1
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
- Step 8: Add Playwright specs for all three screens · lines 686–764
|
|
16
16
|
- Step 9: Register the nav entry and route names · lines 765–779
|
|
17
17
|
- Step 10: `npm run verify`. · lines 780–782
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines 784–
|
|
19
|
-
- [The record view](#the-record-view) · lines 897–
|
|
20
|
-
- [What not to copy](#what-not-to-copy) · lines
|
|
21
|
-
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines
|
|
22
|
-
- [Deleting](#deleting) · lines
|
|
23
|
-
- [Fields only a script writes](#fields-only-a-script-writes) · lines
|
|
24
|
-
- [Searching one part of the app](#searching-one-part-of-the-app) · lines
|
|
25
|
-
- [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 784–933
|
|
19
|
+
- [The record view](#the-record-view) · lines 897–933
|
|
20
|
+
- [What not to copy](#what-not-to-copy) · lines 935–961
|
|
21
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 963–980
|
|
22
|
+
- [Deleting](#deleting) · lines 982–1011
|
|
23
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1013–1034
|
|
24
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1036–1045
|
|
25
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1048–1087
|
|
26
26
|
|
|
27
27
|
<!-- /index -->
|
|
28
28
|
|
|
@@ -903,7 +903,9 @@ view reaches them all. A record uses the parts it has, in this order:
|
|
|
903
903
|
- **Header**: the title, edited in place (`titleEdit`); under it a
|
|
904
904
|
one-line summary field, edited in place (`subtitle`: a goal, a
|
|
905
905
|
description); beside it the status as a quick action (a picker saved
|
|
906
|
-
at once) and other status-like fields as badges, edited in place.
|
|
906
|
+
at once) and other status-like fields as badges, edited in place. A
|
|
907
|
+
record with a face or a mark of its own (a person's avatar, a
|
|
908
|
+
service's logo, a cover) puts it left of all that (`leading`, 4.76).
|
|
907
909
|
`actions` holds Delete (soft, with Undo) and the record's own commands
|
|
908
910
|
(Run, Print), never Edit.
|
|
909
911
|
- **Strip**: the record's key numbers and ratings (`strip`, a
|
|
@@ -915,6 +917,15 @@ view reaches them all. A record uses the parts it has, in this order:
|
|
|
915
917
|
Outline for a long one and Print notes (`print`). Without long text,
|
|
916
918
|
one column. Every value edited in place (`edit`), a sub-item list
|
|
917
919
|
included (`editInPlace({ kind: 'list' })`).
|
|
920
|
+
- **Tabs** (4.76), for a main column with **three or more groups of
|
|
921
|
+
long content** (the steps, where it's used, the reasoning): a `tab` on
|
|
922
|
+
each main section groups them under a tab list, the selected one in
|
|
923
|
+
`?tab=`. Fewer groups stay one scroll, folded by headings. A record's
|
|
924
|
+
Notes stay outside the tabs, above them, unless they are one tab's
|
|
925
|
+
content; the rail and the strip never go in a tab.
|
|
926
|
+
- **Rail fields beside their labels** (`railFields="beside"`, 4.76) for
|
|
927
|
+
a rail of many short facts, so it reads as a list of pairs rather than
|
|
928
|
+
a column of labels; keep labels to a word or two.
|
|
918
929
|
- **A big record's own parts** (a drawing, a player, a checklist of
|
|
919
930
|
documents) are sections in the view, not a screen of their own.
|
|
920
931
|
|
|
@@ -3,32 +3,33 @@
|
|
|
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
|
-
- [A stored colour](#a-stored-colour) · lines
|
|
16
|
-
- [Shapes and sizes](#shapes-and-sizes) · lines
|
|
17
|
-
- [Typography](#typography) · lines
|
|
18
|
-
- [Written text (notes)](#written-text-notes) · lines
|
|
19
|
-
- [Density](#density) · lines
|
|
20
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
21
|
-
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines
|
|
22
|
-
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines
|
|
23
|
-
- [Notices](#notices) · lines
|
|
24
|
-
- [A value over time](#a-value-over-time) · lines
|
|
25
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
26
|
-
- [A list as a board](#a-list-as-a-board) · lines
|
|
27
|
-
- [A list as cards](#a-list-as-cards) · lines
|
|
28
|
-
- [Key numbers on a record](#key-numbers-on-a-record) · lines
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
6
|
+
- [Palettes](#palettes) · lines 42–109
|
|
7
|
+
- [Glow](#glow) · lines 111–129
|
|
8
|
+
- [Semantic tones](#semantic-tones) · lines 131–159
|
|
9
|
+
- [The three badge styles](#the-three-badge-styles) · lines 161–178
|
|
10
|
+
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 180–209
|
|
11
|
+
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 211–224
|
|
12
|
+
- [Logos and brand marks](#logos-and-brand-marks) · lines 226–270
|
|
13
|
+
- [Categorical colour](#categorical-colour) · lines 272–342
|
|
14
|
+
- [Heat scale](#heat-scale) · lines 344–405
|
|
15
|
+
- [A stored colour](#a-stored-colour) · lines 407–455
|
|
16
|
+
- [Shapes and sizes](#shapes-and-sizes) · lines 457–478
|
|
17
|
+
- [Typography](#typography) · lines 480–586
|
|
18
|
+
- [Written text (notes)](#written-text-notes) · lines 514–586
|
|
19
|
+
- [Density](#density) · lines 588–674
|
|
20
|
+
- [Rows on this device](#rows-on-this-device) · lines 647–674
|
|
21
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 676–790
|
|
22
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 792–869
|
|
23
|
+
- [Notices](#notices) · lines 871–899
|
|
24
|
+
- [A value over time](#a-value-over-time) · lines 901–987
|
|
25
|
+
- [Several values over time](#several-values-over-time) · lines 950–987
|
|
26
|
+
- [A list as a board](#a-list-as-a-board) · lines 989–1040
|
|
27
|
+
- [A list as cards](#a-list-as-cards) · lines 1042–1088
|
|
28
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1090–1112
|
|
29
|
+
- [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1114–1158
|
|
30
|
+
- [Picking at random](#picking-at-random) · lines 1160–1191
|
|
31
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1193–1260
|
|
32
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1262–1287
|
|
32
33
|
|
|
33
34
|
<!-- /index -->
|
|
34
35
|
|
|
@@ -1110,6 +1111,52 @@ row under the header, across the page at every width.
|
|
|
1110
1111
|
- **`subtitle`** is the line under the title: what the record is for,
|
|
1111
1112
|
in muted body type, editable in place like any value.
|
|
1112
1113
|
|
|
1114
|
+
## A record's tabs, mark and rail
|
|
1115
|
+
|
|
1116
|
+
Three opt-ins on `EntityView` (4.76), each for a record that needs it;
|
|
1117
|
+
a record without them is as it was.
|
|
1118
|
+
|
|
1119
|
+
```tsx
|
|
1120
|
+
<EntityView
|
|
1121
|
+
layout="rail"
|
|
1122
|
+
mobileOrder="main-first"
|
|
1123
|
+
leading={<img src={photo} alt="" className="size-12 rounded-full object-cover" />}
|
|
1124
|
+
railFields="beside"
|
|
1125
|
+
sections={[
|
|
1126
|
+
{ title: 'Summary', placement: 'rail', fields },
|
|
1127
|
+
{ title: 'Notes', content: <Markdown>{notes}</Markdown> },
|
|
1128
|
+
{ title: 'Steps', tab: 'Steps', content: steps },
|
|
1129
|
+
{ title: 'Where it applies', tab: 'Used in', content: uses },
|
|
1130
|
+
{ title: 'Why this order', tab: 'Reasoning', content: reasoning },
|
|
1131
|
+
]}
|
|
1132
|
+
… />
|
|
1133
|
+
```
|
|
1134
|
+
|
|
1135
|
+
- **Tabs** (`tab` on a main section): a line tab list at the top of
|
|
1136
|
+
the main column, under the strip and any sections with no tab, one
|
|
1137
|
+
tab per name in the order the sections first give it. The selected
|
|
1138
|
+
tab has foreground text and a 2px underline, the others muted text;
|
|
1139
|
+
the list's own bottom border runs the column's width. On a phone each
|
|
1140
|
+
tab is 44px tall, and a list wider than the column scrolls sideways on
|
|
1141
|
+
its own, never the page. Arrow keys move between tabs and select
|
|
1142
|
+
(Home, End), and Tab goes on into the panel. The address holds the
|
|
1143
|
+
selected tab (`?tab=used-in`, `entityViewTabSlug`), replaced rather
|
|
1144
|
+
than pushed, so Back leaves the record, not the tab. Every tab's
|
|
1145
|
+
sections stay mounted, so a value open in place survives a switch.
|
|
1146
|
+
Short tab names, one or two words; no counts or icons in them yet.
|
|
1147
|
+
- **A mark or avatar** (`leading`): left of the title, top-aligned,
|
|
1148
|
+
with the title, subtitle and badges beside it at every width. 40 to
|
|
1149
|
+
64px (`size-10` to `size-16`): an avatar round (`rounded-full`), a
|
|
1150
|
+
mark or cover in a rounded square (`rounded-lg`). Decorative, since
|
|
1151
|
+
the title names the record (`alt=""`, `aria-hidden`); initials in
|
|
1152
|
+
foreground on `bg-muted`, an icon in muted foreground on the card
|
|
1153
|
+
with its border. "Logos and brand marks" above holds for a logo here.
|
|
1154
|
+
- **Rail fields beside** (`railFields="beside"`): the label in a 6 to
|
|
1155
|
+
7rem column left of its value, baseline-aligned, rows a little tighter
|
|
1156
|
+
than stacked. Where the rail's list is under 18rem (a phone narrower
|
|
1157
|
+
than ~350px) it stacks as before, and once the rail stacks full width
|
|
1158
|
+
the label column widens to the page's.
|
|
1159
|
+
|
|
1113
1160
|
## Picking at random
|
|
1114
1161
|
|
|
1115
1162
|
`SpinWheel` (4.42) picks one of a few candidates by chance, for "what do
|
|
@@ -59,6 +59,14 @@ export type EntityViewSection = ({
|
|
|
59
59
|
print?: boolean | {
|
|
60
60
|
answerSpace?: boolean;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* The tab the section goes under, by name ("Steps", "Used in"): main
|
|
64
|
+
* sections only (a `rail` one ignores it). Any main section with a tab
|
|
65
|
+
* adds a tab list to the main column, one tab per name in the order the
|
|
66
|
+
* sections first give it; sections without one stay above the list. The
|
|
67
|
+
* selected tab is in the address, `?tab=<slug of the name>`.
|
|
68
|
+
*/
|
|
69
|
+
tab?: string;
|
|
62
70
|
};
|
|
63
71
|
export type EntityViewPlacement = 'main' | 'rail';
|
|
64
72
|
/**
|
|
@@ -72,6 +80,12 @@ export type EntityViewLayout = 'column' | 'rail';
|
|
|
72
80
|
* or a narrow content area): `rail-first` (the default) or `main-first`.
|
|
73
81
|
*/
|
|
74
82
|
export type EntityViewMobileOrder = 'rail-first' | 'main-first';
|
|
83
|
+
/**
|
|
84
|
+
* How a rail section's fields lay out: `stacked` (the default), each label
|
|
85
|
+
* above its value; `beside`, the label to the left of its value, stacked
|
|
86
|
+
* where the rail's list is narrower than 18rem (a small phone).
|
|
87
|
+
*/
|
|
88
|
+
export type EntityViewRailFields = 'stacked' | 'beside';
|
|
75
89
|
export type EntityViewProps = {
|
|
76
90
|
/** The record's name or title, the page's <h1>, and the browser tab's once it loads (`documentTitle`). */
|
|
77
91
|
title?: string;
|
|
@@ -86,6 +100,14 @@ export type EntityViewProps = {
|
|
|
86
100
|
titleEdit?: EditInPlace & {
|
|
87
101
|
label: string;
|
|
88
102
|
};
|
|
103
|
+
/**
|
|
104
|
+
* Left of the title, top-aligned with it: the record's mark or avatar
|
|
105
|
+
* (an image, an icon, initials), at a size of the screen's own choosing
|
|
106
|
+
* (`size-10` to `size-16`). The title, subtitle and badges sit beside it
|
|
107
|
+
* at every width. Decorative unless it says something the title doesn't:
|
|
108
|
+
* give an image `alt=""`.
|
|
109
|
+
*/
|
|
110
|
+
leading?: ReactNode;
|
|
89
111
|
/**
|
|
90
112
|
* A line under the title, in muted body type: what the record is for (a
|
|
91
113
|
* goal, a one-line summary). Any markup, an `<EditableValue>` included,
|
|
@@ -134,6 +156,14 @@ export type EntityViewProps = {
|
|
|
134
156
|
printLabel?: string;
|
|
135
157
|
/** The rail's landmark name (its `<aside>`). Defaults to the title + " details". */
|
|
136
158
|
railLabel?: string;
|
|
159
|
+
/**
|
|
160
|
+
* In the `rail` layout, a rail section's fields: each label above its
|
|
161
|
+
* value (`stacked`, the default), or to its left (`beside`), falling back
|
|
162
|
+
* to stacked where the rail is too narrow for both. Once the rail's
|
|
163
|
+
* sections stack full width on a narrower screen, labels sit beside
|
|
164
|
+
* values either way.
|
|
165
|
+
*/
|
|
166
|
+
railFields?: EntityViewRailFields;
|
|
137
167
|
isLoading: boolean;
|
|
138
168
|
/** A `notfound` error (including another user's record) shows "Not found" and a way back, never a retry. */
|
|
139
169
|
error?: AppError | null;
|
|
@@ -144,4 +174,4 @@ export type EntityViewProps = {
|
|
|
144
174
|
label: string;
|
|
145
175
|
};
|
|
146
176
|
};
|
|
147
|
-
export declare function EntityView({ title, documentTitle, titleEdit, subtitle, badges, actions, notice, strip, sections, footer, layout, mobileOrder, railLabel, printLabel, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|
|
177
|
+
export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, mobileOrder, railLabel, railFields, printLabel, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|
|
@@ -55,8 +55,24 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
55
55
|
// it for: notes, a checklist). The DOM is in that order at every width, so
|
|
56
56
|
// reading and tab order match the screen: beside each other, the columns'
|
|
57
57
|
// places come from the grid, not the DOM.
|
|
58
|
+
//
|
|
59
|
+
// Tabs (4.76, #303): a main section with a `tab` goes under a tab list at
|
|
60
|
+
// the top of the main column, one tab per distinct name in the order the
|
|
61
|
+
// sections first give it, and only the selected tab's sections show. The
|
|
62
|
+
// rest of the main column stays above the list, and the rail always shows.
|
|
63
|
+
// The selected tab is `?tab=<slug>` (the history entry replaced, its state
|
|
64
|
+
// kept, so a record over its list stays the dialog); the first tab is the
|
|
65
|
+
// bare address, and an unknown slug reads as the first. Every tab's
|
|
66
|
+
// sections stay mounted, hidden, so a field open in place survives a
|
|
67
|
+
// switch. With no `tab` on any section, nothing changes.
|
|
68
|
+
//
|
|
69
|
+
// `leading`, left of the title: the record's mark or avatar, with the
|
|
70
|
+
// title, subtitle and badges beside it at every width. `railFields`
|
|
71
|
+
// `beside` puts a rail field's label to the left of its value, as in an
|
|
72
|
+
// issue tracker's sidebar, stacked again where the rail's list is too
|
|
73
|
+
// narrow for both.
|
|
58
74
|
import { useEffect, useId, useState, useSyncExternalStore } from 'react';
|
|
59
|
-
import { Link } from 'react-router';
|
|
75
|
+
import { Link, useLocation, useNavigate } from 'react-router';
|
|
60
76
|
import { ArrowLeftIcon, SearchXIcon } from 'lucide-react';
|
|
61
77
|
import { cn } from 'cn';
|
|
62
78
|
import { ErrorState } from './error-state.js';
|
|
@@ -64,6 +80,7 @@ import { Button } from '../ui/button.js';
|
|
|
64
80
|
import { Card, CardContent, CardHeader } from '../ui/card.js';
|
|
65
81
|
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, } from '../ui/empty.js';
|
|
66
82
|
import { Skeleton } from '../ui/skeleton.js';
|
|
83
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from '../ui/tabs.js';
|
|
67
84
|
import { useDocumentTitle } from '../../hooks/use-document-title.js';
|
|
68
85
|
import { PrintNotes } from './entity-view-print.js';
|
|
69
86
|
import { EditInPlaceContext } from './edit-in-place.js';
|
|
@@ -71,6 +88,7 @@ import { EditInPlaceStore } from './edit-in-place-store.js';
|
|
|
71
88
|
import { EditableList } from './editable-list.js';
|
|
72
89
|
import { EditableValue, LeaveGuard } from './editable-value.js';
|
|
73
90
|
import { useRecordDialog } from './record-dialog-context.js';
|
|
91
|
+
import { entityViewTabSlug } from '../../lib/entity-view-tab.js';
|
|
74
92
|
const DEFAULT_EMPTY_LABEL = 'Not set';
|
|
75
93
|
function isEmptyValue(value) {
|
|
76
94
|
return (value === null ||
|
|
@@ -90,18 +108,22 @@ function orEmptyLabel(value, emptyLabel) {
|
|
|
90
108
|
// the rail the list's own width decides instead (a container query on the
|
|
91
109
|
// <dl>): label above value in the narrow rail, beside it once the rail's
|
|
92
110
|
// sections stack full width under the header.
|
|
111
|
+
// `railFields="beside"` (4.76) puts them side by side in the rail too,
|
|
112
|
+
// from an 18rem list (a rail card beside the main column is ~19rem
|
|
113
|
+
// inside), with a narrower label column, and stacked below that.
|
|
93
114
|
const FIELD_ROW = {
|
|
94
115
|
page: 'sm:grid sm:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] sm:gap-6',
|
|
95
116
|
rail: '@lg/fields:grid @lg/fields:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] @lg/fields:gap-6',
|
|
117
|
+
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',
|
|
96
118
|
};
|
|
97
|
-
function FieldRow({ field,
|
|
119
|
+
function FieldRow({ field, place }) {
|
|
98
120
|
// A preset shows its own value unless the screen gives one.
|
|
99
121
|
const value = field.value !== undefined ? field.value : field.edit?.shown;
|
|
100
|
-
return (_jsxs("div", { className: cn('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[
|
|
122
|
+
return (_jsxs("div", { className: cn('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[place]), children: [_jsx("dt", { className: "type-label text-muted-foreground", children: field.label }), _jsx("dd", { className: "min-w-0 type-body break-words text-foreground", children: field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, children: orEmptyLabel(value, field.emptyLabel) })) : (orEmptyLabel(value, field.emptyLabel)) })] }));
|
|
101
123
|
}
|
|
102
|
-
function ViewSection({ section, inRail = false }) {
|
|
124
|
+
function ViewSection({ section, inRail = false, railFields = 'stacked', }) {
|
|
103
125
|
const headingId = useId();
|
|
104
|
-
return (_jsx("section", { "aria-labelledby": headingId, children: _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx("h2", { id: headingId, className: "type-section-title text-foreground", children: section.title }) }), _jsx(CardContent, { children: 'fields' in section ? (_jsx("dl", { className: cn('flex flex-col divide-y divide-border', inRail && '@container/fields'), children: section.fields.map((field) => (_jsx(FieldRow, { field: field,
|
|
126
|
+
return (_jsx("section", { "aria-labelledby": headingId, children: _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx("h2", { id: headingId, className: "type-section-title text-foreground", children: section.title }) }), _jsx(CardContent, { children: 'fields' in section ? (_jsx("dl", { className: cn('flex flex-col divide-y divide-border', inRail && '@container/fields'), children: section.fields.map((field) => (_jsx(FieldRow, { field: field, place: !inRail ? 'page' : railFields === 'beside' ? 'railBeside' : 'rail' }, field.label))) })) : section.edit?.kind === 'list' ? (_jsxs("div", { className: "flex min-w-0 flex-col gap-2 type-body break-words text-foreground", children: [!isEmptyValue(section.content) && section.content, _jsx(EditableList, { label: section.title, edit: section.edit, emptyLabel: section.emptyLabel ?? DEFAULT_EMPTY_LABEL })] })) : (_jsx("div", { className: "min-w-0 type-body break-words text-foreground", children: section.edit ? (_jsx(EditableValue, { label: section.title, edit: section.edit, children: orEmptyLabel(section.content, section.emptyLabel) })) : (orEmptyLabel(section.content, section.emptyLabel)) })) })] }) }));
|
|
105
127
|
}
|
|
106
128
|
// The rail layout's columns. The view is a container, so the switch to
|
|
107
129
|
// two columns follows the width the page actually has (the sidebar open
|
|
@@ -157,11 +179,48 @@ function useFitsWindow() {
|
|
|
157
179
|
}, [element]);
|
|
158
180
|
return [setElement, fits];
|
|
159
181
|
}
|
|
160
|
-
function Rail({ label, sections }) {
|
|
182
|
+
function Rail({ label, sections, fields, }) {
|
|
161
183
|
const [ref, fits] = useFitsWindow();
|
|
162
|
-
return (_jsx("aside", { ref: ref, "aria-label": label, "data-fits": fits ? '' : undefined, className: cn(RAIL_LAYOUT.rail, RAIL_LAYOUT.sticky, 'flex min-w-0 flex-col gap-6'), children: sections.map((section) => (_jsx(ViewSection, { section: section, inRail: true }, section.title))) }));
|
|
184
|
+
return (_jsx("aside", { ref: ref, "aria-label": label, "data-fits": fits ? '' : undefined, className: cn(RAIL_LAYOUT.rail, RAIL_LAYOUT.sticky, 'flex min-w-0 flex-col gap-6'), children: sections.map((section) => (_jsx(ViewSection, { section: section, inRail: true, railFields: fields }, section.title))) }));
|
|
185
|
+
}
|
|
186
|
+
const TAB_PARAM = 'tab';
|
|
187
|
+
// The main sections' tabs, in the order the sections first name them. Two
|
|
188
|
+
// names with one slug ("Notes", "notes") are one tab, under the first.
|
|
189
|
+
function tabsOf(sections) {
|
|
190
|
+
const tabs = [];
|
|
191
|
+
for (const section of sections) {
|
|
192
|
+
if (section.tab === undefined)
|
|
193
|
+
continue;
|
|
194
|
+
const slug = entityViewTabSlug(section.tab);
|
|
195
|
+
const tab = tabs.find((each) => each.slug === slug);
|
|
196
|
+
if (tab)
|
|
197
|
+
tab.sections.push(section);
|
|
198
|
+
else
|
|
199
|
+
tabs.push({ slug, name: section.tab, sections: [section] });
|
|
200
|
+
}
|
|
201
|
+
return tabs;
|
|
202
|
+
}
|
|
203
|
+
// The tab list, under the sections with no tab, and every tab's sections
|
|
204
|
+
// (hidden but mounted unless selected). The selected tab is the address's,
|
|
205
|
+
// changed in place: the entry replaced, its state kept (a record over its
|
|
206
|
+
// list stays the dialog), the scroll where it was.
|
|
207
|
+
function MainTabs({ tabs, label }) {
|
|
208
|
+
const location = useLocation();
|
|
209
|
+
const navigate = useNavigate();
|
|
210
|
+
const asked = new URLSearchParams(location.search).get(TAB_PARAM);
|
|
211
|
+
const selected = tabs.find((tab) => tab.slug === asked)?.slug ?? tabs[0].slug;
|
|
212
|
+
const select = (slug) => {
|
|
213
|
+
const params = new URLSearchParams(location.search);
|
|
214
|
+
if (slug === tabs[0].slug)
|
|
215
|
+
params.delete(TAB_PARAM);
|
|
216
|
+
else
|
|
217
|
+
params.set(TAB_PARAM, slug);
|
|
218
|
+
const search = params.toString();
|
|
219
|
+
void navigate({ pathname: location.pathname, search: search ? `?${search}` : '', hash: location.hash }, { replace: true, state: location.state, preventScrollReset: true });
|
|
220
|
+
};
|
|
221
|
+
return (_jsxs(Tabs, { value: selected, onValueChange: (value) => select(String(value)), "data-slot": "entity-view-tabs", className: "min-w-0 gap-6", children: [_jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-1 overflow-x-auto overflow-y-hidden border-b border-border p-0 [scrollbar-width:thin]", children: tabs.map((tab) => (_jsx(TabsTrigger, { value: tab.slug, className: "h-9 flex-none px-3 text-muted-foreground group-data-horizontal/tabs:after:bottom-0 pointer-coarse:h-11 dark:text-muted-foreground", children: tab.name }, tab.slug))) }), tabs.map((tab) => (_jsx(TabsContent, { value: tab.slug, keepMounted: true, className: "flex min-w-0 flex-col gap-6 [font-size:inherit]", children: tab.sections.map((section) => (_jsx(ViewSection, { section: section }, section.title))) }, tab.slug)))] }));
|
|
163
222
|
}
|
|
164
|
-
export function EntityView({ title, documentTitle, titleEdit, subtitle, badges, actions, notice, strip, sections, footer, layout = 'column', mobileOrder = 'rail-first', railLabel, printLabel = 'Print notes', isLoading, error, onRetry, back, }) {
|
|
223
|
+
export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'column', mobileOrder = 'rail-first', railLabel, railFields = 'stacked', printLabel = 'Print notes', isLoading, error, onRetry, back, }) {
|
|
165
224
|
// Editing in place: one store per view, and the leave-page prompt only
|
|
166
225
|
// while a field is open (or one is always editable).
|
|
167
226
|
const [store] = useState(() => new EditInPlaceStore());
|
|
@@ -196,6 +255,14 @@ export function EntityView({ title, documentTitle, titleEdit, subtitle, badges,
|
|
|
196
255
|
const printButton = printSections.length > 0 && (_jsx(PrintNotes, { label: printLabel, title: title, subtitle: subtitle, sections: printSections }));
|
|
197
256
|
const railSections = sections.filter((section) => section.placement === 'rail');
|
|
198
257
|
const mainSections = sections.filter((section) => section.placement !== 'rail');
|
|
199
|
-
|
|
200
|
-
|
|
258
|
+
// Tabs: a main section's `tab` (a rail one's is ignored, in either layout).
|
|
259
|
+
const tabs = tabsOf(mainSections);
|
|
260
|
+
const tabbed = (section) => section.placement !== 'rail' && section.tab !== undefined;
|
|
261
|
+
const tabList = tabs.length > 0 && _jsx(MainTabs, { tabs: tabs, label: `${title ?? 'Record'} sections` });
|
|
262
|
+
const main = (_jsxs("div", { className: cn(RAIL_LAYOUT.main, railSections.length === 0 && RAIL_LAYOUT.mainAlone), children: [mainSections
|
|
263
|
+
.filter((section) => !tabbed(section))
|
|
264
|
+
.map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
|
|
265
|
+
return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsxs("div", { className: layout === 'rail' ? RAIL_LAYOUT.page : 'flex max-w-4xl flex-col gap-6', "data-state": "success", "data-layout": layout, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && _jsx(BackLink, { back: back }), _jsxs("header", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { className: "flex min-w-0 flex-1 items-start gap-3 sm:min-w-64 sm:gap-4", children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsx("h1", { id: dialog?.titleId, className: "type-page-title break-words text-foreground", children: titleEdit ? (_jsx(EditableValue, { label: titleEdit.label, edit: titleEdit, layout: "inline", className: "w-full", children: title })) : (title) }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle })), badges && _jsx("div", { className: "flex flex-wrap items-center gap-1.5", children: badges })] })] }), (actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] }))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), layout === 'rail' ? (_jsxs("div", { className: RAIL_LAYOUT.columns, children: [mobileOrder === 'main-first' && main, railSections.length > 0 && (_jsx(Rail, { label: railLabel ?? `${title ?? 'Record'} details`, sections: railSections, fields: railFields })), mobileOrder === 'rail-first' && main] })) : (_jsxs(_Fragment, { children: [sections
|
|
266
|
+
.filter((section) => !tabbed(section))
|
|
267
|
+
.map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] })), footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }));
|
|
201
268
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Tabs as TabsPrimitive } from "@base-ui/react/tabs";
|
|
2
|
+
import { type VariantProps } from "class-variance-authority";
|
|
3
|
+
declare function Tabs({ className, orientation, ...props }: TabsPrimitive.Root.Props): import("react").JSX.Element;
|
|
4
|
+
declare const tabsListVariants: (props?: ({
|
|
5
|
+
variant?: "default" | "line" | null | undefined;
|
|
6
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
|
+
declare function TabsList({ className, variant, ...props }: TabsPrimitive.List.Props & VariantProps<typeof tabsListVariants>): import("react").JSX.Element;
|
|
8
|
+
declare function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props): import("react").JSX.Element;
|
|
9
|
+
declare function TabsContent({ className, ...props }: TabsPrimitive.Panel.Props): import("react").JSX.Element;
|
|
10
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Tabs as TabsPrimitive } from "@base-ui/react/tabs";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
function Tabs({ className, orientation = "horizontal", ...props }) {
|
|
6
|
+
return (_jsx(TabsPrimitive.Root, { "data-slot": "tabs", "data-orientation": orientation, className: cn("group/tabs flex gap-2 data-horizontal:flex-col", className), ...props }));
|
|
7
|
+
}
|
|
8
|
+
const tabsListVariants = cva("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none", {
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-muted",
|
|
12
|
+
line: "gap-1 bg-transparent",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: "default",
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
function TabsList({ className, variant = "default", ...props }) {
|
|
20
|
+
return (_jsx(TabsPrimitive.List, { "data-slot": "tabs-list", "data-variant": variant, className: cn(tabsListVariants({ variant }), className), ...props }));
|
|
21
|
+
}
|
|
22
|
+
function TabsTrigger({ className, ...props }) {
|
|
23
|
+
return (_jsx(TabsPrimitive.Tab, { "data-slot": "tabs-trigger", className: cn("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", "group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent", "data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground", "after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100", className), ...props }));
|
|
24
|
+
}
|
|
25
|
+
function TabsContent({ className, ...props }) {
|
|
26
|
+
return (_jsx(TabsPrimitive.Panel, { "data-slot": "tabs-content", className: cn("flex-1 text-sm outline-none", className), ...props }));
|
|
27
|
+
}
|
|
28
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export { type RowGroup } from './components/app/table-groups.js';
|
|
|
14
14
|
export { byDay, type ByDayOptions } from './lib/group-by-day.js';
|
|
15
15
|
export { EntityForm, type EntityFormProps } from './components/app/entity-form.js';
|
|
16
16
|
export { KeyStats, type KeyStat, type KeyStatsProps } from './components/app/key-stats.js';
|
|
17
|
-
export { EntityView, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewSection, } from './components/app/entity-view.js';
|
|
17
|
+
export { EntityView, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
|
|
18
|
+
export { entityViewTabSlug } from './lib/entity-view-tab.js';
|
|
18
19
|
export { usePrinting } from './components/app/print-context.js';
|
|
19
20
|
export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
|
|
20
21
|
export { recordDialogState, useOpenRecord, useRecordDialog, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export { byDay } from './lib/group-by-day.js';
|
|
|
19
19
|
export { EntityForm } from './components/app/entity-form.js';
|
|
20
20
|
export { KeyStats } from './components/app/key-stats.js';
|
|
21
21
|
export { EntityView, } from './components/app/entity-view.js';
|
|
22
|
+
export { entityViewTabSlug } from './lib/entity-view-tab.js';
|
|
22
23
|
export { usePrinting } from './components/app/print-context.js';
|
|
23
24
|
export { RecordDialogRoute, RecordLink, } from './components/app/record-dialog.js';
|
|
24
25
|
export { recordDialogState, useOpenRecord, useRecordDialog, } from './components/app/record-dialog-context.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// EntityView's tabs (4.76, #303): the selected tab is `?tab=<slug>`, so a
|
|
2
|
+
// screen can link straight to one (`/things/3?tab=${entityViewTabSlug('Used in')}`).
|
|
3
|
+
/** A tab's name as it reads in the address: "Used in" is `used-in`. */
|
|
4
|
+
export function entityViewTabSlug(name) {
|
|
5
|
+
return (name
|
|
6
|
+
.normalize('NFKD')
|
|
7
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
10
|
+
.replace(/^-+|-+$/g, '') || 'tab');
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.76.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": {
|