Getting Started
1. Install peers
pnpm add @schema-engine/forms-radiant @schema-engine/forms @schema-engine/layout @ecopages/radiant-ui @ecopages/radiant @ecopages/jsx @ecopages/signals zodThe peers need @ecopages/radiant, @ecopages/jsx and @ecopages/signals 0.12.0 or later and @ecopages/radiant-ui 0.6.0 or later.
Load one Radiant UI theme, its aggregate stylesheet and this adapter'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 adapter'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), which a host retunes with Theming.
2. Create a form engine
Default field registrations ship in the package:
import { createRadiantFormEngine, schemaFormRegistrations } from '@schema-engine/forms-radiant';
const formEngine = createRadiantFormEngine({ elements: schemaFormRegistrations });3. Configure your form
Use the same FormConfig JSON as the React adapter:
For TypeScript authored next to your engine, prefer
engine.defineForm().
See Authoring modes.
import type { FormConfig } from '@schema-engine/forms/schemas';
const formConfig: FormConfig = {
id: 'contact-form',
steps: [
{
id: 'step-1',
elements: [
{
$type: 'input',
id: 'name',
name: 'name',
label: 'Full Name',
rules: [{ type: 'required', message: 'Name is required' }],
},
{
$type: 'input',
id: 'email',
name: 'email',
label: 'Email',
inputType: 'email',
rules: [
{ type: 'required', message: 'Email is required' },
{ type: 'email', message: 'Invalid email' },
],
},
{ $type: 'submit', id: 'submit', name: 'submit', label: 'Send' },
],
},
],
};4. Render the form
import { FormRenderer } from '@schema-engine/forms-radiant';
<FormRenderer
engine={formEngine}
config={formConfig}
onSubmit={(data) => console.log(data)}
/>;Override a registration
import { InputElementRegistration } from '@schema-engine/forms-radiant/registrations';
const engine = createRadiantFormEngine({
elements: [...schemaFormRegistrations, { ...InputElementRegistration, render: MyCustomInput }],
});Server-rendered forms and engine binding
Radiant UI views rendered on the server do not register their elements in the browser, so
the module that builds your engine must reach the client: it imports @schema-engine/forms-radiant,
which registers the form hosts and the Radiant UI components they use. The engine is not
serialized into server-rendered markup, so the app assigns it
to each se-form-renderer. Assign it before or after the renderer upgrades: the
hosts below it read the engine from the renderer's context and follow it when it
arrives or changes.
engine is a property only; there is no HTML attribute. Bind every renderer on the page:
import type { FormRendererElement } from '@schema-engine/forms-radiant';
import { formEngine } from './form-engine';
function bindEngine(root: ParentNode): void {
for (const renderer of root.querySelectorAll<FormRendererElement>('se-form-renderer')) {
renderer.engine = formEngine;
}
}
bindEngine(document);A client-side router that swaps in a parsed page does not upgrade it first. Assign
the engine to the incoming renderers in the router's eco:before-swap event
(event.detail.newDocument), as the docs site does in
apps/docs/src/lib/preview-engine-binding.ts; they upgrade with the engine
already set:
document.addEventListener('eco:before-swap', (event) => {
bindEngine((event as CustomEvent<{ newDocument: Document }>).detail.newDocument);
});A form that is only rendered on the client passes engine to
FormRenderer and needs none of this.
Layout stylesheet per form
Radiant has no head hoisting, so each form carries an identical, self-contained copy of its layout
theme's stylesheet (<style data-se-theme-css="<id>">, about 11 kB raw for the default theme). Every form is
therefore styled before hydration, whatever the render order, streaming, caching or removal of the other forms, and
compression makes the repeated copies cheap on the wire. React hoists the equal stylesheets of its forms to one
element instead; the stylesheet content is the same.
On a page with very many Radiant forms, WebKit spends more time styling, because every form brings its own copy. In a one-off headless run with one small form per copy, WebKit needed about 37 ms for 25 forms and 390 ms for 100, against 3 and 11 ms with one copy, while Chromium and Firefox stayed under 17 ms for 100. For the usual page with one form, or a few, the cost is negligible.
A host that also wants the rules in its own head can serve the theme's css; the forms keep their copies, which hold
the same rules:
const { id, css } = formEngine.getLayout();
const head = `<style data-se-theme-css="${id}">${css}</style>`;Style it
Styling and layout says which tool fits which job, and Recipes has copy-paste configs and CSS, each rendered live with this adapter.
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 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.
Storybook
From the monorepo root:
pnpm dev:radiant-storybookRuns on port 6007 by default.