Recipes

Each recipe is a complete form config, the CSS it needs, and a live demo. The demo renders the same object the config tab shows, and each file tab is the text of the file the demo runs, so a snippet cannot drift from its demo. Every tab has a copy button.

Use a recipe

Set up your app as the getting-started page for your renderer says (Forms Radiant or Forms React), then:

  1. Copy the config tab into a module and render it.
  2. Copy the CSS tab into your global stylesheet, or import it as a file. Every recipe CSS is scoped by the class its config puts on the form with className, so it only applies once pasted with that config.
  3. If the recipe has a theme or engine tab, build your engine with it, as that tab shows. A React app also needs pnpm add @schema-engine/layout for a theme tab, which imports createLayoutTheme and defineAxis from it (Radiant installs it as a peer).

In Radiant:

import { FormRenderer, createRadiantFormEngine, schemaFormRegistrations } from '@schema-engine/forms-radiant';
import { contactCard } from './contact-card';

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

export function Contact() {
	return <FormRenderer engine={engine} config={contactCard} onSubmit={(data) => console.log(data)} />;
}

In React, create the engine with the registrations and recipes you copied from the shadcn registry, as Forms React shows, and render FormRenderer with the same config. The recipes that use fieldSet need the fieldset registration in your engine.

The React demos use the docs' Radiant-styled demo kit, not the shadcn registry components, so fallbacks such as the card's maximum width and shadow differ from a registry install. The demos on this page run on one docs engine per renderer, built on the theme of the brand theme recipe. A recipe that does not name a theme runs on the default one and renders the same without it.

A contact card with two half-width fields

A single-step form on the card recipe. grid.width: half puts the two names on one row; the email and message fill the row because they set no width. The CSS sets the card's width, the readable measure --se-measure, on the form's own class.

React

Your details

We reply within one working day.

Radiant

Your details

We reply within one working day.

import type { FormConfig } from '@schema-engine/forms/schemas';

const contactCard: FormConfig = {
	id: 'contact-card',
	title: 'Contact us',
	description: 'We reply within one working day.',
	className: 'contact-card',
	view: {
		$type: 'card'
	},
	steps: [
		{
			id: 'details',
			title: 'Your details',
			elements: [
				{
					$type: 'input',
					id: 'first',
					name: 'first',
					label: 'First name',
					grid: {
						width: 'half'
					},
					rules: [
						{
							type: 'required',
							message: 'First name is required'
						}
					]
				},
				{
					$type: 'input',
					id: 'last',
					name: 'last',
					label: 'Last name',
					grid: {
						width: 'half'
					},
					rules: [
						{
							type: 'required',
							message: 'Last name is required'
						}
					]
				},
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email',
					rules: [
						{
							type: 'required',
							message: 'Email is required'
						},
						{
							type: 'email',
							message: 'Enter a valid email'
						}
					]
				},
				{
					$type: 'textarea',
					id: 'message',
					name: 'message',
					label: 'Message',
					rows: 4
				}
			]
		}
	]
};

An address fieldset with an inner grid

A fieldset lays its children out on a grid of its own, so width works on the children of a container exactly as it does on a step's fields. The step has no columns, and it does not need one. The CSS tightens the rhythm with the public gap tokens.

Delivery address

Address
import type { FormConfig } from '@schema-engine/forms/schemas';

const addressForm: FormConfig = {
	id: 'address-form',
	title: 'Delivery',
	className: 'address-form',
	view: {
		$type: 'card'
	},
	steps: [
		{
			id: 'delivery',
			title: 'Delivery address',
			elements: [
				{
					$type: 'fieldSet',
					id: 'address',
					name: 'address',
					legend: 'Address',
					elements: [
						{
							$type: 'input',
							id: 'street',
							name: 'street',
							label: 'Street'
						},
						{
							$type: 'input',
							id: 'city',
							name: 'city',
							label: 'City',
							grid: {
								width: 'two-thirds'
							}
						},
						{
							$type: 'input',
							id: 'zip',
							name: 'zip',
							label: 'ZIP code',
							grid: {
								width: 'third'
							}
						},
						{
							$type: 'input',
							id: 'region',
							name: 'region',
							label: 'Region',
							grid: {
								width: 'half'
							}
						},
						{
							$type: 'input',
							id: 'country',
							name: 'country',
							label: 'Country',
							grid: {
								width: 'half'
							}
						}
					]
				}
			]
		}
	]
};

A multi-step card wizard with per-step areas

A step's grid replaces the form's grid for that step, so each step of a wizard draws its own layout and claims every area in it. The names are ASCII CSS identifiers, and each field claims one with grid.area.

Step 1 of 2

Address

Progress
import type { FormConfig } from '@schema-engine/forms/schemas';

const checkoutWizard: FormConfig = {
	id: 'checkout-wizard',
	title: 'Checkout',
	className: 'checkout-wizard',
	view: {
		$type: 'card-wizard'
	},
	steps: [
		{
			id: 'address',
			title: 'Address',
			grid: {
				areas: [
					'street street',
					'city zip'
				]
			},
			elements: [
				{
					$type: 'input',
					id: 'street',
					name: 'street',
					label: 'Street',
					grid: {
						area: 'street'
					}
				},
				{
					$type: 'input',
					id: 'city',
					name: 'city',
					label: 'City',
					grid: {
						area: 'city'
					}
				},
				{
					$type: 'input',
					id: 'zip',
					name: 'zip',
					label: 'ZIP code',
					grid: {
						area: 'zip'
					}
				}
			]
		},
		{
			id: 'payment',
			title: 'Payment',
			grid: {
				areas: [
					'card card',
					'expiry cvc'
				]
			},
			elements: [
				{
					$type: 'input',
					id: 'card',
					name: 'card',
					label: 'Card number',
					grid: {
						area: 'card'
					}
				},
				{
					$type: 'input',
					id: 'expiry',
					name: 'expiry',
					label: 'Expiry',
					grid: {
						area: 'expiry'
					}
				},
				{
					$type: 'input',
					id: 'cvc',
					name: 'cvc',
					label: 'CVC',
					grid: {
						area: 'cvc'
					}
				}
			]
		}
	]
};

A responsive drawn layout

Five fields, stacked on small screens and drawn from md up: A spans three columns and two rows, B and C stack beside it, and D and E share the last row. areas is a record keyed by breakpoint, and it must include default. Resize the window to see the layout change.

import type { FormConfig } from '@schema-engine/forms/schemas';

const drawnLayout: FormConfig = {
	id: 'drawn-layout',
	className: 'drawn-layout',
	grid: {
		areas: {
			default: [
				'a',
				'b',
				'c',
				'd',
				'e'
			],
			md: [
				'a a a b b b',
				'a a a c c c',
				'd d e e e e'
			]
		}
	},
	steps: [
		{
			id: 'fields',
			title: 'Fields',
			elements: [
				{
					$type: 'input',
					id: 'a',
					name: 'a',
					label: 'A',
					grid: {
						area: 'a'
					}
				},
				{
					$type: 'input',
					id: 'b',
					name: 'b',
					label: 'B',
					grid: {
						area: 'b'
					}
				},
				{
					$type: 'input',
					id: 'c',
					name: 'c',
					label: 'C',
					grid: {
						area: 'c'
					}
				},
				{
					$type: 'input',
					id: 'd',
					name: 'd',
					label: 'D',
					grid: {
						area: 'd'
					}
				},
				{
					$type: 'input',
					id: 'e',
					name: 'e',
					label: 'E',
					grid: {
						area: 'e'
					}
				}
			]
		}
	]
};

The rules for areas, and every validation error, are in Drawn layouts.

A brand theme with a host tone axis

The built-in axes are size and surface. A host adds its own with defineAxis: here tone, whose values set the colour roles Radiant UI (--primary, --on-primary) and shadcn (--primary, --primary-foreground) components read. The theme tab builds it; every engine receives it as layout. The form picks tone: 'brand' once, on the form, and the submit button, the checkbox and the border recolor. Try forest after you paste it; the tab is static.

The CSS reads --primary and keys one rule on the data-se-tone attribute the renderer writes on the form element.

Stay in touch

import type { FormConfig } from '@schema-engine/forms/schemas';

const brandForm: FormConfig = {
	id: 'brand-form',
	title: 'Newsletter',
	className: 'brand-form',
	appearance: {
		tone: 'brand'
	},
	view: {
		$type: 'card'
	},
	steps: [
		{
			id: 'signup',
			title: 'Stay in touch',
			elements: [
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email',
					rules: [
						{
							type: 'email',
							message: 'Enter a valid email'
						}
					]
				},
				{
					$type: 'checkbox',
					id: 'weekly',
					name: 'weekly',
					label: 'Weekly digest'
				}
			]
		}
	]
};

Two engines sharing one theme

Compile a theme once and pass the same object to every engine. Both engines then carry one data-se-theme and the same stylesheet content, so a checkout form and a profile form match whatever engine built them. The docs engines use the same pattern across renderers: Radiant and React engines are both built on brandTheme.

checkoutEngine

Contact

profileEngine

Name

import type { FormConfig } from '@schema-engine/forms/schemas';

const checkoutForm: FormConfig = {
	id: 'checkout-theme',
	title: 'Checkout',
	appearance: {
		tone: 'brand'
	},
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'compact'
			}
		}
	},
	steps: [
		{
			id: 'contact',
			title: 'Contact',
			elements: [
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email'
				}
			]
		}
	]
};

const profileForm: FormConfig = {
	id: 'profile-theme',
	title: 'Profile',
	appearance: {
		tone: 'forest'
	},
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'compact'
			}
		}
	},
	steps: [
		{
			id: 'name',
			title: 'Name',
			elements: [
				{
					$type: 'input',
					id: 'display',
					name: 'display',
					label: 'Display name'
				}
			]
		}
	]
};

Each form picks its own tone. React hoists the shared stylesheet to one element; Radiant puts an identical copy in each form, by design (see Layout themes).

Overriding size tokens

size: compact reads two hooks, --se-space-compact and --se-control-height-compact, so tighten them on the form's class, or on :root or a wrapper for every form below it: the pick on the card shell, a step or a field inherits them. --se-measure has a literal value on the element that carries the pick, so override it with a rule that targets that element and has the specificity of a class. The form picks compact on the card shell.

React

Details

Radiant

Details

import type { FormConfig } from '@schema-engine/forms/schemas';

const tightForm: FormConfig = {
	id: 'tight-size',
	title: 'Compact form',
	className: 'tight-form',
	view: {
		$type: 'card',
		shell: {
			appearance: {
				size: 'compact'
			}
		}
	},
	steps: [
		{
			id: 'details',
			title: 'Details',
			elements: [
				{
					$type: 'input',
					id: 'name',
					name: 'name',
					label: 'Name'
				},
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email'
				}
			]
		}
	]
};

A custom recipe shell in React and in Radiant

A recipe is a registration: a spec ($type, kind, slot schemas) bound to the components of one renderer. This one is a single-step shell that frames the fields under a label read from view.shell.label. The same config renders in both renderers; only the binding differs, and the CSS is shared.

Register it when you build the engine, then select it with view.$type:

In React:

import { createFormEngine } from '@schema-engine/forms';
import { elements } from './registrations';
import { BrandFrameRecipe } from './brand-frame.react';

export const engine = createFormEngine({ elements, recipes: [BrandFrameRecipe] });

In Radiant:

import { createRadiantFormEngine, schemaFormRegistrations } from '@schema-engine/forms-radiant';
import { BrandFrameRecipe } from './brand-frame.radiant';

export const engine = createRadiantFormEngine({ elements: schemaFormRegistrations, recipes: [BrandFrameRecipe] });
React

Newsletter

Radiant

Newsletter

import type { FormConfig } from '@schema-engine/forms/schemas';

const brandFrameForm: FormConfig = {
	id: 'brand-frame',
	view: {
		$type: 'brand-frame',
		shell: {
			label: 'Newsletter'
		}
	},
	steps: [
		{
			id: 'signup',
			title: 'Sign up',
			elements: [
				{
					$type: 'input',
					id: 'email',
					name: 'email',
					label: 'Email',
					inputType: 'email'
				},
				{
					$type: 'submit',
					id: 'submit',
					name: 'submit',
					label: 'Subscribe'
				}
			]
		}
	]
};

The shell receives slots (header, progress, content, actions, each present only when the recipe declares it) and viewConfig, and reads its own slot config with getSlotConfig and the schema it declared. A recipe that needs size or surface on a slot declares them with appearanceAxes: { shell: ['size', 'surface'] }. See View recipes.

Authoring in YAML

Every recipe's config is plain data. Each demo has a .form.yaml tab, written from the same object, so the YAML cannot drift either. Load a file with parseYaml and your engine's safeValidateForm, as YAML Forms shows, which also covers editor autocomplete from engine.generateFormConfigSchema() and the caveats of unquoted values such as 1.10.

import { parseYaml } from '@schema-engine/registry/yaml';
import { engine } from './engine';

export function loadForm(text: string, filename: string) {
	return parseYaml(text, (value) => engine.safeValidateForm(value), { filename });
}