ResourceForm
packages/ui/src/components/data/ResourceForm.tsx
Import
Subpath export:
@marktiderman/genesis-ui/dataimport { ResourceForm } from "@marktiderman/genesis-ui/data";Components
Auto-generated from TypeScript source via
react-docgen-typescript.ResourceForm
| Prop | Type | Default | Description |
|---|---|---|---|
| action* | enum | — | |
| onOpenChange* | (open: boolean) => void | — | |
| open* | boolean | — | |
| autoPlaceholder | boolean | — | 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.) |
| columns | enum | — | Number of columns for the form layout. Default 1. |
| defaults | Readonly<Record<string, Scalar>> | — | With `view`: values a new row starts with, as ResourceView's `defaults`. |
| description | string | — | 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}.". |
| fields | ResourceFormFieldDef[] | — | |
| filter | Readonly<Record<string, Scalar | readonly (string | number)[]>> | — | With `view`: the list's filter, as ResourceView's `filter` (a new row starts in it). |
| item | Record<string, unknown> | — | |
| layout | enum | — | Layout mode for the form container. Default "dialog". |
| listData | Record<string, unknown>[] | — | Full dataset used to auto-detect select fields from unique values. |
| mode | enum | — | Form presentation mode. Default "standard". |
| mutationMode | enum | — | 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 />`. |
| noun | string | — | 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. |
| prefillFromUrl | boolean | — | 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) | — | |
| resource | string | — | The resource it saves to. Default: the `view`'s. One of the two is required. |
| scoped | boolean | — | With `view`: whether a new row takes the viewer's scope (default true), as ResourceView's `scoped`. |
| steps | WizardStep[] | — | Wizard step definitions. Required when mode is "wizard". |
| submitLabel | string | — | The submit button's words ("Post", "Send"), over "Create" / "Save". |
| title | string | — | The title, over everything else. |
| undoDelayMs | number | — | How long an `undoable` save waits for an undo, in ms. Default 5000. |
| view | ResourceView<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. |
| warnWhenUnsaved | boolean | { 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`. |