Installation and quick start

@schema-engine/forms-radiant renders a form config with Radiant, the Ecopages custom-element library, and ships its elements in the package: there is no copy step. This page installs it, sets up JSX and the styles, and renders a form that submits.

1. Install

pnpm add @schema-engine/forms @schema-engine/forms-radiant @schema-engine/layout @ecopages/radiant-ui @ecopages/radiant @ecopages/jsx @ecopages/signals zod

The peers need @ecopages/radiant, @ecopages/jsx and @ecopages/signals 0.12.0 or later and @ecopages/radiant-ui 0.6.1 or later. See Packages for every peer range.

2. Set up JSX

Radiant renders with its own JSX runtime. Set it in tsconfig.json:

{
	"compilerOptions": {
		"jsx": "react-jsx",
		"jsxImportSource": "@ecopages/jsx"
	}
}

3. Load the styles

Load one Radiant UI theme, its aggregate stylesheet and the renderer's stylesheet once, in your global stylesheet:

@import '@ecopages/radiant-ui/themes/default';
@import '@ecopages/radiant-ui/styles.css';
@import '@schema-engine/forms-radiant/index.css';

Published JavaScript does not execute CSS, so the renderer's own styles (host display rules, the card, hero and split-screen shells, the fieldset, array and drop-zone CSS) come from index.css. An app with Tailwind imports tailwindcss first. An app without it imports @ecopages/radiant-ui/radiant-ui-core.css first, so headings, lists and controls are not left on user-agent margins. A bundler that loads CSS from JavaScript takes the same three lines as side-effect imports (import '@ecopages/radiant-ui/styles.css';).

Import one theme, never two. Dark mode is a dark class on an ancestor, usually <html class="dark">; Radiant UI does not follow prefers-color-scheme by itself, so set the class from the visitor's preference. Colour, spacing and radius come from Radiant UI's semantic roles (--primary, --space-*, --radius-control for controls, --radius-container for cards and groups), which a host retunes with Theming.

4. Render a form

One file holds the engine, the form config and a component that renders it. createRadiantFormEngine registers the elements of the package and binds the canonical view recipes:

import type { FormConfig, FormValues } from '@schema-engine/forms';
import { createRadiantFormEngine, FormRenderer, schemaFormRegistrations } from '@schema-engine/forms-radiant';

export const engine = createRadiantFormEngine({ elements: schemaFormRegistrations });

export const contactConfig: FormConfig = {
	id: 'contact',
	steps: [
		{
			id: 'details',
			title: 'Your details',
			elements: [
				{
					$type: 'input',
					id: 'name',
					name: 'name',
					label: 'Name',
					rules: [{ $type: 'required', message: 'Enter your name' }],
				},
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email',
					rules: [
						{ $type: 'required', message: 'Enter your email' },
						{ $type: 'email', message: 'Enter a valid email address' },
					],
				},
				{ $type: 'submit', id: 'send', name: 'send', label: 'Send' },
			],
		},
	],
};

export function ContactForm({ onSubmit }: { onSubmit: (values: FormValues) => void }) {
	return <FormRenderer engine={engine} config={contactConfig} onSubmit={onSubmit} />;
}

FormRenderer validates the config, renders it and calls onSubmit with the values that passed validation. The values are FormValues for a plain config or one loaded from JSON. With engine.defineForm() of a literal config, onSubmit, onAction and defaultValues take their types from the config, and with engine.validateForm(json, { values }) from the output of your schema. See Authoring modes and Submitted values.

Override a registration

A later registration with the same $type replaces an earlier one, so a replacement goes after the barrel. FormField is the field host that connects the control to the form's state, so a replacement renders inside one (see Form controls):

import * as z from 'zod/mini';
import { RuiFieldError } from '@ecopages/radiant-ui/field';
import { RuiInput } from '@ecopages/radiant-ui/input';
import { RuiLabel } from '@ecopages/radiant-ui/label';
import { defineInput } from '@schema-engine/forms';
import { createRadiantFormEngine, schemaFormRegistrations } from '@schema-engine/forms-radiant';
import { InputElementRegistration } from '@schema-engine/forms-radiant/registrations';
import { FormField } from '@schema-engine/forms-radiant/primitives';

const myInput = defineInput({
	$type: 'input',
	schema: InputElementRegistration.schema,
	value: () => z.string(),
	metadata: InputElementRegistration.metadata,
	render: (config) => (
		<FormField name={config.name}>
			<RuiLabel>{config.label}</RuiLabel>
			<RuiInput name={config.name} placeholder={config.placeholder} />
			<RuiFieldError />
		</FormField>
	),
});

export const engine = createRadiantFormEngine({ elements: [...schemaFormRegistrations, myInput] });

Submit and state

onSubmit(values, { setServerErrors, fetch }) receives the values that passed validation. Send them with that fetch, which applies the engine's CSRF policy, and show a rejection on the fields it names with setServerErrors. A form with action or method and no onSubmit posts natively after validation passes. The typed FormRenderer prop is the one way to receive the values: se-form-instance has no property to assign for it, and its class is not exported.

The form's state is the engine's container, which rui-form bridges to the controls: see Form controls for the native events, reading the form from your own element and writing a custom control.

Where to go next