Skip to Content
Prism UI
Reference

@prismrepo/forms

Registry and form-builder contracts. Full public export list.

Depends only on @prismrepo/core. Must not import react-hook-form or zod at runtime, and doesn't depend on either adapter package.

defineRegistry(entries)

function defineRegistry<const TRegistry extends FieldRegistry>(
  entries: TRegistry,
): Readonly<TRegistry>;

See Registry System for the full explanation.

createFormBuilder(registry)

function createFormBuilder<TRegistry extends FieldRegistry>(
  registry: TRegistry,
): FormBuilder<TRegistry>;

interface FormBuilder<TRegistry extends FieldRegistry> {
  defineForm<TValues extends object>(
    fields: FormFieldsConfig<TRegistry, TValues>,
  ): FormDefinition<TRegistry, TValues>;
}

See Form Engine Overview for what defineForm checks, at compile time and at runtime.

resolveFieldComponent(registry, type)

function resolveFieldComponent<TRegistry extends FieldRegistry>(
  registry: TRegistry,
  type: string,
): TRegistry[keyof TRegistry];

Resolves a configured field type to its component at the point of use, never a static import. Throws PrismConfigurationError (naming the field's known types) if type isn't a registry key. This is what @prismrepo/adapter-rhf's PrismField calls internally to render a field.

FieldBinding<TValue>

interface FieldBinding<TValue> {
  readonly name: string;
  readonly value: TValue;
  readonly onChange: (value: TValue) => void;
  readonly onBlur: () => void;
  readonly error: string | undefined;
}

See Form Engine Overview.

FieldComponent<TValue, TExtraProps> / FieldComponentProps<TValue, TExtraProps>

type FieldComponentProps<TValue, TExtraProps extends object = object> = TExtraProps & {
  readonly field: FieldBinding<TValue>;
};

type FieldComponent<TValue = never, TExtraProps extends object = object> = ComponentType<
  FieldComponentProps<TValue, TExtraProps>
>;

The type of a Layer 2 field component: any React component accepting its own extra props plus the normalized field binding. See Custom Fields.

On this page