@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
38 lines (37 loc) • 1.94 kB
TypeScript
import { type FormHTMLAttributes, type ReactNode } from 'react';
import { type AnyKitForm } from '../../../runtime/formRuntime.js';
export interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'onReset' | 'children'> {
/** The form from `useAppForm` (or any TanStack form). */
form: AnyKitForm;
/** `view` renders every field's display value instead of its control. */
mode?: 'edit' | 'view';
/**
* In view mode (here or in a `FormReview` inside), clamp each value to about this many lines,
* with a "Show more" toggle. Values that fit show no toggle. Default: no clamp.
*/
viewLines?: number;
/** Disables every field inside (not focusable, not validated, submitted as-is). */
disabled?: boolean;
/** Makes every field read-only (focusable, not editable, not validated). */
readOnly?: boolean;
children: ReactNode;
}
/**
* The form element, wired to the kit. Submitting runs validation and your onSubmit; disabled,
* readOnly and view mode cascade to every field.
*
* @remarks
* `Form` renders a `<form noValidate>` and connects it to a form from `useAppForm`. Pressing Enter
* or a submit button validates and calls your `onSubmit`; a submit while one is already in flight
* is ignored; a reset button resets the form. It forwards its ref to the `<form>`.
*
* @example In a schema
* A schema renders inside a `Form`: `<Form form={form}><SchemaForm form={form} schema={schema}
* /></Form>`.
*
* @privateRemarks
* `<form noValidate>` wired to the kit: submit runs the pipeline (§5.5) and is ignored while a
* submit is in flight or the form is locked; reset returns to the baseline. Provides the form
* to `useFormContext()` and cascades `mode` / `viewLines` / `disabled` / `readOnly` to fields.
*/
export declare const Form: import("react").ForwardRefExoticComponent<FormProps & import("react").RefAttributes<HTMLFormElement>>;