Genesis
@stable

ResourceForm

packages/ui/src/components/data/ResourceForm.tsx

Import
Subpath export: @marktiderman/genesis-ui/data
import { ResourceForm } from "@marktiderman/genesis-ui/data";
Components
Auto-generated from TypeScript source via react-docgen-typescript.

ResourceForm

PropTypeDefaultDescription
action*enum—
onOpenChange*(open: boolean) => void—
open*boolean—
autoPlaceholderboolean—Generate a placeholder ("Enter name") for fields whose `placeholder` is unset. Default `false`: a placeholder that restates the label adds noise, and reads as a filled value at a glance. A field's own `placeholder` always shows. (Select fields keep their "Select…" prompt either way.)
columnsenum—Number of columns for the form layout. Default 1.
defaultsReadonly<Record<string, Scalar>>—With `view`: values a new row starts with, as ResourceView's `defaults`.
descriptionstring—The form's description, read out with its title (`aria-describedby`), over the UI catalogue's "Fill in the details to create a new {noun}." / "Update the {noun}.".
fieldsResourceFormFieldDef[]—
filterReadonly<Record<string, Scalar | readonly (string | number)[]>>—With `view`: the list's filter, as ResourceView's `filter` (a new row starts in it).
itemRecord<string, unknown>—
layoutenum—Layout mode for the form container. Default "dialog".
listDataRecord<string, unknown>[]—Full dataset used to auto-detect select fields from unique values.
modeenum—Form presentation mode. Default "standard".
mutationModeenum—When a save reaches the list. Default `"pessimistic"`: the form waits for the provider. `"optimistic"` closes at once and updates the cached list, putting it back (and toasting the error) if the save fails. `"undoable"` does the same and shows an Undo toast; the save is sent after `undoDelayMs` unless undone (or at once, undone by the provider, when it serves `undo`). Needs a mounted `<Toaster />`.
nounstring—What one record is called ("goal"): the title reads "New goal" / "Edit goal" (the UI catalogue's `form`). Without it the title is built from `resource`, as before.
onDirtyChange((isDirty: boolean, confirmLeave: () => boolean) => void)—Called when the form becomes dirty or clean, with a `confirmLeave` that asks when needed: the hook for a router blocker (SKILL.md "Unsaved changes").
onError((error: Error) => void)—
onSuccess((data: Record<string, unknown>) => void)—
onUndoable((write: UndoableWrite) => void)—Replaces the undo toast.
prefillFromUrlboolean—Pre-fill a create form from the page URL: a query param named like a field (`?status=draft`) becomes that field's starting value. Default `true`, as before. Pass `false` when the page's query string means something else — a list's own filters, say — and must not leak into the new record.
renderForm((form: UseFormReturn<Record<string, unknown>>, fields: ResourceFormFieldDef[]) => ReactNode)—
resourcestring—The resource it saves to. Default: the `view`'s. One of the two is required.
scopedboolean—With `view`: whether a new row takes the viewer's scope (default true), as ResourceView's `scoped`.
stepsWizardStep[]—Wizard step definitions. Required when mode is "wizard".
submitLabelstring—The submit button's words ("Post", "Send"), over "Create" / "Save".
titlestring—The title, over everything else.
undoDelayMsnumber—How long an `undoable` save waits for an undo, in ms. Default 5000.
viewResourceView<ResourceContract<any>, any>—A `defineView` description: the form `<ResourceView>` would open for it, with no list around it (a form beside a sortable list, say). Its fields (only what a writer may send, links as pickers, the viewer's scope filled hidden on create), its noun and its `copy.form` words. The props below win: `fields` replaces the view's fields, and `title`, `submitLabel`, `description` and `noun` replace its words.
warnWhenUnsavedboolean | { message?: string; }—Warn before unsaved changes are lost. Default false. While the form is dirty, Cancel / Esc / clicking outside asks first, and closing or reloading the tab shows the browser's prompt. Pass `{ message }` to change the question. For router navigation, see `onDirtyChange`.