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:
- Copy the config tab into a module and render it.
- 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. - 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/layoutfor a theme tab, which importscreateLayoutThemeanddefineAxisfrom 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.
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
}
]
}
]
};/* The card's width is the readable measure, --se-measure. Set it on the form's own class. */
.contact-card {
--se-measure: 36rem;
}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: 4An 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.
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'
}
}
]
}
]
}
]
};/* Gap tokens are public custom properties: set them on the form (or on :root for every form). */
.address-form {
--se-grid-gap-compact: 0.5rem;
--se-grid-gap-default: 1rem;
}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.
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'
}
}
]
}
]
};.checkout-wizard {
--se-measure: 40rem;
--se-grid-gap-default: 0.75rem;
}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'
}
}
]
}
]
};/* Areas and widths come from the config; the only CSS is the rhythm between the cells. */
.drawn-layout {
--se-grid-gap-default: 0.75rem;
}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.
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'
}
]
}
]
};import { builtInAxes, createLayoutTheme, defineAxis } from '@schema-engine/layout';
/**
* A host axis. Each value is a set of tokens: the colour roles Radiant UI (`--primary`, `--on-primary`) and a
* shadcn theme (`--primary`, `--primary-foreground`) read.
*/
export const tone = defineAxis({
$type: 'tone',
metadata: { name: 'Tone', description: 'Accent colour of a form' },
default: 'neutral',
values: {
neutral: {},
brand: {
'--primary': '#c2410c',
'--on-primary': '#ffffff',
'--primary-foreground': '#ffffff',
'--primary-container': '#ffedd5',
'--on-primary-container': '#7c2d12',
},
forest: {
'--primary': '#15803d',
'--on-primary': '#ffffff',
'--primary-foreground': '#ffffff',
'--primary-container': '#dcfce7',
'--on-primary-container': '#14532d',
},
},
});
/** The compiled theme: the built-in `size` and `surface` axes plus `tone`. Pass it to every engine as `layout`. */
export const brandTheme = createLayoutTheme({ appearance: [...builtInAxes, tone] });/*
* The tone axis sets colour roles (--primary and friends); this rule only reads one.
* [data-se-tone] is written by the renderer on the form element, so it can style the form itself.
*/
.brand-form {
padding-inline-start: 1rem;
border-inline-start: 0.25rem solid var(--primary);
}
.brand-form[data-se-tone='forest'] {
border-inline-start-style: dashed;
}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 digestTwo 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.
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.
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'
}
]
}
]
};/* The compact hooks: set them on the form's own class, or on :root or an ancestor. The pick on the card shell, a step or a field inherits them. */
.tight-form {
--se-space-compact: 0.5rem;
--se-control-height-compact: 1.5rem;
}
/* --se-measure is a literal value of the pick: win on the element that carries it. */
.tight-form [data-se-size='compact'] {
--se-measure: 28rem;
}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: emailA 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] });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'
}
]
}
]
};/** @jsxImportSource react */
import * as z from 'zod/mini';
import { defineRecipeSpec, getSlotConfig } from '@schema-engine/forms/recipes';
import { defineRecipe, type FormShellProps } from '@schema-engine/forms-react/primitives';
const BrandFrameShellSchema = z.strictObject({
label: z._default(z.string(), 'Schema Engine'),
});
function BrandFrameShell({ slots, viewConfig }: FormShellProps) {
const { label } = getSlotConfig(viewConfig, 'shell', BrandFrameShellSchema);
return (
<section className="brand-frame">
<p className="brand-frame__label">{label}</p>
<div className="brand-frame__body">{slots.content}</div>
</section>
);
}
export const BrandFrameRecipe = defineRecipe(
defineRecipeSpec({
$type: 'brand-frame',
kind: 'single-step',
slotSchemas: { shell: BrandFrameShellSchema },
metadata: { name: 'Brand frame', description: 'A labelled frame around the fields' },
}),
{ shell: BrandFrameShell, slots: {} },
);import * as z from 'zod/mini';
import { getSlotConfig } from '@schema-engine/forms/recipes';
import { defineRecipe, defineRecipeSpec, type FormShellProps } from '@schema-engine/forms-radiant';
const BrandFrameShellSchema = z.strictObject({
label: z._default(z.string(), 'Schema Engine'),
});
function BrandFrameShell({ slots, viewConfig }: FormShellProps) {
const { label } = getSlotConfig(viewConfig, 'shell', BrandFrameShellSchema);
return (
<section class="brand-frame">
<p class="brand-frame__label">{label}</p>
<div class="brand-frame__body">{slots.content}</div>
</section>
);
}
export const BrandFrameRecipe = defineRecipe(
defineRecipeSpec({
$type: 'brand-frame',
kind: 'single-step',
slotSchemas: { shell: BrandFrameShellSchema },
metadata: { name: 'Brand frame', description: 'A labelled frame around the fields' },
}),
{ shell: BrandFrameShell, slots: {} },
);.brand-frame {
overflow: hidden;
border: 2px solid var(--primary, currentColor);
border-radius: 0.75rem;
}
.brand-frame__label {
margin: 0;
padding: 0.5rem 1rem;
background: var(--primary, currentColor);
color: var(--on-primary, #fff);
font-size: 0.875rem;
font-weight: 600;
}
.brand-frame__body {
padding: 1rem;
}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: SubscribeThe 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 });
}