@tristan2828/ui-foundation 4.87.0 → 4.89.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 +1 -1
- package/conventions/docs/add-an-entity.md +38 -23
- package/conventions/docs/cell-patterns.md +49 -24
- package/conventions/docs/design-language.md +97 -31
- package/dist/components/app/choice-buttons.d.ts +25 -0
- package/dist/components/app/choice-buttons.js +17 -0
- package/dist/components/app/date-field.d.ts +28 -9
- package/dist/components/app/date-field.js +103 -10
- package/dist/components/app/edit-in-place-controls.d.ts +1 -3
- package/dist/components/app/edit-in-place-controls.js +4 -58
- package/dist/components/app/edit-in-place-presets.d.ts +38 -4
- package/dist/components/app/edit-in-place-presets.js +48 -27
- package/dist/components/app/edit-row.d.ts +7 -0
- package/dist/components/app/edit-row.js +23 -0
- package/dist/components/app/editable-value.d.ts +8 -1
- package/dist/components/app/editable-value.js +36 -4
- package/dist/components/app/entity-view.js +5 -1
- package/dist/components/app/multi-pick.d.ts +8 -1
- package/dist/components/app/multi-pick.js +19 -5
- package/dist/components/app/multi-reference.d.ts +8 -1
- package/dist/components/app/multi-reference.js +44 -6
- package/dist/components/app/overview-page.d.ts +44 -0
- package/dist/components/app/overview-page.js +63 -0
- package/dist/components/app/reference-combobox.d.ts +37 -0
- package/dist/components/app/reference-combobox.js +96 -0
- package/dist/components/app/widget-card.d.ts +15 -2
- package/dist/components/app/widget-card.js +15 -4
- package/dist/components/ui/field.d.ts +2 -2
- package/dist/components/ui/field.js +2 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/lib/names-record.d.ts +4 -0
- package/dist/lib/names-record.js +7 -0
- package/dist/lib/plain-date.d.ts +20 -0
- package/dist/lib/plain-date.js +72 -0
- package/package.json +1 -1
|
@@ -22,18 +22,26 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
22
22
|
// - Keyboard: the filter box first; Down goes to the chips, Left/Right
|
|
23
23
|
// (Home/End) move along them, Up goes back to the box, and Space or
|
|
24
24
|
// Enter toggles a chip.
|
|
25
|
+
// - Every multi-pick (4.88, the form standard's F13): the chips wrap at
|
|
26
|
+
// every width, under the filter box. Past `limit` options (30) it shows
|
|
27
|
+
// the picked ones and the first 30, then "Show all N"; a filter searches
|
|
28
|
+
// them all. The options can be the app's list of records (its query's
|
|
29
|
+
// rows as `{ id, label }`, `loading` while it loads), so a link to
|
|
30
|
+
// several other records uses it too.
|
|
25
31
|
import { CheckIcon } from 'lucide-react';
|
|
26
32
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
27
33
|
import { toast } from 'sonner';
|
|
28
34
|
import { cn } from 'cn';
|
|
35
|
+
import { Button } from '../ui/button.js';
|
|
29
36
|
import { FieldError } from '../ui/field.js';
|
|
30
37
|
import { Input } from '../ui/input.js';
|
|
31
38
|
import { Spinner } from '../ui/spinner.js';
|
|
32
39
|
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
|
|
33
40
|
import { messageOf } from './edit-in-place-store.js';
|
|
34
|
-
export function MultiPick({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder = 'Filter', emptyText = 'No options.', readOnly = false, className, }) {
|
|
41
|
+
export function MultiPick({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder = 'Filter', emptyText = 'No options.', limit = 30, loading = false, readOnly = false, className, }) {
|
|
35
42
|
const key = useId();
|
|
36
43
|
const [filter, setFilter] = useState('');
|
|
44
|
+
const [showAll, setShowAll] = useState(false);
|
|
37
45
|
const [pending, setPending] = useState(() => new Map());
|
|
38
46
|
const [refused, setRefused] = useState(() => new Map());
|
|
39
47
|
const filterBox = useRef(null);
|
|
@@ -91,7 +99,11 @@ export function MultiPick({ options, value, onValueChange, onPick, 'aria-label':
|
|
|
91
99
|
});
|
|
92
100
|
};
|
|
93
101
|
const needle = filter.trim().toLowerCase();
|
|
94
|
-
const
|
|
102
|
+
const matching = needle ? options.filter((option) => option.label.toLowerCase().includes(needle)) : options;
|
|
103
|
+
// A long set: the first `limit`, and any picked one past them, in the options' order.
|
|
104
|
+
const capped = !needle && !showAll && options.length > limit;
|
|
105
|
+
const visible = capped ? matching.filter((option, index) => index < limit || isPicked(option.id)) : matching;
|
|
106
|
+
const hidden = options.length - visible.length;
|
|
95
107
|
// Down from the box: into the chips, at the one the group would tab to.
|
|
96
108
|
const onFilterKeyDown = (event) => {
|
|
97
109
|
if (event.key !== 'ArrowDown')
|
|
@@ -110,11 +122,13 @@ export function MultiPick({ options, value, onValueChange, onPick, 'aria-label':
|
|
|
110
122
|
filterBox.current?.focus();
|
|
111
123
|
};
|
|
112
124
|
const errorId = (option) => `${key}-refused-${String(option)}`;
|
|
113
|
-
return (_jsxs("div", { "data-slot": "multi-pick", className: cn('flex w-full min-w-0 flex-col gap-2', className), children: [_jsx(Input, { ref: filterBox, id: id, type: "search", value: filter, onChange: (event) => setFilter(event.target.value), onKeyDown: onFilterKeyDown, placeholder: placeholder, "aria-label": `Filter ${label}`, "aria-describedby": describedBy, autoComplete: "off", readOnly: readOnly, className: "max-w-xs" }), visible.length === 0 ? (_jsx("p", { className: "type-caption text-muted-foreground", children: options.length === 0 ? emptyText : 'No matches.' })) : (_jsx(ToggleGroup, { ref: chips, multiple: true, variant: "outline", size: "sm", spacing: 1.5, value: shown.map(String), disabled: readOnly, onKeyDown: onChipsKeyDown, "aria-label": label, "aria-describedby": describedBy,
|
|
125
|
+
return (_jsxs("div", { "data-slot": "multi-pick", className: cn('flex w-full min-w-0 flex-col gap-2', className), children: [_jsx(Input, { ref: filterBox, id: id, type: "search", value: filter, onChange: (event) => setFilter(event.target.value), onKeyDown: onFilterKeyDown, placeholder: placeholder, "aria-label": `Filter ${label}`, "aria-describedby": describedBy, autoComplete: "off", readOnly: readOnly, className: "max-w-xs" }), loading ? (_jsx("p", { role: "status", className: "type-caption text-muted-foreground", children: "Loading\u2026" })) : visible.length === 0 ? (_jsx("p", { className: "type-caption text-muted-foreground", children: options.length === 0 ? emptyText : 'No matches.' })) : (_jsx(ToggleGroup, { ref: chips, multiple: true, variant: "outline", size: "sm", spacing: 1.5, value: shown.map(String), disabled: readOnly, onKeyDown: onChipsKeyDown, "aria-label": label, "aria-describedby": describedBy,
|
|
126
|
+
// Wraps at every width; a chip longer than the row ends in "…".
|
|
127
|
+
className: "w-full max-w-full min-w-0 flex-wrap", children: visible.map((option) => {
|
|
114
128
|
const picked = isPicked(option.id);
|
|
115
129
|
const saving = (pending.get(option.id)?.inFlight ?? 0) > 0;
|
|
116
|
-
return (_jsxs(ToggleGroupItem, { value: String(option.id), onPressedChange: (next) => toggle(option, next), "aria-busy": saving || undefined, "aria-describedby": refused.has(option.id) ? errorId(option.id) : undefined, children: [option.icon && (_jsx("span", { "aria-hidden": "true", className: "inline-flex shrink-0", children: option.icon })), option.label, _jsx("span", { "aria-hidden": "true", className: "inline-flex size-3.5 shrink-0 items-center justify-center", children: saving ? (_jsx(Spinner, { className: "size-3.5 text-muted-foreground" })) : (picked && _jsx(CheckIcon, { className: "size-3.5" })) })] }, option.id));
|
|
117
|
-
}) })), refused.size > 0 && (_jsx(FieldError, { className: "type-caption flex flex-col gap-0.5", children: [...refused].map(([option, reason]) => (_jsx("span", { id: errorId(option), children: reason }, String(option)))) }))] }));
|
|
130
|
+
return (_jsxs(ToggleGroupItem, { value: String(option.id), onPressedChange: (next) => toggle(option, next), "aria-busy": saving || undefined, "aria-describedby": refused.has(option.id) ? errorId(option.id) : undefined, title: option.label, className: "max-w-full min-w-0", children: [option.icon && (_jsx("span", { "aria-hidden": "true", className: "inline-flex shrink-0", children: option.icon })), _jsx("span", { className: "min-w-0 truncate", children: option.label }), _jsx("span", { "aria-hidden": "true", className: "inline-flex size-3.5 shrink-0 items-center justify-center", children: saving ? (_jsx(Spinner, { className: "size-3.5 text-muted-foreground" })) : (picked && _jsx(CheckIcon, { className: "size-3.5" })) })] }, option.id));
|
|
131
|
+
}) })), !loading && capped && hidden > 0 && (_jsxs(Button, { type: "button", variant: "link", size: "sm", className: "h-auto w-fit p-0", "aria-label": `Show all ${options.length} ${label}`, onClick: () => setShowAll(true), children: ["Show all ", options.length] })), refused.size > 0 && (_jsx(FieldError, { className: "type-caption flex flex-col gap-0.5", children: [...refused].map(([option, reason]) => (_jsx("span", { id: errorId(option), children: reason }, String(option)))) }))] }));
|
|
118
132
|
}
|
|
119
133
|
function without(map, key) {
|
|
120
134
|
if (!map.has(key))
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
2
|
+
import type { ReferenceRecord } from './reference-combobox.js';
|
|
3
|
+
export declare function MultiReference<Id extends string | number>({ options, value, onValueChange, getLabel, onSearchChange, id, placeholder, emptyText, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, 'aria-describedby': ariaDescribedBy, readOnly, searching, onCreate, className, }: {
|
|
3
4
|
/** The records the current search returned, in display order. */
|
|
4
5
|
options: readonly {
|
|
5
6
|
id: Id;
|
|
@@ -35,5 +36,11 @@ export declare function MultiReference<Id extends string | number>({ options, va
|
|
|
35
36
|
* still picks. The list is `aria-busy` meanwhile.
|
|
36
37
|
*/
|
|
37
38
|
searching?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Offers Create "<typed>" when what's typed names no option: the app
|
|
41
|
+
* opens its small create form with the name and resolves with the saved
|
|
42
|
+
* record (added to the picks), or `null` when it was cancelled.
|
|
43
|
+
*/
|
|
44
|
+
onCreate?: (name: string) => Promise<ReferenceRecord<Id> | null>;
|
|
38
45
|
className?: string;
|
|
39
46
|
}): React.JSX.Element;
|
|
@@ -17,17 +17,47 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
17
17
|
// results, its first still highlighted. `searching` says so: Enter
|
|
18
18
|
// waits rather than picking from the old list (where it could even
|
|
19
19
|
// remove a pick: the highlighted item may be one already picked).
|
|
20
|
+
// - `onCreate` (4.88, F14): Create "<typed>" as the list's last item when
|
|
21
|
+
// what's typed names no option; the app's create form resolves with the
|
|
22
|
+
// new record, which joins the picks (its name kept here until the app's
|
|
23
|
+
// lookup has it).
|
|
20
24
|
import * as React from 'react';
|
|
21
25
|
import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, ComboboxValue, useComboboxAnchor, } from '../ui/combobox.js';
|
|
26
|
+
import { namesRecord } from '../../lib/names-record.js';
|
|
22
27
|
/** Shown on a chip whose name hasn't loaded yet, instead of a bare id. */
|
|
23
28
|
const PENDING_LABEL = '…';
|
|
24
|
-
|
|
29
|
+
/** The Create "<typed>" item. */
|
|
30
|
+
const CREATE = '__create__';
|
|
31
|
+
export function MultiReference({ options, value, onValueChange, getLabel, onSearchChange, id, placeholder, emptyText = 'No matches.', 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, 'aria-describedby': ariaDescribedBy, readOnly = false, searching = false, onCreate, className, }) {
|
|
25
32
|
const anchor = useComboboxAnchor();
|
|
26
|
-
const
|
|
33
|
+
const [typed, setTyped] = React.useState('');
|
|
34
|
+
const [created] = React.useState(() => new Map());
|
|
35
|
+
const [creating, setCreating] = React.useState(false);
|
|
36
|
+
const label = (option) => getLabel(option) ?? created.get(option) ?? PENDING_LABEL;
|
|
37
|
+
const name = typed.trim();
|
|
38
|
+
const offerCreate = Boolean(onCreate) && name !== '' && !searching && !namesRecord(options, name);
|
|
39
|
+
const items = [...options.map((option) => option.id), ...(offerCreate ? [CREATE] : [])];
|
|
40
|
+
const latest = React.useRef(value);
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
latest.current = value;
|
|
43
|
+
});
|
|
44
|
+
const create = () => {
|
|
45
|
+
if (!onCreate)
|
|
46
|
+
return;
|
|
47
|
+
setCreating(true);
|
|
48
|
+
onCreate(name).then((record) => {
|
|
49
|
+
setCreating(false);
|
|
50
|
+
if (!record)
|
|
51
|
+
return;
|
|
52
|
+
created.set(record.id, record.label);
|
|
53
|
+
if (!latest.current.includes(record.id))
|
|
54
|
+
onValueChange([...latest.current, record.id]);
|
|
55
|
+
}, () => setCreating(false));
|
|
56
|
+
};
|
|
27
57
|
return (_jsxs(Combobox, { multiple: true, autoHighlight: true,
|
|
28
58
|
// Ids, not {id,label} objects: Base UI compares items to the value
|
|
29
59
|
// with Object.is, so the items must have the value's own shape.
|
|
30
|
-
items:
|
|
60
|
+
items: items, value: value, onValueChange: (next, details) => {
|
|
31
61
|
// Base UI empties the value on Escape while the list is closed, so
|
|
32
62
|
// a second Escape after a pick wiped every chip (issue #123). Escape
|
|
33
63
|
// never removes picks here: a chip's remove button, Backspace or
|
|
@@ -38,11 +68,19 @@ export function MultiReference({ options, value, onValueChange, getLabel, onSear
|
|
|
38
68
|
details.allowPropagation();
|
|
39
69
|
return;
|
|
40
70
|
}
|
|
41
|
-
|
|
42
|
-
|
|
71
|
+
const picks = next;
|
|
72
|
+
if (picks.includes(CREATE)) {
|
|
73
|
+
create();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
onValueChange(picks);
|
|
77
|
+
}, onInputValueChange: (text) => {
|
|
78
|
+
setTyped(text);
|
|
79
|
+
onSearchChange(text);
|
|
80
|
+
}, itemToStringLabel: label, filter: null, readOnly: readOnly || creating, children: [_jsx(ComboboxChips, { ref: anchor, className: className, children: _jsx(ComboboxValue, { children: (selected) => (_jsxs(React.Fragment, { children: [selected.map((option) => (_jsx(ComboboxChip, { children: label(option) }, option))), _jsx(ComboboxChipsInput, { id: id, onKeyDown: (event) => {
|
|
43
81
|
if (searching && event.key === 'Enter') {
|
|
44
82
|
event.preventDefault();
|
|
45
83
|
event.preventBaseUIHandler();
|
|
46
84
|
}
|
|
47
|
-
}, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, placeholder: selected.length === 0 ? placeholder : undefined })] })) }) }), _jsxs(ComboboxContent, { anchor: anchor, children: [_jsx(ComboboxEmpty, { children: emptyText }), _jsx(ComboboxList, { "aria-busy": searching || undefined, children: (option) => (_jsx(ComboboxItem, { value: option, children: label(option) }, option)) })] })] }));
|
|
85
|
+
}, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-busy": creating || undefined, "data-edit-hold": creating ? '' : undefined, placeholder: selected.length === 0 ? placeholder : undefined })] })) }) }), _jsxs(ComboboxContent, { anchor: anchor, children: [_jsx(ComboboxEmpty, { children: emptyText }), _jsx(ComboboxList, { "aria-busy": searching || undefined, children: (option) => (_jsx(ComboboxItem, { value: option, "data-create": option === CREATE ? '' : undefined, children: option === CREATE ? `Create "${name}"` : label(option) }, option)) })] })] }));
|
|
48
86
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { To } from 'react-router';
|
|
3
|
+
import type { AppError } from '../../api/contracts.js';
|
|
4
|
+
import { type FreshnessProps } from './freshness.js';
|
|
5
|
+
import type { IconComponent } from './icon-component.js';
|
|
6
|
+
import { type NeedsYouItem } from './needs-you.js';
|
|
7
|
+
import type { PartEmptyState } from './part-empty.js';
|
|
8
|
+
export type OverviewPart = {
|
|
9
|
+
/** Unique on the page: the tile's and the card's id. */
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
/** Decorative: the title names the part. */
|
|
13
|
+
icon?: IconComponent;
|
|
14
|
+
/** Where the part's full list or page is: its detail's title links there. */
|
|
15
|
+
to: To;
|
|
16
|
+
/** The headline: a number or a word or two ("$412,300", "3 of 7"). */
|
|
17
|
+
value?: ReactNode;
|
|
18
|
+
/** One muted line under the value, in the detail: what it means. */
|
|
19
|
+
line?: ReactNode;
|
|
20
|
+
/** How old the value is, in the tile and the detail. */
|
|
21
|
+
freshness?: FreshnessProps;
|
|
22
|
+
/** What the detail shows under the value: a few rows (WidgetList), a small chart. */
|
|
23
|
+
detail?: ReactNode;
|
|
24
|
+
/** A part with nothing yet: given, the part is empty, and its detail offers this one way to start. */
|
|
25
|
+
empty?: PartEmptyState;
|
|
26
|
+
isLoading?: boolean;
|
|
27
|
+
error?: AppError | null;
|
|
28
|
+
onRetry?: () => void;
|
|
29
|
+
};
|
|
30
|
+
export type OverviewPageProps = {
|
|
31
|
+
/** The page's h1: the module's name. */
|
|
32
|
+
title: string;
|
|
33
|
+
parts: readonly OverviewPart[];
|
|
34
|
+
/** What waits on the user, collected from the parts: NeedsYou under the title. */
|
|
35
|
+
needs?: readonly NeedsYouItem[];
|
|
36
|
+
/** A strip of key numbers under the title (a KeyStats), before Needs you. */
|
|
37
|
+
stats?: ReactNode;
|
|
38
|
+
/** Controls at the title's end. */
|
|
39
|
+
actions?: ReactNode;
|
|
40
|
+
/** The part open at first; none when left out. */
|
|
41
|
+
defaultOpen?: string | null;
|
|
42
|
+
className?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function OverviewPage({ title, parts, needs, stats, actions, defaultOpen, className, }: OverviewPageProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// A module's overview page (overview standard O1): what sums a module up
|
|
3
|
+
// rather than lists it. The title (the page's h1), an optional strip of
|
|
4
|
+
// key numbers (`stats`, a KeyStats), NeedsYou from `needs` (nothing when
|
|
5
|
+
// it's empty), then the module's parts:
|
|
6
|
+
//
|
|
7
|
+
// - from 48rem up, a grid of tiles, each at least 170px, as many as fit.
|
|
8
|
+
// A tile is a button: the part's icon and title, its `value` in the
|
|
9
|
+
// numeric type, and its `freshness`. A click opens the part's detail
|
|
10
|
+
// below the grid, one at a time (`aria-expanded`, `aria-controls` the
|
|
11
|
+
// detail); a second click, or Escape inside the detail, closes it.
|
|
12
|
+
// The detail is the part's WidgetCard: the title as a link to `to`
|
|
13
|
+
// with a chevron, `value`, `line`, the app's own `detail`, `freshness`.
|
|
14
|
+
// - under 48rem, the same WidgetCards as an accordion (WidgetCardGroup):
|
|
15
|
+
// each folded to one line with its value, opening one folds the others.
|
|
16
|
+
//
|
|
17
|
+
// A part owns its states as a WidgetCard does: `isLoading` (a skeleton in
|
|
18
|
+
// the tile and the card), `error` (a dash in the tile, ErrorState with
|
|
19
|
+
// `onRetry` in the card), and `empty` (a part with nothing yet: "Nothing
|
|
20
|
+
// yet" in the tile, PartEmpty with its one way to start in the card).
|
|
21
|
+
//
|
|
22
|
+
// The breakpoint is read with matchMedia; on the server, or where it's
|
|
23
|
+
// missing (a test's DOM), the page is drawn wide.
|
|
24
|
+
import { useId, useState, useSyncExternalStore } from 'react';
|
|
25
|
+
import { cn } from 'cn';
|
|
26
|
+
import { Freshness } from './freshness.js';
|
|
27
|
+
import { NeedsYou } from './needs-you.js';
|
|
28
|
+
import { WidgetCard, WidgetCardGroup } from './widget-card.js';
|
|
29
|
+
import { Skeleton } from '../ui/skeleton.js';
|
|
30
|
+
const WIDE_QUERY = '(min-width: 48rem)';
|
|
31
|
+
const canMatchMedia = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function';
|
|
32
|
+
function subscribeWide(listener) {
|
|
33
|
+
if (!canMatchMedia())
|
|
34
|
+
return () => { };
|
|
35
|
+
const query = window.matchMedia(WIDE_QUERY);
|
|
36
|
+
query.addEventListener('change', listener);
|
|
37
|
+
return () => query.removeEventListener('change', listener);
|
|
38
|
+
}
|
|
39
|
+
const useIsWide = () => useSyncExternalStore(subscribeWide, () => !canMatchMedia() || window.matchMedia(WIDE_QUERY).matches, () => true);
|
|
40
|
+
export function OverviewPage({ title, parts, needs = [], stats, actions, defaultOpen = null, className, }) {
|
|
41
|
+
const wide = useIsWide();
|
|
42
|
+
const detailId = useId();
|
|
43
|
+
const [openId, setOpenId] = useState(defaultOpen);
|
|
44
|
+
const open = parts.find((part) => part.id === openId);
|
|
45
|
+
const tileId = (id) => `${detailId}-tile-${id}`;
|
|
46
|
+
// Escape in the detail closes it and puts focus back on its tile.
|
|
47
|
+
const onDetailKeyDown = (event) => {
|
|
48
|
+
if (event.key !== 'Escape' || openId === null)
|
|
49
|
+
return;
|
|
50
|
+
const tile = document.getElementById(tileId(openId));
|
|
51
|
+
setOpenId(null);
|
|
52
|
+
tile?.focus();
|
|
53
|
+
};
|
|
54
|
+
return (_jsxs("div", { "data-slot": "overview-page", className: cn('flex flex-col gap-4', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("h1", { className: "type-page-title text-foreground", children: title }), actions && _jsx("div", { className: "flex shrink-0 items-center gap-2", children: actions })] }), stats, _jsx(NeedsYou, { items: needs }), wide ? (_jsxs(_Fragment, { children: [_jsx("ul", { "data-slot": "overview-tiles", className: "grid grid-cols-[repeat(auto-fill,minmax(170px,1fr))] gap-2.5", children: parts.map((part) => (_jsx("li", { className: "flex min-w-0", children: _jsx(OverviewTile, { id: tileId(part.id), part: part, open: part.id === openId, controls: detailId, onToggle: () => setOpenId(part.id === openId ? null : part.id) }) }, part.id))) }), _jsx("div", { id: detailId, "data-slot": "overview-detail", onKeyDown: onDetailKeyDown, children: open && _jsx(PartCard, { part: open }) })] })) : (_jsx(WidgetCardGroup, { accordion: true, defaultOpen: openId, className: "flex flex-col gap-2.5", children: parts.map((part) => (_jsx(PartCard, { part: part }, part.id))) }))] }));
|
|
55
|
+
}
|
|
56
|
+
function PartCard({ part }) {
|
|
57
|
+
return (_jsx(WidgetCard, { id: part.id, title: part.title, icon: part.icon, to: part.to, value: part.value, line: part.line, freshness: part.freshness, isLoading: part.isLoading ?? false, error: part.error, onRetry: part.onRetry, isEmpty: part.empty !== undefined, emptyMessage: part.empty?.text ?? 'Nothing here yet', empty: part.empty, emptySummary: "Nothing yet", className: "w-full", children: part.detail }));
|
|
58
|
+
}
|
|
59
|
+
function OverviewTile({ id, part, open, controls, onToggle, }) {
|
|
60
|
+
const { icon: Icon } = part;
|
|
61
|
+
const state = part.error ? 'error' : part.isLoading ? 'loading' : part.empty ? 'empty' : 'success';
|
|
62
|
+
return (_jsxs("button", { type: "button", id: id, "data-slot": "overview-tile", "data-state": state, "aria-expanded": open, "aria-controls": controls, onClick: onToggle, className: cn('glow-edge flex w-full min-w-0 flex-col items-start gap-0.5 rounded-lg bg-card px-3 py-2.5 text-left text-card-foreground', 'shadow-(--card-shadow) ring-1 ring-border outline-none hover:bg-muted', 'focus-visible:ring-3 focus-visible:ring-ring/50 aria-expanded:ring-2 aria-expanded:ring-primary'), children: [_jsxs("span", { className: "flex min-w-0 max-w-full items-center gap-1.5 type-label text-muted-foreground", children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0 text-link" }), _jsx("span", { className: "truncate", children: part.title })] }), state === 'loading' ? (_jsxs(_Fragment, { children: [_jsx(Skeleton, { "data-state": "loading", className: "my-1 h-6 w-16" }), _jsx("span", { className: "sr-only", children: "Loading" })] })) : state === 'error' ? (_jsxs("span", { "data-state": "error", className: "type-numeric text-muted-foreground", children: [_jsx("span", { "aria-hidden": "true", children: "\u2014" }), _jsx("span", { className: "sr-only", children: "Couldn't load" })] })) : state === 'empty' ? (_jsx("span", { "data-state": "empty", className: "py-0.5 type-body text-muted-foreground", children: "Nothing yet" })) : (part.value !== undefined && (_jsx("span", { "data-slot": "overview-tile-value", className: "max-w-full truncate type-numeric text-foreground", children: part.value }))), state === 'success' && part.freshness && _jsx(Freshness, { ...part.freshness })] }));
|
|
63
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** A record found by search: its id and its name. */
|
|
2
|
+
export type ReferenceRecord<Id> = {
|
|
3
|
+
id: Id;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
export type ReferenceComboboxProps<Id extends string | number> = {
|
|
7
|
+
/** The box's id, for the field's `<FieldLabel htmlFor>`. */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** The picked record's id, or `null`. */
|
|
10
|
+
value: Id | null;
|
|
11
|
+
onValueChange: (value: Id | null) => void;
|
|
12
|
+
/** Finds records by what's typed. Rejects to show nothing found. */
|
|
13
|
+
search: (text: string) => Promise<readonly ReferenceRecord<Id>[]>;
|
|
14
|
+
/** The picked record's name (the app's lookup by id), shown in the box. */
|
|
15
|
+
label?: string;
|
|
16
|
+
/** No "Not set" item: a record must be picked. */
|
|
17
|
+
required?: boolean;
|
|
18
|
+
/** The "Not set" item's words, for an optional reference. */
|
|
19
|
+
emptyLabel?: string;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** What the list says when nothing matches. Defaults to "No matches." */
|
|
22
|
+
emptyText?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Offers Create "<typed>" when what's typed matches no record's name.
|
|
25
|
+
* Opens the app's create form with the name; resolves with the saved
|
|
26
|
+
* record (then picked), or `null` when the form was cancelled.
|
|
27
|
+
*/
|
|
28
|
+
onCreate?: (name: string) => Promise<ReferenceRecord<Id> | null>;
|
|
29
|
+
readOnly?: boolean;
|
|
30
|
+
/** Open the list on mount (editing in place, where it opens with the field). */
|
|
31
|
+
defaultOpen?: boolean;
|
|
32
|
+
invalid?: boolean;
|
|
33
|
+
'aria-label'?: string;
|
|
34
|
+
'aria-labelledby'?: string;
|
|
35
|
+
'aria-describedby'?: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function ReferenceCombobox<Id extends string | number>({ id, value, onValueChange, search, label, required, emptyLabel, placeholder, emptyText, onCreate, readOnly, defaultOpen, invalid, ...aria }: ReferenceComboboxProps<Id>): import("react").JSX.Element;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Another record, picked from a list searched as you type: the one control
|
|
3
|
+
// for a single reference, on a form and edited in place (`inPlace.reference`
|
|
4
|
+
// draws it). The package knows no endpoint: `search` is the app's (its
|
|
5
|
+
// gateway's search by name), called with what's typed (`''` when the
|
|
6
|
+
// list opens). Names come from the searches and from the saved record's
|
|
7
|
+
// `label`, so a pick the current search no longer returns still shows its
|
|
8
|
+
// name.
|
|
9
|
+
//
|
|
10
|
+
// `onCreate` (4.88, the form standard's F14): when what's typed matches no
|
|
11
|
+
// record's name, Create "<typed>" is the list's last item. Picking it
|
|
12
|
+
// calls the app's `onCreate(name)`, which opens its small create form (a
|
|
13
|
+
// FormDialog) with the name filled in and resolves with the new record
|
|
14
|
+
// once it's saved: that record is then picked. While that form is open,
|
|
15
|
+
// an edit in place holding this control stays open (`data-edit-hold`).
|
|
16
|
+
import { useEffect, useRef, useState } from 'react';
|
|
17
|
+
import { namesRecord } from '../../lib/names-record.js';
|
|
18
|
+
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from '../ui/combobox.js';
|
|
19
|
+
/** A select's and a combobox's items are strings: a record's id, or this for "Not set". */
|
|
20
|
+
const NONE = '__none__';
|
|
21
|
+
/** The Create "<typed>" item. */
|
|
22
|
+
const CREATE = '__create__';
|
|
23
|
+
// How long typing pauses before the search runs.
|
|
24
|
+
const SEARCH_DELAY_MS = 200;
|
|
25
|
+
export function ReferenceCombobox({ id, value, onValueChange, search, label, required = false, emptyLabel = 'Not set', placeholder = 'Search', emptyText = 'No matches.', onCreate, readOnly = false, defaultOpen = false, invalid = false, ...aria }) {
|
|
26
|
+
const [text, setText] = useState('');
|
|
27
|
+
const [found, setFound] = useState([]);
|
|
28
|
+
const [creating, setCreating] = useState(false);
|
|
29
|
+
const [names] = useState(() => new Map());
|
|
30
|
+
if (value != null && label !== undefined && !names.has(String(value)))
|
|
31
|
+
names.set(String(value), { id: value, label });
|
|
32
|
+
for (const record of found)
|
|
33
|
+
names.set(String(record.id), record);
|
|
34
|
+
// The search is the app's, often a new function each render: the
|
|
35
|
+
// latest is called, and only what's typed starts a search.
|
|
36
|
+
const latestSearch = useRef(search);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
latestSearch.current = search;
|
|
39
|
+
});
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
let live = true;
|
|
42
|
+
const timer = setTimeout(() => {
|
|
43
|
+
latestSearch.current(text).then((records) => {
|
|
44
|
+
if (live)
|
|
45
|
+
setFound(records);
|
|
46
|
+
}, () => {
|
|
47
|
+
if (live)
|
|
48
|
+
setFound([]);
|
|
49
|
+
});
|
|
50
|
+
}, text === '' ? 0 : SEARCH_DELAY_MS);
|
|
51
|
+
return () => {
|
|
52
|
+
live = false;
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
};
|
|
55
|
+
}, [text]);
|
|
56
|
+
const mounted = useRef(true);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
mounted.current = true;
|
|
59
|
+
return () => {
|
|
60
|
+
mounted.current = false;
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
const typed = text.trim();
|
|
64
|
+
const offerCreate = Boolean(onCreate) && typed !== '' && !namesRecord(found, typed);
|
|
65
|
+
const picked = value == null ? null : String(value);
|
|
66
|
+
const items = [...(required ? [] : [NONE]), ...found.map((record) => String(record.id)), ...(offerCreate ? [CREATE] : [])];
|
|
67
|
+
const nameOf = (key) => (key === NONE || key === CREATE ? '' : (names.get(key)?.label ?? ''));
|
|
68
|
+
const create = (name) => {
|
|
69
|
+
if (!onCreate)
|
|
70
|
+
return;
|
|
71
|
+
setCreating(true);
|
|
72
|
+
onCreate(name).then((record) => {
|
|
73
|
+
if (mounted.current)
|
|
74
|
+
setCreating(false);
|
|
75
|
+
if (!record)
|
|
76
|
+
return;
|
|
77
|
+
names.set(String(record.id), record);
|
|
78
|
+
onValueChange(record.id);
|
|
79
|
+
}, () => {
|
|
80
|
+
if (mounted.current)
|
|
81
|
+
setCreating(false);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
return (_jsxs(Combobox, { items: items, value: picked, onValueChange: (key) => {
|
|
85
|
+
if (key == null)
|
|
86
|
+
return;
|
|
87
|
+
if (key === CREATE) {
|
|
88
|
+
create(typed);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
onValueChange(key === NONE ? null : (names.get(key)?.id ?? null));
|
|
92
|
+
},
|
|
93
|
+
// The box showing the pick's own name is no search: the list then
|
|
94
|
+
// offers everything, not only the one already picked.
|
|
95
|
+
onInputValueChange: (next) => setText(picked !== null && next === nameOf(picked) ? '' : next), itemToStringLabel: nameOf, filter: null, readOnly: readOnly || creating, defaultOpen: defaultOpen, children: [_jsx(ComboboxInput, { id: id, placeholder: placeholder, "aria-invalid": invalid || undefined, "aria-busy": creating || undefined, "data-edit-hold": creating ? '' : undefined, ...aria }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: emptyText }), _jsx(ComboboxList, { children: items.map((key) => (_jsx(ComboboxItem, { value: key, "data-create": key === CREATE ? '' : undefined, children: key === NONE ? emptyLabel : key === CREATE ? `Create "${typed}"` : nameOf(key) }, key))) })] })] }));
|
|
96
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type To } from 'react-router';
|
|
3
3
|
import type { AppError } from '../../api/contracts.js';
|
|
4
|
+
import { type FreshnessProps } from './freshness.js';
|
|
4
5
|
import type { IconComponent } from './icon-component.js';
|
|
5
6
|
import { type PartEmptyState } from './part-empty.js';
|
|
6
7
|
export interface WidgetCardProps {
|
|
@@ -16,6 +17,18 @@ export interface WidgetCardProps {
|
|
|
16
17
|
* title names the card.
|
|
17
18
|
*/
|
|
18
19
|
icon?: IconComponent;
|
|
20
|
+
/**
|
|
21
|
+
* Makes the title the link to everything the card sums up, with a
|
|
22
|
+
* chevron after it ("Net worth ›"): the overview standard's one way a
|
|
23
|
+
* card links its list (O4). Use it in place of `link`, not beside it.
|
|
24
|
+
*/
|
|
25
|
+
to?: To;
|
|
26
|
+
/** The card's headline: a number or a word or two ("$412,300", "On track"), in the numeric type. */
|
|
27
|
+
value?: ReactNode;
|
|
28
|
+
/** One muted line under `value`: what it means ("+$6,240 since Aug"). */
|
|
29
|
+
line?: ReactNode;
|
|
30
|
+
/** How old the number is: Freshness's props, drawn at the body's end. */
|
|
31
|
+
freshness?: FreshnessProps;
|
|
19
32
|
/** The title's heading level: 2 under the page's h1 (the default), deeper under a section. */
|
|
20
33
|
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
21
34
|
/**
|
|
@@ -55,7 +68,7 @@ export interface WidgetCardProps {
|
|
|
55
68
|
/**
|
|
56
69
|
* One short value shown in the header while the card is folded: a count
|
|
57
70
|
* (`3`), or a word or two (`"Due today"`). A skeleton while loading, a
|
|
58
|
-
* muted dash on an error. Ignored while open.
|
|
71
|
+
* muted dash on an error. Ignored while open. Defaults to `value`.
|
|
59
72
|
*/
|
|
60
73
|
summary?: ReactNode;
|
|
61
74
|
/** What a folded card's summary says when it's empty (`"None"`); nothing when left out. */
|
|
@@ -72,7 +85,7 @@ export type WidgetCardLink = {
|
|
|
72
85
|
label: string;
|
|
73
86
|
to?: never;
|
|
74
87
|
};
|
|
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;
|
|
88
|
+
export declare function WidgetCard({ id, title, icon: Icon, to, value, line, freshness, headingLevel, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows, collapsible, defaultCollapsed, storageKey, summary: ownSummary, emptySummary, children, className, }: WidgetCardProps): import("react").JSX.Element;
|
|
76
89
|
export interface WidgetCardGroupProps {
|
|
77
90
|
/**
|
|
78
91
|
* One card open at a time: `true` always, `"mobile"` only below the
|
|
@@ -50,15 +50,25 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
50
50
|
// switch). A trailing control is labelled by the row's text: pass a
|
|
51
51
|
// function and it gets the id to put in `aria-labelledby`.
|
|
52
52
|
//
|
|
53
|
+
// One card anatomy (overview standard O4), shared with OverviewPage's
|
|
54
|
+
// parts so the hub's widgets and an overview's parts read alike: `to`
|
|
55
|
+
// makes the title the link to everything the card sums up, with a
|
|
56
|
+
// chevron after it; `value` is its headline in the numeric type, `line`
|
|
57
|
+
// one muted line under it, and `freshness` how old the number is
|
|
58
|
+
// (Freshness) at the body's end. A folded card shows `value` as its
|
|
59
|
+
// summary when no `summary` is given. All optional: a card without them
|
|
60
|
+
// is drawn as before, and its folding on a phone is unchanged.
|
|
61
|
+
//
|
|
53
62
|
// Under data-density="compact" (#224) the card's padding drops to 12px and
|
|
54
63
|
// a row's to 4px, for a dense hub; text stays at type-body. On a phone a
|
|
55
64
|
// compact row is 44px tall and its link fills that height, so it stays a
|
|
56
65
|
// finger's target.
|
|
57
66
|
import { createContext, useContext, useId, useState } from 'react';
|
|
58
67
|
import { Link } from 'react-router';
|
|
59
|
-
import { ChevronDownIcon, ExternalLinkIcon } from 'lucide-react';
|
|
68
|
+
import { ChevronDownIcon, ChevronRightIcon, ExternalLinkIcon } from 'lucide-react';
|
|
60
69
|
import { cn } from 'cn';
|
|
61
70
|
import { ErrorState } from './error-state.js';
|
|
71
|
+
import { Freshness } from './freshness.js';
|
|
62
72
|
import { PartEmpty } from './part-empty.js';
|
|
63
73
|
import { Button } from '../ui/button.js';
|
|
64
74
|
import { Card, CardContent, CardHeader } from '../ui/card.js';
|
|
@@ -67,7 +77,8 @@ import { useIsMobile } from '../../hooks/use-mobile.js';
|
|
|
67
77
|
import { useRememberedFlag } from '../../hooks/use-remembered-flag.js';
|
|
68
78
|
const HEADER_LINK_CLASS = 'shrink-0 rounded-sm type-label text-foreground underline underline-offset-4 outline-none ' +
|
|
69
79
|
'hover:decoration-2 focus-visible:ring-3 focus-visible:ring-ring/50';
|
|
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, }) {
|
|
80
|
+
export function WidgetCard({ id, title, icon: Icon, to, value, line, freshness, headingLevel = 2, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows = 3, collapsible = false, defaultCollapsed = false, storageKey, summary: ownSummary, emptySummary, children, className, }) {
|
|
81
|
+
const summary = ownSummary ?? value;
|
|
71
82
|
const headingId = useId();
|
|
72
83
|
const contentId = useId();
|
|
73
84
|
const summaryId = useId();
|
|
@@ -91,10 +102,10 @@ export function WidgetCard({ id, title, icon: Icon, headingLevel = 2, link, isLo
|
|
|
91
102
|
return;
|
|
92
103
|
toggle();
|
|
93
104
|
};
|
|
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,
|
|
105
|
+
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" }), to !== undefined ? (_jsxs(Link, { to: to, "data-slot": "widget-card-title-link", className: "group/title -mx-1 flex min-w-0 items-center gap-0.5 rounded-sm px-1 outline-none hover:text-link focus-visible:ring-3 focus-visible:ring-ring/50", children: [_jsx("span", { className: "truncate underline-offset-4 group-hover/title:underline", children: title }), _jsx(ChevronRightIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground group-hover/title:text-link" })] })) : (_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,
|
|
95
106
|
// The button's own open look (a filled background) would
|
|
96
107
|
// read as pressed: the chevron says it.
|
|
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) })] }) }));
|
|
108
|
+
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 }))) : value !== undefined || line !== undefined || freshness !== undefined ? (_jsxs("div", { "data-slot": "widget-card-anatomy", className: "flex flex-col gap-1.5", children: [(value !== undefined || line !== undefined) && (_jsxs("div", { className: "flex flex-col gap-0.5", children: [value !== undefined && (_jsx("p", { "data-slot": "widget-card-value", className: "type-numeric text-foreground", children: value })), line !== undefined && _jsx("p", { className: "type-body text-muted-foreground", children: line })] })), children, freshness && _jsx(Freshness, { ...freshness, className: cn('self-start', freshness.className) })] })) : (children) })] }) }));
|
|
98
109
|
}
|
|
99
110
|
// A folded card's one value, by state. Loading's skeleton is about one
|
|
100
111
|
// number wide; an error's dash says "Couldn't load" to a screen reader,
|
|
@@ -21,8 +21,8 @@ declare function Field({ className, orientation, size, solo, kind, ...props }: R
|
|
|
21
21
|
solo?: boolean;
|
|
22
22
|
/**
|
|
23
23
|
* A date or a number: two of a kind stay side by side on a phone.
|
|
24
|
-
* Found by itself for a date or number `<input
|
|
25
|
-
* control of your own
|
|
24
|
+
* Found by itself for a date or number `<input>` and for DateField
|
|
25
|
+
* (which marks itself, 4.88); say it for a control of your own.
|
|
26
26
|
*/
|
|
27
27
|
kind?: FieldKind;
|
|
28
28
|
}): import("react").JSX.Element;
|
|
@@ -27,7 +27,8 @@ function FieldLegend({ className, variant = "legend", ...props }) {
|
|
|
27
27
|
}
|
|
28
28
|
// What a Field holds, when it doesn't say (`kind`): a date or a number
|
|
29
29
|
// box keeps its partner on a phone.
|
|
30
|
-
|
|
30
|
+
// DateField marks its own box (`data-kind="date"`, 4.88).
|
|
31
|
+
const DATE_CONTROL = "input[type=date], [data-kind=date]";
|
|
31
32
|
const NUMBER_CONTROL = "input[type=number], input[inputmode=numeric], input[inputmode=decimal]";
|
|
32
33
|
function kindOf(field) {
|
|
33
34
|
const said = field.dataset.kind;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export { EntityForm, type EntityFormProps } from './components/app/entity-form.j
|
|
|
18
18
|
export { countFormErrors } from './lib/form-errors.js';
|
|
19
19
|
export { FormSection, type FormSectionProps } from './components/app/form-section.js';
|
|
20
20
|
export { OptionSelect, type OptionSelectOption, type OptionSelectProps } from './components/app/option-select.js';
|
|
21
|
+
export { ChoiceButtons, type ChoiceButtonsOption, type ChoiceButtonsProps } from './components/app/choice-buttons.js';
|
|
22
|
+
export { ReferenceCombobox, type ReferenceComboboxProps, type ReferenceRecord } from './components/app/reference-combobox.js';
|
|
21
23
|
export { fieldRows, type FieldKind, type FieldRowItem, type FieldRowPlace, type FieldSize } from './lib/field-rows.js';
|
|
22
24
|
export { KeyStats, type KeyStat, type KeyStatsProps } from './components/app/key-stats.js';
|
|
23
25
|
export { IconAction, type IconActionProps } from './components/app/icon-action.js';
|
|
@@ -32,6 +34,7 @@ export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlac
|
|
|
32
34
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
33
35
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
34
36
|
export { EditableValue, type EditableValueProps } from './components/app/editable-value.js';
|
|
37
|
+
export { editRowClass, onEditRowClick, SAVED_FOR_MS } from './components/app/edit-row.js';
|
|
35
38
|
export { ErrorState } from './components/app/error-state.js';
|
|
36
39
|
export { InlineCreate, type InlineCreateProps } from './components/app/inline-create.js';
|
|
37
40
|
export { FoundationProviders } from './components/app/foundation-providers.js';
|
|
@@ -76,11 +79,12 @@ export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.j
|
|
|
76
79
|
export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.js';
|
|
77
80
|
export { ImageField, type ImageFieldProps } from './components/app/image-field.js';
|
|
78
81
|
export { DEFAULT_IMAGE_TYPES, type ImageUpload, type ImageUploadResult } from './lib/image-file.js';
|
|
79
|
-
export { formatPlainDate, type PlainDate } from './lib/plain-date.js';
|
|
82
|
+
export { formatPlainDate, parsePlainDate, plainDateExamples, unreadableDateMessage, type ParsePlainDateOptions, type PlainDate, } from './lib/plain-date.js';
|
|
80
83
|
export { formatMonthDay, isMonthDay, monthDayProblem, type MonthDay } from './lib/month-day.js';
|
|
81
84
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
|
|
82
85
|
export { ModuleCard, ModuleStrip, type CategorySlot, type ModuleCardLink, type ModuleCardPlace, type ModuleCardProps, type ModuleStripMobile, type ModuleStripProps, } from './components/app/module-card.js';
|
|
83
86
|
export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, type WidgetCardGroupProps, type WidgetCardLink, type WidgetCardProps, type WidgetListItemProps, } from './components/app/widget-card.js';
|
|
87
|
+
export { OverviewPage, type OverviewPageProps, type OverviewPart } from './components/app/overview-page.js';
|
|
84
88
|
export { WidgetLayoutSheet, type WidgetLayoutSheetProps } from './components/app/widget-layout-sheet.js';
|
|
85
89
|
export { ThemeProvider } from './components/theme-provider.js';
|
|
86
90
|
export { LoginRoute, type LoginRouteProps } from './routes/login.js';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ export { EntityForm } from './components/app/entity-form.js';
|
|
|
22
22
|
export { countFormErrors } from './lib/form-errors.js';
|
|
23
23
|
export { FormSection } from './components/app/form-section.js';
|
|
24
24
|
export { OptionSelect } from './components/app/option-select.js';
|
|
25
|
+
export { ChoiceButtons } from './components/app/choice-buttons.js';
|
|
26
|
+
export { ReferenceCombobox } from './components/app/reference-combobox.js';
|
|
25
27
|
export { fieldRows } from './lib/field-rows.js';
|
|
26
28
|
export { KeyStats } from './components/app/key-stats.js';
|
|
27
29
|
export { IconAction } from './components/app/icon-action.js';
|
|
@@ -36,6 +38,7 @@ export { inPlace, } from './components/app/edit-in-place-presets.js';
|
|
|
36
38
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
37
39
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
38
40
|
export { EditableValue } from './components/app/editable-value.js';
|
|
41
|
+
export { editRowClass, onEditRowClick, SAVED_FOR_MS } from './components/app/edit-row.js';
|
|
39
42
|
export { ErrorState } from './components/app/error-state.js';
|
|
40
43
|
export { InlineCreate } from './components/app/inline-create.js';
|
|
41
44
|
export { FoundationProviders } from './components/app/foundation-providers.js';
|
|
@@ -78,11 +81,12 @@ export { EmojiField } from './components/app/emoji-field.js';
|
|
|
78
81
|
export { MonthDayField } from './components/app/month-day-field.js';
|
|
79
82
|
export { ImageField } from './components/app/image-field.js';
|
|
80
83
|
export { DEFAULT_IMAGE_TYPES } from './lib/image-file.js';
|
|
81
|
-
export { formatPlainDate } from './lib/plain-date.js';
|
|
84
|
+
export { formatPlainDate, parsePlainDate, plainDateExamples, unreadableDateMessage, } from './lib/plain-date.js';
|
|
82
85
|
export { formatMonthDay, isMonthDay, monthDayProblem } from './lib/month-day.js';
|
|
83
86
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
|
|
84
87
|
export { ModuleCard, ModuleStrip, } from './components/app/module-card.js';
|
|
85
88
|
export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, } from './components/app/widget-card.js';
|
|
89
|
+
export { OverviewPage } from './components/app/overview-page.js';
|
|
86
90
|
export { WidgetLayoutSheet } from './components/app/widget-layout-sheet.js';
|
|
87
91
|
export { ThemeProvider } from './components/theme-provider.js';
|
|
88
92
|
// Screens outside the app shell
|