Layouts and chrome
Replace how fields, steps and screens look without touching behavior: theme components, the Stepper, Split and Focus layouts, and closed screens.
Built-in fields own behavior; their markup comes from replaceable
components. So does the form's arrangement — the Layout — and its chrome:
header, progress, buttons, success and closed screens. Replace any subset and
the rest keep the default look. Validation, focus, steps and schema discovery
keep working whatever you render.
import { Form, SplitLayout } from '@open-form-build/core';
<Form components={{ Layout: SplitLayout }}>…</Form>Replaceable components
| Component | Renders | Key props |
|---|---|---|
Field | Label, help and error around every field except Matrix, which Matrix and MatrixRow draw themselves | field, children, as, hideLabel, hideDescription |
TextInput | Text, Email, Url, Tel, NumberInput, DateInput | field, type, value, onChange(string), unit, placeholder, inputMode, autoComplete, maxLength, min / max / step |
Textarea | Textarea | field, value, onChange, rows, maxLength, placeholder, autoComplete |
Select | Select | field, options, value, onChange, placeholder |
PhoneInput | Tel with a country picker | field, country, countries, onCountryChange(country), value, onChange(string), countryLabel, placeholder, autoComplete. The default renders the active Select and TextInput side by side |
ChoiceGroup | RadioGroup, CheckboxGroup | field, options, multiple, selected, onToggle(value, checked), variant |
Checkbox | Checkbox | field, checked, onChange(boolean), children, markRequired |
Rating | Rating | field, scores, value, onChange(number), lowLabel, highLabel |
Matrix | The frame of a Matrix: question, column headings, rows | label, description, required, columns, children (the rows) |
MatrixRow | One row of a Matrix | field (the row's own), columns, value, onChange(string), markRequired |
Layout | The whole form | The regions below |
Header | Title and description | title, description |
Progress | Step indicator | nav, label ("Step 2 of 5", localized) |
Nav | Back / Next / Submit | nav, submitLabel, labels |
Button | Every button in Nav | variant: 'primary' | 'secondary' plus button props |
Success | Thank-you screen | title, children |
Notice | Closed screens | state, eyebrow, title, message |
LanguageSwitch | Language picker on translated forms | value, options, onChange, label |
Each has a matching props type exported from @open-form-build/core: FieldUIProps,
TextInputUIProps, LayoutUIProps, NoticeUIProps and so on.
A replacement control follows the
custom field rules for
field.controlProps and field.ref, and passes on the attributes it
receives — inputMode, autoComplete, maxLength, placeholder — so mobile
keyboards, autofill and limits keep working. Inside any replacement,
useFormComponents() returns the components in effect, so a custom Nav can
render the theme's Button. <RequiredMark /> is the built-in required
asterisk, for a custom Field or Checkbox.
Override order
defaultComponents ← the theme's components ← <Form components>. The
theme is the form's own look, passed as <Form theme>, so its components apply
to that form only; <Form components> wins over them for one-off changes.
import { defineTheme, StepperLayout } from '@open-form-build/core';
export default defineTheme({ components: { Layout: StepperLayout } });import theme from './theme/index.ts';
<Form theme={theme} components={{ ChoiceGroup: Chips }}>…</Form>To extend instead of rewrite, render the default inside your own markup:
import { defaultComponents, type TextInputUIProps } from '@open-form-build/core';
function FramedInput(props: TextInputUIProps) {
return (
<div className="brand-frame">
<defaultComponents.TextInput {...props} />
</div>
);
}Built-in layouts
| Layout | Use it for |
|---|---|
| (default) | A centered card. General purpose. |
StepperLayout | Three or more named steps — applications, onboarding. A step list beside the questions; visited steps are clickable. Give every <Page> a short title. With fewer than two visible steps, and on the success and closed screens, it shows the default card. |
SplitLayout | Brand-forward forms — sales, waitlists, events. A panel with the title, progress and aside; questions on the other side. Stacks on small screens. |
FocusLayout | Conversational surveys. One screen per step, large type, Enter to continue. Put one question in each <Page> and leave page titles off. Doesn't show aside. |
When the form has a title or description, FocusLayout opens with a
welcome screen built from them and a Start button, so write them as an
invitation.
It is built for the keyboard. Enter moves on from anywhere on the step, a
Textarea too, where Shift + Enter adds a line; everywhere else Shift + Enter
goes back a step, and the hint under the buttons says which. A step that opens
with a text field puts the cursor in it, so people can type straight away, and
Tab reaches Next before Back, as they sit on screen. On touch screens nothing
is focused for them, Return in a Textarea adds a line and Cmd/Ctrl + Enter
advances. Letter keys for choices or number keys for a rating belong in the
theme's ChoiceGroup and Rating.
To show the title above the first question instead of on its own screen:
<Form components={{ Layout: (props) => <FocusLayout {...props} cover={false} /> }}>…</Form>Layout regions
A Layout receives ready-made regions (LayoutUIProps) and arranges them:
Prop
Type
import type { LayoutUIProps } from '@open-form-build/core';
function Centered({ state, header, progress, content, alert, actions }: LayoutUIProps) {
return (
<div className="my-shell" data-state={state}>
{state === 'form' && header}
{progress}
{content}
{alert}
{actions}
</div>
);
}A custom Nav or Button must keep type="submit" on the primary button so
Enter still advances.
Screen headings — ScreenHeadingContext
A screen has one <h1>. The built-in Success and Notice take it, unless
the layout keeps the form's header, and its <h1>, on the thank-you and closed
screens, as SplitLayout does. ScreenHeadingContext holds the level those
screens should use: 'h1' by default, 'h2' under such a layout. A custom
Success or Notice reads it instead of hard-coding a tag, so it stays right
in any layout:
import { useContext } from 'react';
import { ScreenHeadingContext, type SuccessUIProps } from '@open-form-build/core';
function Thanks({ title, children }: SuccessUIProps) {
const Heading = useContext(ScreenHeadingContext);
return (
<div className="thanks">
<Heading className="of-title">{title}</Heading>
{children}
</div>
);
}A custom Layout that renders header on the success or unavailable
screen wraps content in <ScreenHeadingContext.Provider value="h2">:
import { type LayoutUIProps, ScreenHeadingContext } from '@open-form-build/core';
function Poster({ banner, header, intro, content, alert, actions }: LayoutUIProps) {
return (
<div className="poster">
{banner}
{header}
{intro}
<ScreenHeadingContext.Provider value="h2">{content}</ScreenHeadingContext.Provider>
{alert}
{actions}
</div>
);
}On a translated form, the language picker (.of-lang) sits 12px inside the
top-right corner of .of-root and is 32px tall. The built-in layouts start
below it. A custom Layout, or CSS that changes .of-root's padding, has to
keep that corner clear at every width, phones included. Reserve the room, or
move the picker into space your layout leaves free:
.of-root[data-of-theme="acme"]:has(> .of-lang) {
padding-top: clamp(56px, 6vw, 64px);
}Closed screens — Notice
Respondents see Notice instead of the questions when the form isn't taking
responses. It receives state, eyebrow (the form's title), title and
message, already translated.
state | When | message |
|---|---|---|
'closed' | closed: true, after closesAt, or closed in Studio | closedMessage, or a built-in sentence |
'not-open' | Before opensAt | A built-in sentence with the opening date |
'full' | maxResponses reached | fullMessage, or a built-in sentence |
'duplicate' | uniqueBy: 'device' and this browser already responded | duplicateMessage, or a built-in sentence |
'not-found' | A <FormHost> asked for a form the server doesn't have, or one that's unpublished; title is "Form not found" | A built-in sentence: the link may be mistyped, or the form is no longer available |
import { useContext } from 'react';
import { Form, type NoticeUIProps, ScreenHeadingContext, T } from '@open-form-build/core';
function MeetupClosed({ state, eyebrow, title, message }: NoticeUIProps) {
const Heading = useContext(ScreenHeadingContext);
return (
<div className="meetup-closed">
{eyebrow && Heading === 'h1' && <p className="of-eyebrow">{eyebrow}</p>}
<Heading className="of-title">{state === 'full' ? <T>All 100 seats are taken</T> : title}</Heading>
<p className="of-description">{message}</p>
</div>
);
}
<Form components={{ Notice: MeetupClosed }}>…</Form>Branch on state for what differs and fall back to title and message, so
a state you didn't plan for still reads right. Keep policy messages in
config.submissions, where Studio and the server use them too. Render one
<h1>: take the title's level from
ScreenHeadingContext, and skip
eyebrow when it is 'h2', since the header already names the form. Studio's
Preview shows every closed screen the form can reach.
Custom fields
Turn any React UI into a form field with useField and FieldShell: value, validation, errors, focus, ARIA and storage, just like the built-ins.
Live answers and navigation
Hooks for live previews, answer summaries, custom navigation and translated copy: useFormValues, useFieldValue, useFormNav and more.