@tristan2828/ui-foundation 4.83.0 → 4.84.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/README.md CHANGED
@@ -18,7 +18,7 @@ than installing this by hand:
18
18
 
19
19
  | Import | What |
20
20
  |---|---|
21
- | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
21
+ | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For the page standards (`docs/foundation/design-language.md` "Parts of the page standards"): `ValueList`, `ListHeader`, `Timeline`, `NeedsYou`, `Freshness`, `PartEmpty`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
22
22
  | `@tristan2828/ui-foundation/ui/<name>` | shadcn primitives: badge, button, calendar, card, checkbox, combobox, dialog, empty, field, input, input-group, label, popover, select, separator, sheet, sidebar, skeleton, sonner, spinner, switch, table, textarea, tooltip |
23
23
  | `@tristan2828/ui-foundation/gateway` | `safeFetch`, `toAppError`, `networkError` — for an app's `src/api/gateway/` only |
24
24
  | `@tristan2828/ui-foundation/mocks` | MSW: `authHandlers`, `environmentHandlers`, `resetMockAuth`, `getMockCurrentUser`, `MOCK_USER`, `exposeMswForE2E` |
@@ -3,36 +3,37 @@
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 45–112
7
- - [Glow](#glow) · lines 114–132
8
- - [Semantic tones](#semantic-tones) · lines 134–162
9
- - [The three badge styles](#the-three-badge-styles) · lines 164–181
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 183–212
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 214–227
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 229–273
13
- - [Categorical colour](#categorical-colour) · lines 275–345
14
- - [Heat scale](#heat-scale) · lines 347–408
15
- - [Depth ramps](#depth-ramps) · lines 410–488
16
- - [A stored colour](#a-stored-colour) · lines 490–538
17
- - [Shapes and sizes](#shapes-and-sizes) · lines 540–561
18
- - [Typography](#typography) · lines 563–683
19
- - [Written text (notes)](#written-text-notes) · lines 597–683
20
- - [Density](#density) · lines 685–771
21
- - [Rows on this device](#rows-on-this-device) · lines 744–771
22
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 773–887
23
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 889–966
24
- - [Notices](#notices) · lines 968–996
25
- - [A value over time](#a-value-over-time) · lines 998–1084
26
- - [Several values over time](#several-values-over-time) · lines 1047–1084
27
- - [A list as a board](#a-list-as-a-board) · lines 1086–1137
28
- - [A list as cards](#a-list-as-cards) · lines 1139–1185
29
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1187–1216
30
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1218–1256
31
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1258–1303
32
- - [Picking at random](#picking-at-random) · lines 1305–1336
33
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1338–1405
34
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1407–1432
35
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1434–1480
6
+ - [Palettes](#palettes) · lines 46–113
7
+ - [Glow](#glow) · lines 115–133
8
+ - [Semantic tones](#semantic-tones) · lines 135–163
9
+ - [The three badge styles](#the-three-badge-styles) · lines 165–182
10
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 184–213
11
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 215–228
12
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 230–274
13
+ - [Categorical colour](#categorical-colour) · lines 276–346
14
+ - [Heat scale](#heat-scale) · lines 348–409
15
+ - [Depth ramps](#depth-ramps) · lines 411–489
16
+ - [A stored colour](#a-stored-colour) · lines 491–539
17
+ - [Shapes and sizes](#shapes-and-sizes) · lines 541–562
18
+ - [Typography](#typography) · lines 564–684
19
+ - [Written text (notes)](#written-text-notes) · lines 598–684
20
+ - [Density](#density) · lines 686–772
21
+ - [Rows on this device](#rows-on-this-device) · lines 745–772
22
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 774–888
23
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 890–967
24
+ - [Notices](#notices) · lines 969–997
25
+ - [A value over time](#a-value-over-time) · lines 999–1085
26
+ - [Several values over time](#several-values-over-time) · lines 1048–1085
27
+ - [A list as a board](#a-list-as-a-board) · lines 1087–1138
28
+ - [A list as cards](#a-list-as-cards) · lines 1140–1186
29
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1188–1217
30
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1219–1262
31
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1263–1301
32
+ - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1303–1348
33
+ - [Picking at random](#picking-at-random) · lines 1350–1381
34
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1383–1450
35
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1452–1477
36
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1479–1525
36
37
 
37
38
  <!-- /index -->
38
39
 
@@ -1215,6 +1216,50 @@ row under the header, across the page at every width.
1215
1216
  - **`subtitle`** is the line under the title: what the record is for,
1216
1217
  in muted body type, editable in place like any value.
1217
1218
 
1219
+ ## Parts of the page standards
1220
+
1221
+ Six small parts the list, record and overview standards share. Each is
1222
+ generic and standalone: an app (or a later foundation release) wires it
1223
+ into a table, a record or an overview.
1224
+
1225
+ - **`ValueList`: several values in a cell.** `<ValueList items={[{ label }]} max={2} />`
1226
+ shows two values on one line and the rest as `+N`, every folded value in
1227
+ its tooltip (the `+N` is a button, so a keyboard and a tap reach it). A
1228
+ value is a chip by default, or the app's own `node` (an icon, a
1229
+ `ColorSwatch`) with its `label` as the plain text. An empty cell is a
1230
+ muted dash that reads "None".
1231
+ - **`ListHeader`: a list's header.** The title (the page's h1) with its
1232
+ `count`, `newAction` alone beside it, and one ⋯ menu for the rest. One
1233
+ related link in `links` stays a button; two or more fold into ⋯ with
1234
+ `more` (the page's own actions). `deleted={{ shown, onShownChange }}` adds
1235
+ "Show deleted" as the menu's last item and, while it's on, an info
1236
+ `Notice` with "Back to the list" in a `role="status"` region that is
1237
+ always there. It holds no state: the app keeps `shown`.
1238
+ - **`Timeline`: a record's dated history.** `items` newest first
1239
+ (`{ id, date, dateTime?, kind?, body, edit? }`): dates in a tabular
1240
+ column on the left, a dot and a thin line, the entry on the right with
1241
+ its `kind` as a muted line under it and `edit` (the entry's own
1242
+ control) at its end. The first `initial` (5) show, then "Show all N";
1243
+ under 24rem of its own width the date moves above its entry. Empty
1244
+ reads `emptyText` ("Nothing yet").
1245
+ - **`NeedsYou`: what waits on the user.** `items={[{ text, to, tone? }]}`:
1246
+ one region at the top of an overview, a warning wash with the `*-text`
1247
+ icon, each line a link; `tone: 'destructive'` for an overdue one.
1248
+ Nothing renders for an empty list.
1249
+ - **`Freshness`: how old a number is.** `<Freshness label="Balances entered"
1250
+ at="2026-08-02" staleAfter="2026-11-02" />` reads "Balances entered Aug
1251
+ 2" in caption type and the muted tone, and once `staleAfter` has passed
1252
+ the warning tone with a warning icon and ", out of date" for a screen
1253
+ reader. The app owns the rule (entered plus 90 days); this only compares.
1254
+ A plain `'YYYY-MM-DD'` day is never shifted by the time zone.
1255
+ - **`PartEmpty` and `WidgetCard`'s `empty`: a part with nothing yet.**
1256
+ `empty={{ text?, action }}` draws "Nothing here yet" and one outline
1257
+ button (a link `to`, or `onClick`) in place of the card's plain
1258
+ `emptyMessage` line, the foundation's `Empty` at card size.
1259
+
1260
+ Every one is measured with axe and the glyph check in both themes
1261
+ (fixtures `app/ValueList`, `ListHeader`, `Timeline`, `NeedsYou`,
1262
+ `Freshness`, `PartEmpty`).
1218
1263
  ## A record's header and empty values
1219
1264
 
1220
1265
  The record page standard (4.81): the same header on every record, the
@@ -0,0 +1,14 @@
1
+ export type FreshnessProps = {
2
+ /** When it was entered or checked; null or '' when it never was. */
3
+ at: Date | string | null | undefined;
4
+ /** The moment it goes stale. Left out, the line is never in the warning tone. */
5
+ staleAfter?: Date | string;
6
+ /** What happened, before the date: "Balances entered", "Prices checked". */
7
+ label: string;
8
+ /** What the line says when `at` is empty. Defaults to "<label>: never". */
9
+ neverText?: string;
10
+ /** The clock, for stories and tests. Defaults to now. */
11
+ now?: Date;
12
+ className?: string;
13
+ };
14
+ export declare function Freshness({ at, staleAfter, label, neverText, now, className }: FreshnessProps): import("react").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // How fresh a number is (overview standard O3): one quiet line under it,
3
+ // "Balances entered Aug 2", in the caption type and the muted tone. Once
4
+ // `staleAfter` has passed it turns to the warning tone and gains a
5
+ // warning icon, so an out-of-date balance never looks current; the line
6
+ // still says when, and a screen reader hears ", out of date".
7
+ //
8
+ // Used in a part's tile and detail and in a WidgetCard's body. The date is
9
+ // a plain day ('YYYY-MM-DD', as the wire writes it, shown without the
10
+ // time zone shifting it) or an instant (a Date, or an ISO timestamp).
11
+ // `staleAfter` is the moment it goes stale, so the app owns the rule
12
+ // (entered + 90 days): this only says whether it has passed. `now` is for
13
+ // stories and tests.
14
+ import { TriangleAlertIcon } from 'lucide-react';
15
+ import { cn } from 'cn';
16
+ import { isStale, showDate } from '../../lib/freshness.js';
17
+ export function Freshness({ at, staleAfter, label, neverText, now = new Date(), className }) {
18
+ const entered = at ? showDate(at, now) : '';
19
+ if (!entered) {
20
+ return (_jsx("span", { "data-slot": "freshness", "data-state": "never", className: cn('type-caption text-muted-foreground', className), children: neverText ?? `${label}: never` }));
21
+ }
22
+ const stale = isStale(staleAfter, now);
23
+ const iso = at instanceof Date ? at.toISOString() : String(at);
24
+ return (_jsxs("span", { "data-slot": "freshness", "data-state": stale ? 'stale' : 'fresh', className: cn('inline-flex items-center gap-1 type-caption', stale ? 'text-warning-text' : 'text-muted-foreground', className), children: [stale && _jsx(TriangleAlertIcon, { "aria-hidden": "true", className: "size-3 shrink-0" }), _jsxs("span", { children: [label, " ", _jsx("time", { dateTime: iso, children: entered }), stale && _jsx("span", { className: "sr-only", children: ", out of date" })] })] }));
25
+ }
@@ -0,0 +1,44 @@
1
+ import { type To } from 'react-router';
2
+ import type { IconComponent } from './icon-component.js';
3
+ export type ListHeaderLink = {
4
+ label: string;
5
+ to: To;
6
+ icon?: IconComponent;
7
+ };
8
+ export type ListHeaderAction = {
9
+ label: string;
10
+ onSelect: () => void;
11
+ icon?: IconComponent;
12
+ };
13
+ export type ListHeaderProps = {
14
+ /** The list's name: the page's h1. */
15
+ title: string;
16
+ /** How many records there are, beside the title in the muted tone. Left out while loading. */
17
+ count?: number;
18
+ /** Related screens (Board, Change log). One stays a button; two or more fold into ⋯. */
19
+ links?: readonly ListHeaderLink[];
20
+ /** The New button: a link to the new-record page, or a function that opens its dialog. */
21
+ newAction?: {
22
+ label: string;
23
+ to: To;
24
+ onClick?: never;
25
+ } | {
26
+ label: string;
27
+ onClick: () => void;
28
+ to?: never;
29
+ };
30
+ /** The page's other actions (Export, Import), in ⋯ after the folded links. */
31
+ more?: readonly ListHeaderAction[];
32
+ /**
33
+ * Soft-deleted records, for a list that has them: "Show deleted" in ⋯,
34
+ * and the notice while it is on. `noun` completes "Showing deleted
35
+ * <noun>" (default "records").
36
+ */
37
+ deleted?: {
38
+ shown: boolean;
39
+ onShownChange: (shown: boolean) => void;
40
+ noun?: string;
41
+ };
42
+ className?: string;
43
+ };
44
+ export declare function ListHeader({ title, count, links, newAction, more, deleted, className }: ListHeaderProps): import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A list page's header (list standard L12): the title with its count,
3
+ // the New button alone beside it, and everything else behind one ⋯ menu.
4
+ // The related screens (Board, Change log) stay out as buttons while
5
+ // there's one; two or more fold into the menu with the page's other
6
+ // extras, so the row is the same on a list with no siblings and one with
7
+ // four. "Show deleted" is the menu's last item, and while it's on a notice
8
+ // says so with "Back to the list", so the ⋯ menu and the notice are one
9
+ // component and a list can't show deleted records without saying so.
10
+ //
11
+ // Holds no state: the app keeps `shown` (usually a URL filter). `links`
12
+ // are routes, `more` are the app's own actions. The ⋯ button has an
13
+ // accessible name and is left out when the menu would be empty.
14
+ import { EllipsisIcon, PlusIcon, Trash2Icon } from 'lucide-react';
15
+ import { Link } from 'react-router';
16
+ import { cn } from 'cn';
17
+ import { Notice } from './notice.js';
18
+ import { Button } from '../ui/button.js';
19
+ import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
20
+ export function ListHeader({ title, count, links = [], newAction, more = [], deleted, className }) {
21
+ // One link is a button of its own; two or more go in the menu.
22
+ const outLink = links.length === 1 ? links[0] : undefined;
23
+ const menuLinks = links.length > 1 ? links : [];
24
+ const hasMenu = menuLinks.length > 0 || more.length > 0 || deleted !== undefined;
25
+ return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more" }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", children: [menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show deleted"] }))] })] })), newAction &&
26
+ (newAction.to !== undefined ? (_jsxs(Button, { size: "sm", nativeButton: false, render: _jsx(Link, { to: newAction.to }), children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })) : (_jsxs(Button, { size: "sm", onClick: newAction.onClick, children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })))] })] }), _jsx("div", { role: "status", "data-slot": "list-header-notice", className: "not-empty:mt-3", children: deleted?.shown && (_jsxs(Notice, { tone: "info", icon: Trash2Icon, action: _jsx(Button, { size: "sm", variant: "outline", onClick: () => deleted.onShownChange(false), children: "Back to the list" }), children: ["Showing deleted ", deleted.noun ?? 'records', "."] })) })] }));
27
+ }
@@ -0,0 +1,19 @@
1
+ import { type To } from 'react-router';
2
+ export type NeedsYouTone = 'warning' | 'destructive';
3
+ export type NeedsYouItem = {
4
+ /** What waits: a short sentence ("1 document is overdue"). The whole line is the link. */
5
+ text: string;
6
+ /** Where to fix it. */
7
+ to: To;
8
+ /** `warning` (the default), or `destructive` for what's overdue. */
9
+ tone?: NeedsYouTone;
10
+ };
11
+ export type NeedsYouProps = {
12
+ items: readonly NeedsYouItem[];
13
+ /** The heading. Defaults to "Needs you". */
14
+ title?: string;
15
+ /** The heading's level: 2 under the page's h1 (the default). */
16
+ headingLevel?: 2 | 3 | 4;
17
+ className?: string;
18
+ };
19
+ export declare function NeedsYou({ items, title, headingLevel, className }: NeedsYouProps): import("react").JSX.Element | null;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // What waits on you (overview standard O2): one list at the top of an
3
+ // overview, in the warning tone, each line a link to where it's fixed
4
+ // ("Balances are three months old", "2 deals at their target"). It
5
+ // collects what each part already says about itself, so the page's first
6
+ // answer is "what do I do", not a scan of every tile.
7
+ //
8
+ // Nothing at all when `items` is empty: no heading, no empty box. A
9
+ // region named by its heading, so it is in the page's outline and a
10
+ // screen reader can jump to it. The wash is the tone at 10% (20% in dark)
11
+ // with foreground text and the `*-text` icon, as a Notice draws it; a
12
+ // line may take another tone (`destructive` for an overdue one).
13
+ import { ChevronRightIcon, CircleAlertIcon, TriangleAlertIcon } from 'lucide-react';
14
+ import { useId } from 'react';
15
+ import { Link } from 'react-router';
16
+ import { cn } from 'cn';
17
+ const LINE = {
18
+ warning: { icon: 'text-warning-text', Icon: TriangleAlertIcon },
19
+ destructive: { icon: 'text-destructive-text', Icon: CircleAlertIcon },
20
+ };
21
+ export function NeedsYou({ items, title = 'Needs you', headingLevel = 2, className }) {
22
+ const headingId = useId();
23
+ if (items.length === 0)
24
+ return null;
25
+ const Heading = `h${headingLevel}`;
26
+ return (_jsxs("section", { "aria-labelledby": headingId, "data-slot": "needs-you", className: cn('flex flex-col gap-1 rounded-lg border border-warning-text/30 bg-warning/10 px-4 py-3 text-foreground dark:bg-warning/20', className), children: [_jsx(Heading, { id: headingId, className: "type-label font-semibold text-foreground", children: title }), _jsx("ul", { className: "flex flex-col", children: items.map((item, index) => {
27
+ const { icon, Icon } = LINE[item.tone ?? 'warning'];
28
+ return (_jsx("li", { "data-tone": item.tone ?? 'warning', children: _jsxs(Link, { to: item.to, className: "group/line -mx-1 flex min-h-8 items-center gap-2 rounded-sm px-1 py-1 type-body text-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/50 max-sm:min-h-11", children: [_jsx(Icon, { "aria-hidden": "true", className: cn('size-4 shrink-0', icon) }), _jsx("span", { className: "min-w-0 flex-1 underline-offset-4 group-hover/line:underline", children: item.text }), _jsx(ChevronRightIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" })] }) }, `${index}-${item.text}`));
29
+ }) })] }));
30
+ }
@@ -0,0 +1,20 @@
1
+ import { type To } from 'react-router';
2
+ export type PartEmptyAction = {
3
+ label: string;
4
+ to: To;
5
+ onClick?: never;
6
+ } | {
7
+ label: string;
8
+ onClick: () => void;
9
+ to?: never;
10
+ };
11
+ export type PartEmptyState = {
12
+ /** What it says. Defaults to "Nothing here yet". */
13
+ text?: string;
14
+ /** The one way to start: a link to where the first one is added, or a button that opens it. */
15
+ action?: PartEmptyAction;
16
+ };
17
+ export type PartEmptyProps = PartEmptyState & {
18
+ className?: string;
19
+ };
20
+ export declare function PartEmpty({ text, action, className }: PartEmptyProps): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A part with nothing in it yet (overview standard O5): the card stays,
3
+ // with "Nothing here yet" and one way to start ("Add the first line"), as
4
+ // an empty list does. The foundation's Empty at card size: no big
5
+ // illustration, a dashed border, the message and one outline button.
6
+ //
7
+ // `WidgetCard`'s `empty` prop draws this in its body in place of the
8
+ // plain `emptyMessage` line; an overview part uses the same component for
9
+ // its own `empty`. The button is a link (`to`) or a plain button
10
+ // (`onClick`).
11
+ import { Link } from 'react-router';
12
+ import { cn } from 'cn';
13
+ import { Button } from '../ui/button.js';
14
+ import { Empty, EmptyContent, EmptyDescription, EmptyHeader } from '../ui/empty.js';
15
+ export function PartEmpty({ text = 'Nothing here yet', action, className }) {
16
+ return (_jsxs(Empty, { "data-slot": "part-empty", "data-state": "empty", className: cn('gap-3 border p-4', className), children: [_jsx(EmptyHeader, { children: _jsx(EmptyDescription, { children: text }) }), action && (_jsx(EmptyContent, { children: action.to !== undefined ? (_jsx(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: action.to }), children: action.label })) : (_jsx(Button, { size: "sm", variant: "outline", onClick: action.onClick, children: action.label })) }))] }));
17
+ }
@@ -0,0 +1,25 @@
1
+ import { type ReactNode } from 'react';
2
+ export type TimelineItem = {
3
+ /** Unique in the list; a stored id when there is one. */
4
+ id: string;
5
+ /** The date as shown ("Nov 2", "Nov 2, 2025"): short, one line. */
6
+ date: string;
7
+ /** The date for machines ('2026-11-02'), on the <time> element. */
8
+ dateTime?: string;
9
+ /** What sort of entry: "Visit", "Call", "Note". A muted line under the body. */
10
+ kind?: string;
11
+ body: ReactNode;
12
+ /** The entry's own control, at its end (an edit button, a ⋯ menu). */
13
+ edit?: ReactNode;
14
+ };
15
+ export type TimelineProps = {
16
+ items: readonly TimelineItem[];
17
+ /** How many show before "Show all N". Defaults to 5. */
18
+ initial?: number;
19
+ /** The list's name for screen readers ("Changes"). */
20
+ label: string;
21
+ /** What an empty timeline says. Defaults to "Nothing yet". */
22
+ emptyText?: string;
23
+ className?: string;
24
+ };
25
+ export declare function Timeline({ items, initial, label, emptyText, className }: TimelineProps): import("react").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A record's dated history (record standard R7): updates, changes, a
3
+ // care log. Dates line up in a tabular column on the left, a dot and a
4
+ // thin line between, the entry on the right, so it reads as a history
5
+ // instead of a stack of paragraphs. The newest `initial` (5) show, then
6
+ // "Show all N": a long history stays short and the entries after it stay
7
+ // where they were.
8
+ //
9
+ // Items are given newest first, as the app sorts them. An entry has its
10
+ // date (`date`, already formatted; `dateTime` the machine-readable day
11
+ // for the <time>), an optional `kind` ("Visit", "Note") as a muted line
12
+ // under the body, the `body` (text, or markup such as <Markdown inline>),
13
+ // and `edit`: the entry's own control (an edit button, a menu), at its
14
+ // end. Under 24rem of the timeline's own width (a phone, a narrow
15
+ // dialog) the date moves above its entry and the column goes.
16
+ //
17
+ // It owns the empty state: "Nothing yet" (`emptyText`), never a blank.
18
+ import { useId, useState } from 'react';
19
+ import { cn } from 'cn';
20
+ import { Button } from '../ui/button.js';
21
+ export function Timeline({ items, initial = 5, label, emptyText = 'Nothing yet', className }) {
22
+ const [all, setAll] = useState(false);
23
+ const listId = useId();
24
+ if (items.length === 0) {
25
+ return (_jsx("p", { "data-slot": "timeline", "data-state": "empty", className: cn('type-body text-muted-foreground', className), children: emptyText }));
26
+ }
27
+ const limit = Math.max(1, initial);
28
+ const folds = items.length > limit;
29
+ const shown = folds && !all ? items.slice(0, limit) : items;
30
+ return (_jsxs("div", { "data-slot": "timeline", className: cn('@container flex min-w-0 flex-col gap-2', className), children: [_jsx("ol", { id: listId, "aria-label": label, className: "flex flex-col", children: shown.map((item, index) => (_jsxs("li", { "data-slot": "timeline-item", className: "grid grid-cols-[5.5rem_1rem_minmax(0,1fr)] gap-x-2 @max-[24rem]:grid-cols-[1rem_minmax(0,1fr)]", children: [_jsx("div", { className: "col-start-1 row-start-1 pt-px text-right type-caption tabular-nums text-muted-foreground @max-[24rem]:col-start-2 @max-[24rem]:text-left", children: item.dateTime ? _jsx("time", { dateTime: item.dateTime, children: item.date }) : item.date }), _jsxs("div", { "aria-hidden": "true", className: "col-start-2 row-start-1 flex flex-col items-center @max-[24rem]:col-start-1 @max-[24rem]:row-span-2", children: [_jsx("span", { className: "mt-1.5 size-2 shrink-0 rounded-full bg-primary" }), index < shown.length - 1 && _jsx("span", { className: "w-px flex-1 bg-border" })] }), _jsxs("div", { className: "col-start-3 row-start-1 flex min-w-0 items-start gap-2 pb-3 @max-[24rem]:col-start-2 @max-[24rem]:row-start-2", children: [_jsxs("div", { className: "min-w-0 flex-1 type-body text-foreground", children: [_jsx("div", { className: "break-words", children: item.body }), item.kind && _jsx("div", { className: "type-caption text-muted-foreground", children: item.kind })] }), item.edit && _jsx("div", { className: "shrink-0", children: item.edit })] })] }, item.id))) }), folds && (_jsx(Button, { variant: "link", size: "sm", "aria-expanded": all, "aria-controls": listId, onClick: () => setAll(!all), className: "self-start", children: all ? 'Show fewer' : `Show all ${items.length}` }))] }));
31
+ }
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from 'react';
2
+ export type ValueListItem = {
3
+ /** Plain text: the chip's text, the tooltip's line and the screen reader's. Unique in the list. */
4
+ label: string;
5
+ /** The app's own mark for the value (an icon, a swatch), drawn in place of the chip. */
6
+ node?: ReactNode;
7
+ };
8
+ export type ValueListProps = {
9
+ items: readonly ValueListItem[];
10
+ /** How many show before "+N". Defaults to 2. */
11
+ max?: number;
12
+ className?: string;
13
+ };
14
+ export declare function ValueList({ items, max, className }: ValueListProps): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from 'cn';
3
+ import { Badge } from '../ui/badge.js';
4
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip.js';
5
+ export function ValueList({ items, max = 2, className }) {
6
+ if (items.length === 0) {
7
+ return (_jsxs("span", { "data-slot": "value-list", "data-state": "empty", className: cn('text-muted-foreground', className), children: [_jsx("span", { "aria-hidden": "true", children: "\u2014" }), _jsx("span", { className: "sr-only", children: "None" })] }));
8
+ }
9
+ const shown = items.slice(0, Math.max(0, max));
10
+ const folded = items.slice(shown.length);
11
+ const names = folded.map((item) => item.label).join(', ');
12
+ return (_jsxs("span", { "data-slot": "value-list", className: cn('inline-flex items-center gap-1 whitespace-nowrap', className), children: [shown.map((item) => (_jsx("span", { "data-slot": "value-list-item", className: "inline-flex shrink-0 items-center", children: item.node ?? _jsx(Badge, { children: item.label }) }, item.label))), folded.length > 0 && (_jsx(TooltipProvider, { children: _jsxs(Tooltip, { children: [_jsxs(TooltipTrigger, { render: _jsx("button", { type: "button", "data-slot": "value-list-more", "aria-label": `${folded.length} more: ${names}`, className: "rounded-sm px-1 type-caption tabular-nums text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50" }), children: ["+", folded.length] }), _jsx(TooltipContent, { children: names })] }) }))] }));
13
+ }
@@ -2,6 +2,7 @@ import { type ReactNode } from 'react';
2
2
  import { type To } from 'react-router';
3
3
  import type { AppError } from '../../api/contracts.js';
4
4
  import type { IconComponent } from './icon-component.js';
5
+ import { type PartEmptyState } from './part-empty.js';
5
6
  export interface WidgetCardProps {
6
7
  title: string;
7
8
  /**
@@ -32,6 +33,13 @@ export interface WidgetCardProps {
32
33
  isEmpty: boolean;
33
34
  /** The empty state's one line: "Nothing waiting". */
34
35
  emptyMessage: string;
36
+ /**
37
+ * A card with nothing yet that offers a way to start (overview standard
38
+ * O5): `{ text, action }` draws "Nothing here yet" and one button, the
39
+ * foundation's Empty at card size (PartEmpty), in place of the plain
40
+ * `emptyMessage` line. `text` defaults to "Nothing here yet".
41
+ */
42
+ empty?: PartEmptyState;
35
43
  /** How many rows the loading skeleton shows: the number the widget usually holds. */
36
44
  skeletonRows?: number;
37
45
  /** A button at the header's end that folds the card to its header, and opens it again. */
@@ -64,7 +72,7 @@ export type WidgetCardLink = {
64
72
  label: string;
65
73
  to?: never;
66
74
  };
67
- export declare function WidgetCard({ id, title, icon: Icon, headingLevel, link, isLoading, error, onRetry, isEmpty, emptyMessage, skeletonRows, collapsible, defaultCollapsed, storageKey, summary, emptySummary, children, className, }: WidgetCardProps): import("react").JSX.Element;
75
+ export declare function WidgetCard({ id, title, icon: Icon, headingLevel, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows, collapsible, defaultCollapsed, storageKey, summary, emptySummary, children, className, }: WidgetCardProps): import("react").JSX.Element;
68
76
  export interface WidgetCardGroupProps {
69
77
  /**
70
78
  * One card open at a time: `true` always, `"mobile"` only below the
@@ -59,6 +59,7 @@ import { Link } from 'react-router';
59
59
  import { ChevronDownIcon, ExternalLinkIcon } from 'lucide-react';
60
60
  import { cn } from 'cn';
61
61
  import { ErrorState } from './error-state.js';
62
+ import { PartEmpty } from './part-empty.js';
62
63
  import { Button } from '../ui/button.js';
63
64
  import { Card, CardContent, CardHeader } from '../ui/card.js';
64
65
  import { Skeleton } from '../ui/skeleton.js';
@@ -66,7 +67,7 @@ import { useIsMobile } from '../../hooks/use-mobile.js';
66
67
  import { useRememberedFlag } from '../../hooks/use-remembered-flag.js';
67
68
  const HEADER_LINK_CLASS = 'shrink-0 rounded-sm type-label text-foreground underline underline-offset-4 outline-none ' +
68
69
  'hover:decoration-2 focus-visible:ring-3 focus-visible:ring-ring/50';
69
- export function WidgetCard({ id, title, icon: Icon, headingLevel = 2, link, isLoading, error, onRetry, isEmpty, emptyMessage, skeletonRows = 3, collapsible = false, defaultCollapsed = false, storageKey, summary, emptySummary, children, className, }) {
70
+ export function WidgetCard({ id, title, icon: Icon, headingLevel = 2, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows = 3, collapsible = false, defaultCollapsed = false, storageKey, summary, emptySummary, children, className, }) {
70
71
  const headingId = useId();
71
72
  const contentId = useId();
72
73
  const summaryId = useId();
@@ -93,7 +94,7 @@ export function WidgetCard({ id, title, icon: Icon, headingLevel = 2, link, isLo
93
94
  return (_jsx("section", { id: id, "aria-labelledby": headingId, "data-slot": "widget-card", "data-state": state, "data-collapsed": collapsed || undefined, className: cn('min-w-0 self-start', className), children: _jsxs(Card, { className: cn('glow-edge density-compact:[--card-spacing:--spacing(3)]', collapsed && 'pb-0'), children: [_jsxs(CardHeader, { onClick: onHeaderClick, className: cn('flex items-center justify-between gap-3', inAccordion && 'cursor-pointer select-none', collapsed && 'border-b-0'), children: [_jsxs(Heading, { id: headingId, className: "flex min-w-0 items-center gap-2 type-section-title text-foreground", children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" }), _jsx("span", { className: "truncate", children: title })] }), (link || foldable || summaryShown) && (_jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [summaryShown && (_jsx("span", { id: summaryId, "data-slot": "widget-card-summary", className: "mr-2 flex items-center", children: _jsx(WidgetCardSummary, { state: state, summary: summary, emptySummary: emptySummary }) })), link?.href !== undefined ? (_jsxs("a", { href: link.href, target: "_blank", rel: "noreferrer", "aria-describedby": headingId, className: cn(HEADER_LINK_CLASS, 'inline-flex items-center gap-1'), children: [link.label, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "size-3 shrink-0 text-muted-foreground" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] })) : (link && (_jsx(Link, { to: link.to, "aria-describedby": headingId, className: HEADER_LINK_CLASS, children: link.label }))), foldable && (_jsx(Button, { variant: "ghost", size: "icon-sm", "aria-labelledby": headingId, "aria-describedby": summaryShown ? summaryId : undefined, "aria-expanded": !collapsed, "aria-controls": contentId, onClick: toggle,
94
95
  // The button's own open look (a filled background) would
95
96
  // read as pressed: the chevron says it.
96
- className: "-my-1 -mr-1.5 aria-expanded:not-hover:bg-transparent", children: _jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('transition-transform', collapsed && '-rotate-90') }) }))] }))] }), _jsx(CardContent, { id: contentId, hidden: collapsed, "aria-busy": state === 'loading' || undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry, size: "compact" })) : state === 'loading' ? (_jsx(WidgetListSkeleton, { rows: skeletonRows })) : state === 'empty' ? (_jsx("p", { "data-state": "empty", className: "py-2 type-body text-muted-foreground", children: emptyMessage })) : (children) })] }) }));
97
+ className: "-my-1 -mr-1.5 aria-expanded:not-hover:bg-transparent", children: _jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('transition-transform', collapsed && '-rotate-90') }) }))] }))] }), _jsx(CardContent, { id: contentId, hidden: collapsed, "aria-busy": state === 'loading' || undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry, size: "compact" })) : state === 'loading' ? (_jsx(WidgetListSkeleton, { rows: skeletonRows })) : state === 'empty' ? (empty ? (_jsx(PartEmpty, { ...empty })) : (_jsx("p", { "data-state": "empty", className: "py-2 type-body text-muted-foreground", children: emptyMessage }))) : (children) })] }) }));
97
98
  }
98
99
  // A folded card's one value, by state. Loading's skeleton is about one
99
100
  // number wide; an error's dash says "Couldn't load" to a screen reader,
package/dist/index.d.ts CHANGED
@@ -49,6 +49,13 @@ export { SessionStage, SessionView, sessionStageLit, sessionStageMain, sessionSt
49
49
  export { AllowReminders, type AllowRemindersProps } from './components/app/allow-reminders.js';
50
50
  export { StageCircle, type StageCircleProps, type StageCircleStage, type StageCircleTone, } from './components/app/stage-circle.js';
51
51
  export { Notice, type NoticeProps, type NoticeTone } from './components/app/notice.js';
52
+ export { ValueList, type ValueListItem, type ValueListProps } from './components/app/value-list.js';
53
+ export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, } from './components/app/list-header.js';
54
+ export { Timeline, type TimelineItem, type TimelineProps } from './components/app/timeline.js';
55
+ export { NeedsYou, type NeedsYouItem, type NeedsYouProps, type NeedsYouTone } from './components/app/needs-you.js';
56
+ export { Freshness, type FreshnessProps } from './components/app/freshness.js';
57
+ export { isStale } from './lib/freshness.js';
58
+ export { PartEmpty, type PartEmptyAction, type PartEmptyProps, type PartEmptyState } from './components/app/part-empty.js';
52
59
  export { SourceCredit, type Source, type SourceCreditProps } from './components/app/source-credit.js';
53
60
  export { ProgressRing, type ProgressRingProps } from './components/app/progress-ring.js';
54
61
  export { LineChart, type LineChartMark, type LineChartPoint, type LineChartProps, } from './components/app/line-chart.js';
package/dist/index.js CHANGED
@@ -51,6 +51,13 @@ export { SessionStage, SessionView, sessionStageLit, sessionStageMain, sessionSt
51
51
  export { AllowReminders } from './components/app/allow-reminders.js';
52
52
  export { StageCircle, } from './components/app/stage-circle.js';
53
53
  export { Notice } from './components/app/notice.js';
54
+ export { ValueList } from './components/app/value-list.js';
55
+ export { ListHeader, } from './components/app/list-header.js';
56
+ export { Timeline } from './components/app/timeline.js';
57
+ export { NeedsYou } from './components/app/needs-you.js';
58
+ export { Freshness } from './components/app/freshness.js';
59
+ export { isStale } from './lib/freshness.js';
60
+ export { PartEmpty } from './components/app/part-empty.js';
54
61
  export { SourceCredit } from './components/app/source-credit.js';
55
62
  export { ProgressRing } from './components/app/progress-ring.js';
56
63
  export { LineChart, } from './components/app/line-chart.js';
@@ -0,0 +1,6 @@
1
+ /** A plain day as local midnight, anything else as the instant it names; null when it isn't a date. */
2
+ export declare function toDate(value: Date | string): Date | null;
3
+ /** "Aug 2" this year, "Aug 2, 2025" before it; '' when it isn't a date. */
4
+ export declare function showDate(value: Date | string, now: Date): string;
5
+ /** True once `staleAfter` is before `now`. Never for a missing or unreadable date. */
6
+ export declare function isStale(staleAfter: Date | string | undefined, now?: Date): boolean;
@@ -0,0 +1,37 @@
1
+ // The rules under <Freshness>: reading a date the way the wire writes it,
2
+ // showing it short, and saying whether a limit has passed. A plain day
3
+ // ('YYYY-MM-DD') is a calendar day, never shifted by the time zone; any
4
+ // other string is an instant (an ISO timestamp).
5
+ import { formatPlainDate } from './plain-date.js';
6
+ const PLAIN_DAY = /^\d{4}-\d{2}-\d{2}$/;
7
+ /** A plain day as local midnight, anything else as the instant it names; null when it isn't a date. */
8
+ export function toDate(value) {
9
+ if (value instanceof Date)
10
+ return Number.isNaN(value.getTime()) ? null : value;
11
+ if (PLAIN_DAY.test(value)) {
12
+ const [year, month, day] = value.split('-').map(Number);
13
+ return new Date(year, month - 1, day);
14
+ }
15
+ const parsed = new Date(value);
16
+ return Number.isNaN(parsed.getTime()) ? null : parsed;
17
+ }
18
+ /** "Aug 2" this year, "Aug 2, 2025" before it; '' when it isn't a date. */
19
+ export function showDate(value, now) {
20
+ const date = toDate(value);
21
+ if (!date)
22
+ return '';
23
+ const sameYear = date.getFullYear() === now.getFullYear();
24
+ const options = sameYear
25
+ ? { month: 'short', day: 'numeric' }
26
+ : { month: 'short', day: 'numeric', year: 'numeric' };
27
+ if (typeof value === 'string' && PLAIN_DAY.test(value))
28
+ return formatPlainDate(value, options);
29
+ return date.toLocaleDateString(undefined, options);
30
+ }
31
+ /** True once `staleAfter` is before `now`. Never for a missing or unreadable date. */
32
+ export function isStale(staleAfter, now = new Date()) {
33
+ if (staleAfter === undefined || staleAfter === '')
34
+ return false;
35
+ const limit = toDate(staleAfter);
36
+ return limit !== null && limit.getTime() < now.getTime();
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.83.0",
3
+ "version": "4.84.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": {