trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
40 lines • 1.87 kB
TypeScript
/**
* Trellis Forms React — `useForm` + `<Form>` / `<Field>` bindings.
*
* Import from `trellis/forms/react`:
*
* import { useForm, Form, Field } from 'trellis/forms/react';
*
* Accepts a `defineType` handle (in-process, zod validation) or a headless
* `FormDescriptor` (remote or runtime-registered schemas).
*
* @module trellis/forms/react
*/
import * as React from 'react';
import type { AnyType } from '../../schema/define.js';
import type { FormDescriptor } from '../types.js';
import { type FieldBinding, type UseFormReturn } from '../core/index.js';
import type { FormValues } from '../core/types.js';
export type FormSchemaInput = AnyType | FormDescriptor;
export interface FormFieldProps<K extends string> {
name: K;
children: (field: FieldBinding) => React.ReactElement;
}
export interface FormProps {
schema: FormSchemaInput;
initialValues?: FormValues;
onSubmit?: (values: FormValues) => Promise<void>;
children: (form: UseFormReturn) => React.ReactElement;
}
/**
* Bind a form core to React. The core is created once per schema; state
* flows through `useSyncExternalStore`.
*/
export declare function useForm(schema: FormSchemaInput, initialValues?: FormValues): UseFormReturn;
/** Read the nearest form from context (inside `<Form>`). */
export declare function useFormContext(): UseFormReturn;
/** `<form>` element wired to a form core, providing context to `<Field>`. */
export declare function Form({ schema, initialValues, onSubmit, children }: FormProps): React.FunctionComponentElement<React.ProviderProps<UseFormReturn | null>>;
/** Render-prop field binding for one attribute, from the nearest `<Form>`. */
export declare function Field<K extends string>({ name, children }: FormFieldProps<K>): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
//# sourceMappingURL=index.d.ts.map