@tristan2828/ui-foundation 4.100.0 → 4.101.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 752–829
16
16
  - Step 9: Register the nav entry and route names · lines 830–844
17
17
  - Step 10: `npm run verify`. · lines 845–847
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 849–1206
19
- - [The record view](#the-record-view) · lines 1002–1063
20
- - [Forms](#forms) · lines 1065–1123
21
- - [Dialogs](#dialogs) · lines 1125–1156
22
- - [Toasts and feedback](#toasts-and-feedback) · lines 1158–1206
23
- - [What not to copy](#what-not-to-copy) · lines 1208–1234
24
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1236–1253
25
- - [Deleting](#deleting) · lines 1255–1286
26
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1288–1309
27
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1311–1320
28
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1323–1365
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 849–1208
19
+ - [The record view](#the-record-view) · lines 1002–1065
20
+ - [Forms](#forms) · lines 1067–1125
21
+ - [Dialogs](#dialogs) · lines 1127–1158
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1160–1208
23
+ - [What not to copy](#what-not-to-copy) · lines 1210–1236
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1238–1255
25
+ - [Deleting](#deleting) · lines 1257–1288
26
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1290–1311
27
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1313–1322
28
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1325–1367
29
29
 
30
30
  <!-- /index -->
31
31
 
@@ -1033,7 +1033,9 @@ A record uses the parts it has, in this order:
1033
1033
  - **Tabs** (4.76), for a main column with **three or more groups of
1034
1034
  long content** (the steps, where it's used, the reasoning): a `tab` on
1035
1035
  each main section groups them under a tab list, the selected one in
1036
- `?tab=`. Fewer groups stay one scroll, folded by headings. A record's
1036
+ `?tab=`. Give each tab that holds records its count (`tabCounts={{
1037
+ Updates: updates.length }}`); the bar sticks as the record scrolls,
1038
+ with the record's name above it (4.101). Fewer groups stay one scroll, folded by headings. A record's
1037
1039
  Notes stay outside the tabs, above them, unless they are one tab's
1038
1040
  content; the strip never goes in a tab, and the facts are a tab of
1039
1041
  their own (Details, `detailsTab` to name it otherwise).
@@ -33,11 +33,11 @@
33
33
  - [A few equal things](#a-few-equal-things) · lines 1401–1485
34
34
  - [An overview page](#an-overview-page) · lines 1487–1550
35
35
  - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1551–1602
36
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1604–1663
37
- - [Picking at random](#picking-at-random) · lines 1665–1696
38
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1698–1765
39
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1767–1792
40
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1794–1883
36
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1604–1671
37
+ - [Picking at random](#picking-at-random) · lines 1673–1704
38
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1706–1773
39
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1775–1800
40
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1802–1891
41
41
 
42
42
  <!-- /index -->
43
43
 
@@ -1622,10 +1622,18 @@ its short facts the last tab, Details. A mark goes left of the title.
1622
1622
 
1623
1623
  - **Tabs** (`tab` on a section): a line tab list under the strip and any
1624
1624
  sections with no tab, one tab per name in the order the sections first
1625
- give it. The selected tab has foreground text and a 2px underline, the
1626
- others muted text; the list's own bottom border runs the column's
1627
- width. On a phone each tab is 44px tall, and a list wider than the
1628
- column scrolls sideways on its own, never the page. Arrow keys move
1625
+ give it. The look is the record standard's 3B (4.101): 44px tabs in
1626
+ 16px semibold (14px under 48rem), the selected one in foreground text
1627
+ with a 3px primary line under it, the others muted; the list's own
1628
+ bottom border runs the column's width. A tab's count (`tabCounts`, by
1629
+ name: the records it holds) sits beside its name in a small muted
1630
+ pill; a tab with none shows no count. A list wider than the column
1631
+ scrolls sideways on its own, never the page.
1632
+ - **The tab bar sticks** (4.101) to the top of whatever scrolls (the
1633
+ page, or a record dialog's body) while the record scrolls under it,
1634
+ and once stuck shows the record's name above the tabs, so you always
1635
+ see which record and which other tabs there are. A page with a bar of
1636
+ its own pinned to the top passes `tabsStickyTop` (any CSS length). Arrow keys move
1629
1637
  between tabs and select (Home, End), and Tab goes on into the panel.
1630
1638
  The address holds the selected tab (`?tab=used-in`,
1631
1639
  `entityViewTabSlug`), replaced rather than pushed, so Back leaves the
@@ -174,6 +174,18 @@ export type EntityViewProps = {
174
174
  * section of the record's own with this tab joins it.
175
175
  */
176
176
  detailsTab?: string;
177
+ /**
178
+ * Each tab's count, by its name (`{ Updates: 2, Linked: 1 }`): the
179
+ * records it holds, shown beside the name. A tab left out, or at 0,
180
+ * shows none.
181
+ */
182
+ tabCounts?: Readonly<Record<string, number>>;
183
+ /**
184
+ * How far from the top the tab bar sticks, for a page with a bar of its
185
+ * own pinned to the top: any CSS length (`'3.5rem'`,
186
+ * `'var(--page-bar-height)'`). Defaults to `0px`.
187
+ */
188
+ tabsStickyTop?: string;
177
189
  /**
178
190
  * In the `rail` layout, where its columns stack (a phone): the rail
179
191
  * before the main column (`rail-first`, the default), or the main column
@@ -233,4 +245,4 @@ export type EntityViewProps = {
233
245
  trail?: readonly PageCrumb[];
234
246
  };
235
247
  };
236
- export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, detailsTab, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
248
+ export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, detailsTab, tabCounts, tabsStickyTop, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
@@ -73,6 +73,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
73
73
  // sections stay mounted, hidden, so a field open in place survives a
74
74
  // switch. With no `tab` on any section, nothing changes.
75
75
  //
76
+ // The tab bar (4.101, record standard 3B): bigger underline tabs (16px
77
+ // semibold, 14px on a phone), a 3px primary line under the open one, each
78
+ // tab's count beside its name (`tabCounts`; none for zero). The bar sticks
79
+ // to the top of whatever scrolls (the page, or a record dialog's body) as
80
+ // the record scrolls under it, `tabsStickyTop` below the top, and once
81
+ // stuck it shows the record's name above the tabs, so the other tabs and
82
+ // the record you're on stay in view. Stuck is measured (a marker just
83
+ // above the bar, compared on every scroll), never guessed from the width.
84
+ //
76
85
  // `leading`, left of the title: the record's mark or avatar, with the
77
86
  // title, subtitle and badges beside it at every width. A rail field's
78
87
  // label sits to the left of its value (`railFields`, `beside` by default
@@ -258,7 +267,35 @@ function TabBody({ tab, railFields }) {
258
267
  // (hidden but mounted unless selected). The selected tab is the address's,
259
268
  // changed in place: the entry replaced, its state kept (a record over its
260
269
  // list stays the dialog), the scroll where it was.
261
- function MainTabs({ tabs, label, railFields = 'beside', }) {
270
+ // Whether the tab bar is stuck: the marker just above it has scrolled
271
+ // above the bar's top. Read on every scroll anywhere (a capture listener:
272
+ // the page's or a dialog body's) and on resize.
273
+ function useStuck() {
274
+ const [marker, setMarker] = useState(null);
275
+ const [bar, setBar] = useState(null);
276
+ const [stuck, setStuck] = useState(false);
277
+ useEffect(() => {
278
+ if (!marker || !bar)
279
+ return;
280
+ const measure = () => setStuck(marker.getBoundingClientRect().top < bar.getBoundingClientRect().top - 1);
281
+ measure();
282
+ window.addEventListener('scroll', measure, { capture: true, passive: true });
283
+ window.addEventListener('resize', measure);
284
+ return () => {
285
+ window.removeEventListener('scroll', measure, { capture: true });
286
+ window.removeEventListener('resize', measure);
287
+ };
288
+ }, [marker, bar]);
289
+ return { setMarker, setBar, stuck };
290
+ }
291
+ function MainTabs({ tabs, label, railFields = 'beside', title, counts, stickyTop, }) {
292
+ const { setMarker, setBar, stuck } = useStuck();
293
+ const countOf = (tab) => {
294
+ if (!counts)
295
+ return 0;
296
+ const key = Object.keys(counts).find((name) => entityViewTabSlug(name) === tab.slug);
297
+ return key ? counts[key] ?? 0 : 0;
298
+ };
262
299
  const location = useLocation();
263
300
  const navigate = useNavigate();
264
301
  const asked = new URLSearchParams(location.search).get(TAB_PARAM);
@@ -272,7 +309,13 @@ function MainTabs({ tabs, label, railFields = 'beside', }) {
272
309
  const search = params.toString();
273
310
  void navigate({ pathname: location.pathname, search: search ? `?${search}` : '', hash: location.hash }, { replace: true, state: location.state, preventScrollReset: true });
274
311
  };
275
- 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: "@container/tab flex min-w-0 flex-col gap-6 [font-size:inherit]", children: _jsx(TabBody, { tab: tab, railFields: railFields }) }, tab.slug)))] }));
312
+ return (_jsxs(Tabs, { value: selected, onValueChange: (value) => select(String(value)), "data-slot": "entity-view-tabs", className: "min-w-0 gap-6", children: [_jsx("div", { ref: setMarker, "aria-hidden": "true", "data-slot": "entity-view-tabs-marker", className: "h-px -mb-6" }), _jsxs("div", { ref: setBar, "data-slot": "entity-view-tab-bar", "data-stuck": stuck ? '' : undefined,
313
+ // A record dialog's body sets --entity-view-sticky-top to minus its
314
+ // padding, so the bar sits at the body's own top edge there.
315
+ style: { top: stickyTop ?? 'var(--entity-view-sticky-top, 0px)' }, className: "sticky z-10 -mx-1 flex min-w-0 flex-col gap-1 bg-background px-1 pt-0 data-[stuck]:pt-2 data-[stuck]:shadow-[0_8px_12px_-10px_var(--color-foreground)]", children: [stuck && title && (_jsx("p", { "data-slot": "entity-view-tab-bar-title", "aria-hidden": "true", className: "truncate type-label font-semibold text-foreground", children: title })), _jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-0 overflow-x-auto overflow-y-hidden border-b border-border p-0 md:gap-1 [scrollbar-width:thin]", children: tabs.map((tab) => {
316
+ const count = countOf(tab);
317
+ return (_jsxs(TabsTrigger, { value: tab.slug, className: "h-11 flex-none gap-1.5 px-2.5 text-sm font-semibold text-muted-foreground group-data-horizontal/tabs:after:bottom-0 group-data-horizontal/tabs:after:h-[3px] after:bg-primary data-active:text-foreground md:px-4 md:text-base dark:text-muted-foreground dark:data-active:text-foreground", children: [tab.name, count > 0 && (_jsx("span", { "data-slot": "entity-view-tab-count", className: "rounded-full bg-muted px-1.5 text-xs leading-[1.0625rem] font-medium tabular-nums text-foreground", children: count }))] }, tab.slug));
318
+ }) })] }), tabs.map((tab) => (_jsx(TabsContent, { value: tab.slug, keepMounted: true, className: "@container/tab flex min-w-0 flex-col gap-6 [font-size:inherit]", children: _jsx(TabBody, { tab: tab, railFields: railFields }) }, tab.slug)))] }));
276
319
  }
277
320
  // The `tabs` layout's sections (1A): the main column's untabbed sections,
278
321
  // then the tab list, with the facts (placed `rail`, no tab) as the last
@@ -298,7 +341,7 @@ function tabsLayout(sections, detailsTab) {
298
341
  tabs.push({ slug, name: detailsTab, sections: facts, side: [], details: true });
299
342
  return { above: main.filter((section) => section.tab === undefined), tabs, factsInColumn: false };
300
343
  }
301
- export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'tabs', detailsTab = 'Details', mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
344
+ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'tabs', detailsTab = 'Details', tabCounts, tabsStickyTop, mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
302
345
  // Editing in place: one store per view, and the leave-page prompt only
303
346
  // while a field is open (or one is always editable).
304
347
  const [store] = useState(() => new EditInPlaceStore());
@@ -346,7 +389,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
346
389
  const shaped = layout === 'tabs' ? tabsLayout(sections, detailsTab) : null;
347
390
  const tabs = shaped ? shaped.tabs : tabsOf(mainSections);
348
391
  const tabbed = (section) => section.placement !== 'rail' && section.tab !== undefined;
349
- const tabList = tabs.length > 0 && _jsx(MainTabs, { tabs: tabs, label: tabsLabel, railFields: railFields });
392
+ const tabList = tabs.length > 0 && (_jsx(MainTabs, { tabs: tabs, label: tabsLabel, railFields: railFields, title: title, counts: tabCounts, stickyTop: tabsStickyTop }));
350
393
  const main = (_jsxs("div", { className: cn(RAIL_LAYOUT.main, railSections.length === 0 && RAIL_LAYOUT.mainAlone), children: [mainSections
351
394
  .filter((section) => !tabbed(section))
352
395
  .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
@@ -161,7 +161,12 @@ export function RecordDialogRoute({ list, label, className, look = 'record', ful
161
161
  return;
162
162
  }
163
163
  close();
164
- }, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", size: card ? 'confirm' : 'record', "data-look": look, className: cn('gap-0 overflow-hidden p-0 data-closed:hidden', card && 'flex max-h-[calc(100dvh-2rem)] flex-col', className), children: [!card && (_jsxs("div", { className: cn('flex items-center gap-2 border-b px-2 py-2', fullPage ? 'justify-between' : 'justify-end'), children: [fullPage && (_jsxs(Link, { to: { pathname: location.pathname, search: location.search, hash: location.hash }, replace: true, className: buttonVariants({ variant: 'ghost', size: 'sm' }), children: [_jsx(Maximize2Icon, { "aria-hidden": "true" }), "Open Full Page"] })), _jsxs(DialogClose, { render: _jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [_jsx(XIcon, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: "Close" })] })] })), _jsx("div", { "data-slot": "record-dialog-body", className: cn('min-h-0 overflow-y-auto', card ? 'p-4 pb-[calc(1rem+env(safe-area-inset-bottom))] md:p-5' : 'p-4 sm:p-6'), children: _jsx(RecordDialogContext.Provider, { value: dialog, children: open && outlet }) })] }) })] }));
164
+ }, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", size: card ? 'confirm' : 'record', "data-look": look, className: cn('gap-0 overflow-hidden p-0 data-closed:hidden', card && 'flex max-h-[calc(100dvh-2rem)] flex-col', className), children: [!card && (_jsxs("div", { className: cn('flex items-center gap-2 border-b px-2 py-2', fullPage ? 'justify-between' : 'justify-end'), children: [fullPage && (_jsxs(Link, { to: { pathname: location.pathname, search: location.search, hash: location.hash }, replace: true, className: buttonVariants({ variant: 'ghost', size: 'sm' }), children: [_jsx(Maximize2Icon, { "aria-hidden": "true" }), "Open Full Page"] })), _jsxs(DialogClose, { render: _jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [_jsx(XIcon, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: "Close" })] })] })), _jsx("div", { "data-slot": "record-dialog-body", className: cn('min-h-0 overflow-y-auto',
165
+ // A record's tab bar sticks to the body's top edge, not inside
166
+ // its padding (4.101): minus the padding, for EntityView.
167
+ card
168
+ ? 'p-4 pb-[calc(1rem+env(safe-area-inset-bottom))] [--entity-view-sticky-top:-1rem] md:p-5 md:[--entity-view-sticky-top:-1.25rem]'
169
+ : 'p-4 [--entity-view-sticky-top:-1rem] sm:p-6 sm:[--entity-view-sticky-top:-1.5rem]'), children: _jsx(RecordDialogContext.Provider, { value: dialog, children: open && outlet }) })] }) })] }));
165
170
  }
166
171
  /**
167
172
  * A link to a record that opens it over the current list (a board's card,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.100.0",
3
+ "version": "4.101.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": {