@tristan2828/ui-foundation 4.87.0 → 4.88.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/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/reference-combobox.d.ts +37 -0
- package/dist/components/app/reference-combobox.js +96 -0
- package/dist/components/ui/field.d.ts +2 -2
- package/dist/components/ui/field.js +2 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -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
|
@@ -51,9 +51,16 @@ export type InPlaceMoneyConfig<TRequired extends boolean = boolean> = {
|
|
|
51
51
|
max?: number;
|
|
52
52
|
placeholder?: string;
|
|
53
53
|
};
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* A plain day, `'YYYY-MM-DD'` (DateField). Typed by default ("3/14",
|
|
56
|
+
* "Mar 14", "today"), with the calendar on its button; Enter or leaving
|
|
57
|
+
* saves, a day picked in the calendar saves at once. Not `required`:
|
|
58
|
+
* emptying the box (or Clear) saves `null`.
|
|
59
|
+
*/
|
|
55
60
|
export type InPlaceDateConfig<TRequired extends boolean = boolean> = {
|
|
56
61
|
required?: TRequired;
|
|
62
|
+
/** `false`: DateField's button alone, its calendar opening with the field and a pick saving. */
|
|
63
|
+
typing?: boolean;
|
|
57
64
|
/** How the day reads. Defaults to `{ dateStyle: 'medium' }`. */
|
|
58
65
|
format?: Intl.DateTimeFormatOptions;
|
|
59
66
|
locale?: string;
|
|
@@ -76,9 +83,17 @@ export type InPlaceOption<T> = {
|
|
|
76
83
|
value: T;
|
|
77
84
|
label: string;
|
|
78
85
|
};
|
|
79
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* One of a fixed list. Not `required`: the list starts with "Not set",
|
|
88
|
+
* which saves `null` (as buttons, pressing the picked one again does).
|
|
89
|
+
*/
|
|
80
90
|
export type InPlaceSelectConfig<T extends string | number, TRequired extends boolean = boolean> = {
|
|
81
91
|
required?: TRequired;
|
|
92
|
+
/**
|
|
93
|
+
* `select` (the default): OptionSelect, its list opening with the field.
|
|
94
|
+
* `buttons`: ChoiceButtons, for two to four short options; a press saves.
|
|
95
|
+
*/
|
|
96
|
+
look?: 'select' | 'buttons';
|
|
82
97
|
/** Every option, in the order the list shows them. */
|
|
83
98
|
options: readonly InPlaceOption<T>[];
|
|
84
99
|
/** How an option reads, at rest, on the trigger and in the list (a badge). Defaults to its label. */
|
|
@@ -108,6 +123,14 @@ export type InPlaceReferenceConfig<Id extends string | number, TRequired extends
|
|
|
108
123
|
placeholder?: string;
|
|
109
124
|
/** What the list says when nothing matches. Defaults to "No matches." */
|
|
110
125
|
emptyText?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Offers Create "<typed text>" as the list's last item when what's typed
|
|
128
|
+
* matches no record's name. Called with the typed name: the app opens its
|
|
129
|
+
* small create form (a FormDialog) with the name filled in, and resolves
|
|
130
|
+
* with the record once it's saved, which is then picked (and, in place,
|
|
131
|
+
* saved); `null` if the form was cancelled.
|
|
132
|
+
*/
|
|
133
|
+
onCreate?: (name: string) => Promise<InPlaceRecord<Id> | null>;
|
|
111
134
|
};
|
|
112
135
|
/** A link: its address and an optional label, as the app maps them to its own fields. */
|
|
113
136
|
export type InPlaceLinkValue = {
|
|
@@ -185,9 +208,20 @@ export declare const inPlace: {
|
|
|
185
208
|
* Reads as "Mar 14"; February 29 is a day, February 30 is refused.
|
|
186
209
|
*/
|
|
187
210
|
monthDay<R extends boolean = false>(options: Common<MonthDay | null | undefined, InPlaceSaved<MonthDay, R>> & InPlaceMonthDayConfig<R>): EditInPlace;
|
|
188
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* One of a fixed list; its list opens with the field and a pick saves.
|
|
213
|
+
* `look: 'buttons'` draws it as ChoiceButtons (`inPlace.choice`).
|
|
214
|
+
*/
|
|
189
215
|
select<T extends string | number, R extends boolean = false>(options: Common<T | null | undefined, InPlaceSaved<T, R>> & InPlaceSelectConfig<T, R>): EditInPlace;
|
|
190
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* Two to four short options as a row of buttons (ChoiceButtons); a press
|
|
218
|
+
* saves. `inPlace.select` with `look: 'buttons'`.
|
|
219
|
+
*/
|
|
220
|
+
choice<T extends string | number, R extends boolean = false>(options: Common<T | null | undefined, InPlaceSaved<T, R>> & Omit<InPlaceSelectConfig<T, R>, "look">): EditInPlace;
|
|
221
|
+
/**
|
|
222
|
+
* Another record, searched as you type through the app's `search`; a
|
|
223
|
+
* pick saves its id. With `onCreate`, Create "<typed>" makes one.
|
|
224
|
+
*/
|
|
191
225
|
reference<Id extends string | number, R extends boolean = false>(options: Common<Id | null | undefined, InPlaceSaved<Id, R>> & InPlaceReferenceConfig<Id, R>): EditInPlace;
|
|
192
226
|
/**
|
|
193
227
|
* A link: at rest its label (or the address's host when it has none),
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Input } from '../ui/input.js';
|
|
3
3
|
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '../ui/input-group.js';
|
|
4
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
5
4
|
import { linkHost, linkRule } from '../../lib/link-href.js';
|
|
6
5
|
import { formatMonthDay, monthDayProblem } from '../../lib/month-day.js';
|
|
7
|
-
import { formatPlainDate } from '../../lib/plain-date.js';
|
|
6
|
+
import { formatPlainDate, unreadableDateMessage } from '../../lib/plain-date.js';
|
|
7
|
+
import { ChoiceButtons } from './choice-buttons.js';
|
|
8
8
|
import { DateField } from './date-field.js';
|
|
9
9
|
import { MonthDayField } from './month-day-field.js';
|
|
10
|
-
import {
|
|
10
|
+
import { OptionSelect } from './option-select.js';
|
|
11
|
+
import { Parts, ReferencePicker } from './edit-in-place-controls.js';
|
|
11
12
|
import { LinkOut } from './row-edit-cells.js';
|
|
12
13
|
const REQUIRED = 'Required';
|
|
13
14
|
// The props every control spreads onto its element.
|
|
@@ -115,6 +116,8 @@ function moneyKind(config) {
|
|
|
115
116
|
};
|
|
116
117
|
}
|
|
117
118
|
function dateKind(config) {
|
|
119
|
+
if (config.typing !== false)
|
|
120
|
+
return typedDateKind(config);
|
|
118
121
|
return {
|
|
119
122
|
editKind: 'choice',
|
|
120
123
|
toDraft: (value) => value ?? '',
|
|
@@ -135,6 +138,22 @@ function dateKind(config) {
|
|
|
135
138
|
: undefined, "aria-label": props.label, "aria-describedby": props.describedBy })),
|
|
136
139
|
};
|
|
137
140
|
}
|
|
141
|
+
// Typed: Enter (a one-line field's key) or leaving saves the day typed; a
|
|
142
|
+
// day picked in the calendar saves at once. Something unreadable is the
|
|
143
|
+
// field's problem, so it isn't saved.
|
|
144
|
+
function typedDateKind(config) {
|
|
145
|
+
return {
|
|
146
|
+
editKind: 'text',
|
|
147
|
+
toDraft: (value) => value ?? '',
|
|
148
|
+
check: (draft) => {
|
|
149
|
+
if (draft === '')
|
|
150
|
+
return config.required ? { ok: false, message: REQUIRED } : { ok: true, value: null };
|
|
151
|
+
return formatPlainDate(draft) === '' ? { ok: false, message: unreadableDateMessage(config.locale) } : { ok: true, value: draft };
|
|
152
|
+
},
|
|
153
|
+
show: (value) => (value ? formatPlainDate(value, config.format, config.locale) || value : null),
|
|
154
|
+
control: (props, alone) => (_jsx(DateField, { id: props.id, value: props.value, onChange: props.onChange, onPick: alone ? (day) => props.commit(day) : props.onChange, onProblem: props.onProblem, clearable: !config.required, placeholder: config.placeholder, format: config.format, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, modal: false, "aria-label": props.label, "aria-describedby": props.describedBy })),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
138
157
|
function monthDayKind(config) {
|
|
139
158
|
return {
|
|
140
159
|
editKind: 'choice',
|
|
@@ -161,34 +180,23 @@ function monthDayKind(config) {
|
|
|
161
180
|
function selectKind(config) {
|
|
162
181
|
const labelOf = (value) => config.options.find((option) => option.value === value)?.label ?? String(value);
|
|
163
182
|
const shownOf = (value) => (config.render ? config.render(value, labelOf(value)) : labelOf(value));
|
|
164
|
-
const keyOf = (value) => {
|
|
165
|
-
const at = value == null ? -1 : config.options.findIndex((option) => option.value === value);
|
|
166
|
-
return at === -1 ? null : String(at);
|
|
167
|
-
};
|
|
168
|
-
const valueOf = (key) => (key === null || key === NONE ? null : (config.options[Number(key)]?.value ?? null));
|
|
169
183
|
const emptyLabel = config.emptyLabel ?? 'Not set';
|
|
170
184
|
return {
|
|
171
185
|
editKind: 'choice',
|
|
172
186
|
toDraft: (value) => value,
|
|
173
187
|
check: (draft) => (draft == null && config.required ? { ok: false, message: REQUIRED } : { ok: true, value: draft }),
|
|
174
188
|
show: (value) => (value == null ? null : shownOf(value)),
|
|
175
|
-
control: (props, alone) =>
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
props.cancel();
|
|
187
|
-
}
|
|
188
|
-
: undefined, children: [_jsx(SelectTrigger, { id: props.id, className: "min-w-40", ...controlAria(props), children: _jsx(SelectValue, { placeholder: config.placeholder ?? 'Pick one', children: (key) => {
|
|
189
|
-
const value = valueOf(key);
|
|
190
|
-
return value == null ? (key === NONE ? emptyLabel : (config.placeholder ?? 'Pick one')) : shownOf(value);
|
|
191
|
-
} }) }), _jsxs(SelectContent, { children: [!config.required && _jsx(SelectItem, { value: NONE, children: emptyLabel }), config.options.map((option, index) => (_jsx(SelectItem, { value: String(index), children: shownOf(option.value) }, String(option.value))))] })] })),
|
|
189
|
+
control: (props, alone) => {
|
|
190
|
+
const pick = (picked) => (alone ? props.commit(picked) : props.onChange(picked));
|
|
191
|
+
if (config.look === 'buttons')
|
|
192
|
+
return (_jsx(ChoiceButtons, { id: props.id, options: config.options, value: props.value, onValueChange: pick, render: config.render, clearable: !config.required, disabled: props.disabled, ...controlAria(props) }));
|
|
193
|
+
return (_jsx(OptionSelect, { id: props.id, options: config.options, value: props.value, onValueChange: pick, render: config.render, required: config.required, emptyLabel: emptyLabel, placeholder: config.placeholder, disabled: props.disabled, defaultOpen: alone, modal: false, onOpenChange: alone
|
|
194
|
+
? (open) => {
|
|
195
|
+
if (!open)
|
|
196
|
+
props.cancel();
|
|
197
|
+
}
|
|
198
|
+
: undefined, className: "w-auto min-w-40", ...controlAria(props) }));
|
|
199
|
+
},
|
|
192
200
|
};
|
|
193
201
|
}
|
|
194
202
|
function referenceKind(config) {
|
|
@@ -413,11 +421,24 @@ export const inPlace = {
|
|
|
413
421
|
monthDay(options) {
|
|
414
422
|
return single(monthDayKind(options), { ...options, value: options.value || null });
|
|
415
423
|
},
|
|
416
|
-
/**
|
|
424
|
+
/**
|
|
425
|
+
* One of a fixed list; its list opens with the field and a pick saves.
|
|
426
|
+
* `look: 'buttons'` draws it as ChoiceButtons (`inPlace.choice`).
|
|
427
|
+
*/
|
|
417
428
|
select(options) {
|
|
418
429
|
return single(selectKind(options), { ...options, value: options.value ?? null });
|
|
419
430
|
},
|
|
420
|
-
/**
|
|
431
|
+
/**
|
|
432
|
+
* Two to four short options as a row of buttons (ChoiceButtons); a press
|
|
433
|
+
* saves. `inPlace.select` with `look: 'buttons'`.
|
|
434
|
+
*/
|
|
435
|
+
choice(options) {
|
|
436
|
+
return single(selectKind({ ...options, look: 'buttons' }), { ...options, value: options.value ?? null });
|
|
437
|
+
},
|
|
438
|
+
/**
|
|
439
|
+
* Another record, searched as you type through the app's `search`; a
|
|
440
|
+
* pick saves its id. With `onCreate`, Create "<typed>" makes one.
|
|
441
|
+
*/
|
|
421
442
|
reference(options) {
|
|
422
443
|
return single(referenceKind(options), { ...options, value: options.value ?? null });
|
|
423
444
|
},
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MouseEvent } from 'react';
|
|
2
|
+
/** How long "✓ Saved" stays beside a value once its save lands. */
|
|
3
|
+
export declare const SAVED_FOR_MS = 2000;
|
|
4
|
+
/** The classes that make a field row the target of the `look="row"` EditableValue inside it. */
|
|
5
|
+
export declare const editRowClass: string;
|
|
6
|
+
/** The row's click: anywhere on it but a link, a button or the open control opens its value. */
|
|
7
|
+
export declare function onEditRowClick(event: MouseEvent<HTMLElement>): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** How long "✓ Saved" stays beside a value once its save lands. */
|
|
2
|
+
export const SAVED_FOR_MS = 2000;
|
|
3
|
+
/** The classes that make a field row the target of the `look="row"` EditableValue inside it. */
|
|
4
|
+
export const editRowClass = [
|
|
5
|
+
'group/edit-row cursor-text rounded-md transition-colors',
|
|
6
|
+
'hover:bg-(--table-hover) hover:shadow-[inset_3px_0_0_0_var(--primary)]',
|
|
7
|
+
'has-[[data-edit]:focus-visible]:bg-(--table-hover) has-[[data-edit]:focus-visible]:shadow-[inset_3px_0_0_0_var(--primary)]',
|
|
8
|
+
// Muted words (the label, "Not set") read as foreground on the tint.
|
|
9
|
+
'hover:[&_.text-muted-foreground]:text-foreground has-[[data-edit]:focus-visible]:[&_.text-muted-foreground]:text-foreground',
|
|
10
|
+
// Open, the control has its own look: no row hover over it. (Written
|
|
11
|
+
// out whole: Tailwind finds classes by reading the source.)
|
|
12
|
+
'has-[[data-slot=editable-value][data-state]]:cursor-auto has-[[data-slot=editable-value][data-state]]:bg-transparent has-[[data-slot=editable-value][data-state]]:shadow-none has-[[data-slot=editable-value][data-state]]:[&_.text-muted-foreground]:text-muted-foreground',
|
|
13
|
+
// A finger's target.
|
|
14
|
+
'max-md:min-h-11 pointer-coarse:min-h-11',
|
|
15
|
+
].join(' ');
|
|
16
|
+
// What a click on the row leaves alone: links, buttons and boxes, and the open control.
|
|
17
|
+
const LEAVE_ALONE = 'a[href], button, input, select, textarea, [role="button"], [role="link"], [role="checkbox"], [role="switch"], [role="combobox"], [role="listbox"], [data-slot=editable-value][data-state]';
|
|
18
|
+
/** The row's click: anywhere on it but a link, a button or the open control opens its value. */
|
|
19
|
+
export function onEditRowClick(event) {
|
|
20
|
+
if (event.target.closest(LEAVE_ALONE))
|
|
21
|
+
return;
|
|
22
|
+
event.currentTarget.querySelector('[data-slot="editable-value"] [data-edit]')?.click();
|
|
23
|
+
}
|
|
@@ -9,6 +9,13 @@ export type EditableValueProps = {
|
|
|
9
9
|
children?: ReactNode;
|
|
10
10
|
/** `inline` in a heading or beside badges, `block` in a field row (default). */
|
|
11
11
|
layout?: 'inline' | 'block';
|
|
12
|
+
/**
|
|
13
|
+
* `value` (the default): hover tints the value itself, as in a header's
|
|
14
|
+
* strip or a title. `row`: the field list's row is the target and wears
|
|
15
|
+
* the hover (edit-row.ts's `editRowClass` on it, as EntityView's rows
|
|
16
|
+
* have); under 48rem or on a touch screen a chevron, not the pencil.
|
|
17
|
+
*/
|
|
18
|
+
look?: 'value' | 'row';
|
|
12
19
|
className?: string;
|
|
13
20
|
};
|
|
14
21
|
/** EditableValue's own props, plus what a list's rows and its Add box need (editable-list.tsx). */
|
|
@@ -23,7 +30,7 @@ export type EditableFieldProps = EditableValueProps & {
|
|
|
23
30
|
reopenAfterKeyboardSave?: boolean;
|
|
24
31
|
};
|
|
25
32
|
export declare function EditableValue(props: EditableValueProps): import("react").JSX.Element;
|
|
26
|
-
export declare function EditableField({ label, edit, children, layout, className, trigger, reopenAfterKeyboardSave, }: EditableFieldProps): import("react").JSX.Element;
|
|
33
|
+
export declare function EditableField({ label, edit, children, layout, look, className, trigger, reopenAfterKeyboardSave, }: EditableFieldProps): import("react").JSX.Element;
|
|
27
34
|
/**
|
|
28
35
|
* While a field holds something unsaved, leaving asks first: an in-app
|
|
29
36
|
* link or Back (React Router's blocker, so the app needs a data router),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// A value on a record's view that turns into its form control where it's
|
|
3
3
|
// shown, and saves when you leave it (cell-patterns.md "Editable value").
|
|
4
4
|
// EntityView wraps every field, section and title marked `edit`; a header
|
|
@@ -18,7 +18,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
18
18
|
// click to open, and never closes. Ctrl/Cmd+Enter and Esc save now.
|
|
19
19
|
// - `inline`: always editable, and the control is told to look like the
|
|
20
20
|
// value it edits (`inline` among its props).
|
|
21
|
-
|
|
21
|
+
// - Saved (4.88, F16): once a save lands, "✓ Saved" shows beside the value
|
|
22
|
+
// for two seconds (`role="status"`).
|
|
23
|
+
// - `look="row"` (4.88, F15 and F18): in a record's field list the row is
|
|
24
|
+
// the target (edit-row.ts): it wears the list's row hover and the pencil
|
|
25
|
+
// sits at its end; under 48rem or on a touch screen there's a chevron
|
|
26
|
+
// instead of the pencil. The control still opens in the row.
|
|
27
|
+
import { CheckIcon, ChevronRightIcon, PencilIcon } from 'lucide-react';
|
|
22
28
|
import { useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
23
29
|
import { useBlocker } from 'react-router';
|
|
24
30
|
import { cn } from 'cn';
|
|
@@ -27,6 +33,7 @@ import { DiscardChangesDialog } from '../ui/dialog.js';
|
|
|
27
33
|
import { FieldError } from '../ui/field.js';
|
|
28
34
|
import { Spinner } from '../ui/spinner.js';
|
|
29
35
|
import { EditInPlaceContext } from './edit-in-place.js';
|
|
36
|
+
import { SAVED_FOR_MS } from './edit-row.js';
|
|
30
37
|
import { escapePassedThrough } from './escape-passthrough.js';
|
|
31
38
|
// What a click on the shown value must leave alone: links navigate,
|
|
32
39
|
// buttons and boxes do their own thing (a list item's done box ticks it).
|
|
@@ -42,6 +49,9 @@ const FOCUS_ORDER = [
|
|
|
42
49
|
// Focus moving here doesn't save the field: a link that leaves the page
|
|
43
50
|
// (the leave prompt decides what happens to the draft) or the prompt itself.
|
|
44
51
|
const LEAVING = 'a[href]:not([target="_blank"]), [data-leave-guard]';
|
|
52
|
+
// A control holding the field open while something of the app's is in
|
|
53
|
+
// front of it (ReferenceCombobox's create form): leaving doesn't save.
|
|
54
|
+
const HOLD = '[data-edit-hold]';
|
|
45
55
|
// The field's own control, given what it needs.
|
|
46
56
|
function Control({ render, ...props }) {
|
|
47
57
|
return render(props);
|
|
@@ -55,7 +65,7 @@ function useStore() {
|
|
|
55
65
|
export function EditableValue(props) {
|
|
56
66
|
return _jsx(EditableField, { ...props });
|
|
57
67
|
}
|
|
58
|
-
export function EditableField({ label, edit, children, layout = 'block', className, trigger, reopenAfterKeyboardSave = false, }) {
|
|
68
|
+
export function EditableField({ label, edit, children, layout = 'block', look = 'value', className, trigger, reopenAfterKeyboardSave = false, }) {
|
|
59
69
|
const store = useStore();
|
|
60
70
|
const key = useId();
|
|
61
71
|
const controlId = `${key}-control`;
|
|
@@ -70,6 +80,22 @@ export function EditableField({ label, edit, children, layout = 'block', classNa
|
|
|
70
80
|
});
|
|
71
81
|
useEffect(() => store.register(key, () => config.current), [store, key]);
|
|
72
82
|
const state = useSyncExternalStore(store.subscribe, () => store.state(key), () => store.state(key));
|
|
83
|
+
// "✓ Saved" for a moment once a save lands (saving, then closed).
|
|
84
|
+
const [justSaved, setJustSaved] = useState(false);
|
|
85
|
+
const [seenStatus, setSeenStatus] = useState(state.status);
|
|
86
|
+
if (seenStatus !== state.status) {
|
|
87
|
+
setSeenStatus(state.status);
|
|
88
|
+
if (seenStatus === 'saving' && state.status === 'closed')
|
|
89
|
+
setJustSaved(true);
|
|
90
|
+
else if (state.status !== 'closed')
|
|
91
|
+
setJustSaved(false);
|
|
92
|
+
}
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!justSaved)
|
|
95
|
+
return;
|
|
96
|
+
const timer = window.setTimeout(() => setJustSaved(false), SAVED_FOR_MS);
|
|
97
|
+
return () => window.clearTimeout(timer);
|
|
98
|
+
}, [justSaved]);
|
|
73
99
|
const editButton = useRef(null);
|
|
74
100
|
// Holds a trigger (the list's Add): its button is the one the caret goes back to.
|
|
75
101
|
const triggerBox = useRef(null);
|
|
@@ -196,6 +222,8 @@ export function EditableField({ label, edit, children, layout = 'block', classNa
|
|
|
196
222
|
blurTimer.current = window.setTimeout(() => {
|
|
197
223
|
if (store.state(key).status !== 'open')
|
|
198
224
|
return;
|
|
225
|
+
if (container.current?.querySelector(HOLD))
|
|
226
|
+
return;
|
|
199
227
|
void store.commit(key).then(() => {
|
|
200
228
|
if (always)
|
|
201
229
|
refresh();
|
|
@@ -206,7 +234,11 @@ export function EditableField({ label, edit, children, layout = 'block', classNa
|
|
|
206
234
|
if (state.status === 'closed' && !always) {
|
|
207
235
|
if (trigger)
|
|
208
236
|
return (_jsx("span", { ref: triggerBox, className: "contents", children: trigger(start) }));
|
|
209
|
-
|
|
237
|
+
const row = look === 'row';
|
|
238
|
+
return (_jsxs("span", { "data-slot": "editable-value", "data-look": look, onClick: onShownClick, className: cn('group/editable relative cursor-text items-start gap-1',
|
|
239
|
+
// A row: the row (editRowClass) wears the hover, not the value.
|
|
240
|
+
!row && '-mx-1.5 rounded-md px-1.5 transition-colors hover:bg-muted has-[[data-edit]:focus-visible]:bg-muted', layout === 'block' ? 'flex w-full' : 'inline-flex max-w-full align-top', className), children: [_jsxs("span", { className: cn('min-w-0 flex-1', !row &&
|
|
241
|
+
'group-hover/editable:[&_.text-muted-foreground]:text-foreground group-has-[[data-edit]:focus-visible]/editable:[&_.text-muted-foreground]:text-foreground'), children: [children !== undefined ? children : edit.shown, _jsx("span", { role: "status", "data-slot": "editable-value-saved", className: "ml-2 inline-flex items-center gap-1 align-baseline type-caption text-success-text empty:hidden", children: justSaved && (_jsxs(_Fragment, { children: [_jsx(CheckIcon, { "aria-hidden": "true", className: "size-3.5" }), "Saved"] })) })] }), _jsx(Button, { ref: editButton, "data-edit": "", type: "button", variant: "ghost", size: "icon-xs", "aria-label": `Edit ${label}`, onClick: start, className: cn('shrink-0 text-muted-foreground opacity-0 focus-visible:opacity-100 pointer-coarse:opacity-100', row ? 'group-hover/edit-row:opacity-100 hover:bg-transparent max-md:opacity-100' : 'group-hover/editable:opacity-100'), children: row ? (_jsxs(_Fragment, { children: [_jsx(PencilIcon, { className: "max-md:hidden pointer-coarse:hidden" }), _jsx(ChevronRightIcon, { className: "hidden max-md:block pointer-coarse:block" })] })) : (_jsx(PencilIcon, {})) })] }));
|
|
210
242
|
}
|
|
211
243
|
// Always editable, before the store has it (the first render): the saved value.
|
|
212
244
|
const open = state.status === 'closed' ? { status: 'open', draft: edit.value, error: null, autosave: undefined, revision: 0 } : state;
|
|
@@ -92,6 +92,7 @@ import { PrintNotes } from './entity-view-print.js';
|
|
|
92
92
|
import { EditInPlaceContext } from './edit-in-place.js';
|
|
93
93
|
import { EditInPlaceStore } from './edit-in-place-store.js';
|
|
94
94
|
import { EditableList } from './editable-list.js';
|
|
95
|
+
import { editRowClass, onEditRowClick } from './edit-row.js';
|
|
95
96
|
import { EditableValue, LeaveGuard } from './editable-value.js';
|
|
96
97
|
import { EmptyText } from './empty-value.js';
|
|
97
98
|
import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
|
|
@@ -133,7 +134,10 @@ const FIELD_ROW = {
|
|
|
133
134
|
};
|
|
134
135
|
function FieldRow({ field, place }) {
|
|
135
136
|
const value = fieldValue(field);
|
|
136
|
-
|
|
137
|
+
// An editable row is the target as a whole (4.88, F15/F18): the list's
|
|
138
|
+
// row hover, its pencil at the end, a chevron on a phone.
|
|
139
|
+
const editable = Boolean(field.edit);
|
|
140
|
+
return (_jsxs("div", { className: cn('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[place], editable && cn(editRowClass, '-mx-2 px-2 first:pt-2 last:pb-2')), onClick: editable ? onEditRowClick : undefined, children: [_jsx("dt", { className: "type-label text-muted-foreground", children: field.label }), _jsx("dd", { className: "min-w-0 type-body break-words text-foreground", children: field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, look: "row", children: _jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }) })) : (_jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel })) })] }));
|
|
137
141
|
}
|
|
138
142
|
// A fields card's rows. Folded (`emptyFields="fold"`), the filled fields
|
|
139
143
|
// show and the empty ones wait behind "N empty", which opens them in their
|
|
@@ -36,8 +36,15 @@ export type MultiPickProps<Id extends string | number> = {
|
|
|
36
36
|
placeholder?: string;
|
|
37
37
|
/** Shown when there are no options at all. */
|
|
38
38
|
emptyText?: string;
|
|
39
|
+
/**
|
|
40
|
+
* How many options show before "Show all N": past it, the picked ones
|
|
41
|
+
* and the first `limit`. Defaults to 30. A filter always searches them all.
|
|
42
|
+
*/
|
|
43
|
+
limit?: number;
|
|
44
|
+
/** The options are still loading (the app's query of its records): "Loading…" in place of the chips. */
|
|
45
|
+
loading?: boolean;
|
|
39
46
|
/** Shown, not changeable. */
|
|
40
47
|
readOnly?: boolean;
|
|
41
48
|
className?: string;
|
|
42
49
|
};
|
|
43
|
-
export declare function MultiPick<Id extends string | number>({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder, emptyText, readOnly, className, }: MultiPickProps<Id>): import("react").JSX.Element;
|
|
50
|
+
export declare function MultiPick<Id extends string | number>({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder, emptyText, limit, loading, readOnly, className, }: MultiPickProps<Id>): import("react").JSX.Element;
|
|
@@ -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,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;
|