Appearance axes

An appearance axis is one independent dimension of how something looks, with a small closed set of named values. Each value stands for a set of semantic CSS tokens. Components read the tokens and never read an axis value.

import { engine } from './engine';

export const config = engine.defineForm({
	id: 'settings',
	appearance: { size: 'compact' },
	view: { $type: 'card', shell: { appearance: { surface: 'outlined' } } },
	steps: [
		{
			id: 'general',
			title: 'General',
			elements: [{ $type: 'input', id: 'name', name: 'name', label: 'Name' }],
		},
	],
});

How an axis works

The roles are separate:

  • The layout theme declares the vocabulary: each axis, its values and the tokens of each value.
  • A registration (an element, or a slot of a recipe) declares which axes it responds to. A pick on any other axis fails validation.
  • The document picks values. A pick passes down from the form to a step, a container and a field, or from the form to a recipe slot, and a closer pick wins.

The pipeline is the same in every renderer:

  1. A document picks a value: appearance: { size: 'compact' }.
  2. validateForm checks the pick against the vocabulary and the owner's declaration, then writes the resolved pick into the normalized config.
  3. The renderer writes data-se-size="compact" on the element.
  4. The theme's stylesheet has a rule for that attribute that sets tokens: --se-space, --se-font-size, --se-measure, --se-control-height.
  5. Component CSS reads var(--se-space, 1.5rem) and keeps the look of an unstyled form as its fallback.

Every token rule sits inside :where(), so it adds no specificity and a class of yours on the same element wins. (The grid and item rules are not zero-specificity; see Layout themes.)

What makes a good axis

RuleWhyA good axisNot an axis, and where it goes
Orthogonal to every other axisA pick on one axis never forces a pick on anothersize and surface combine freelydense-outlined: two axes in one
Means the same on every componentA token names a role, never a component--se-space pads a card, a fieldset and an array rowcardWidth: only one component reads it. Use slot config, or a token only that CSS reads
A small closed set of named values, 2 to 5A raw value is a token override, not a pickcompact, default, comfortablecolor: '#f60': set a token in CSS. A variant with eleven values: split it or drop it
Appearance onlyStructure belongs to slot config and the gridsurface: border, shadow, backgroundlayout: inline, orientation: horizontal: slot config. Which fields share a row: the grid

defineAxis enforces the part it can: 2 to 5 values, and tokens that are custom properties. The rest is design judgement. If an idea fits only one component, it is slot config. If every entity of your domain has its own value (a colour per machine, per brand), it is not an axis either: see Identity tokens.

Built-in axes

The engine ships size and surface. They are in builtInAxes, the default list of every layout theme.

size (compact, default, comfortable) sets how much room components take:

Value--se-space--se-font-size--se-measure--se-control-height
compactvar(--se-space-compact, var(--se-renderer-space-compact, 1rem))0.875rem24remvar(--se-control-height-compact, var(--se-renderer-control-height-compact, 1.75rem))
defaultinitialinitialinitialinitial
comfortablevar(--se-space-comfortable, var(--se-renderer-space-comfortable, 2rem))1.0625rem32remvar(--se-control-height-comfortable, var(--se-renderer-control-height-comfortable, 2.25rem))

surface (flat, outlined, elevated, default elevated) sets how a container sets itself apart:

Value--se-border-width--se-shadow--se-surface-background
flat0noneinitial
outlined1pxnoneinitial
elevatedinitialinitialinitial

A token set to initial hands the token back to the component's own fallback. So size: default and surface: elevated look like no pick, in a themed app and also inside a compact form. A value that declares no tokens inherits the surrounding value's tokens through custom-property inheritance.

--se-measure is the readable width of a block: the card is that wide, so a compact card is 24rem and a comfortable one 32rem. The card shells of both renderers read all the tokens above, and the hero, split screen, sidebar and stack shells read --se-space for their padding and gaps (the first three declare size on their shell slot); --se-control-height also sizes single-line controls (Radiant maps it onto its --size-control-md, and the React registry controls that carry data-se-control read it through controls.css, see View recipes). The DOM contract is the same in every renderer, and so is the field layout below; what a value does to a component's own look is the renderer's styling.

The shared field layout is three things: a field that carries a size pick reads --se-font-size, a text input fills its field, and the action bar of a single-step recipe places its button by actions.align. In React the first is a :where() rule in controls.css (falling back with revert-layer so a Tailwind text class on the field wins until a size is picked), the second is the w-full of the shadcn Input your project copies, and the third is form-actions.css (in recipes.css); in Radiant they are appearance.css, the input's own CSS and the block styles. Everything else (a control's padding and border, its type scale, a field's spacing) is the renderer's own styling. A Tailwind text-sm on a registry label keeps its own size, because an inherited font size never beats a class on the element.

The compact and comfortable values of --se-space and --se-control-height read hooks (--se-space-compact and the others). An author sets the hooks, on :root or any ancestor, to retune a value without redefining the axis; see Theming. Each hook falls back to a --se-renderer-* twin (--se-renderer-space-compact and the others), set by renderers, not by apps, and then to the neutral value.

Pick a value

appearance is a map from axis name to value. It is accepted on the form, on each step, on a field or container, and inside a recipe slot's config:

import { engine } from './engine';

export const config = engine.defineForm({
	id: 'profile',
	appearance: { size: 'comfortable' }, // the form
	view: { $type: 'card-wizard', shell: { appearance: { surface: 'outlined' } } }, // a recipe slot
	steps: [
		{
			id: 'account',
			title: 'Account',
			appearance: { size: 'compact' }, // a step
			elements: [
				{ $type: 'input', id: 'email', name: 'email', label: 'Email' },
				{
					$type: 'input',
					id: 'code',
					name: 'code',
					label: 'Code',
					appearance: { size: 'comfortable' }, // one field
				},
			],
		},
		{
			id: 'review',
			title: 'Review',
			elements: [{ $type: 'input', id: 'note', name: 'note', label: 'Note' }],
		},
	],
});

A value flows down, a closer pick winning per axis: the form's picks, then the step's, then each containing element's, then the field's own. A view slot takes the form's picks, then its own. Each owner keeps only the axes it declares, and an element with no resolved pick carries no appearance key.

The renderer writes the resolved pick as data-se-<axis>="<value>" on the form element (the one carrying className and style), the step element, the field host and the recipe slot elements. In the example, the email field is compact and code is comfortable.

An invalid pick fails validateForm, naming the axis and the owner:

MistakeMessagepath ends with
An axis the theme does not haveUnknown axis 'sise'. Declared axes: size, surface.['appearance', 'sise']
An axis the owner did not declare<owner> does not support the axis 'surface'. Supported axes: size.['appearance', 'surface']
A value the axis does not have'huge' is not a value of 'size'. Allowed: compact, default, comfortable.['appearance', 'size']

Declare the axes a registration supports

An element declares the axes it responds to with appearanceAxes, and a recipe declares them per slot:

import * as z from 'zod/mini';
import { defineStatic, BaseFieldSchema } from '@schema-engine/forms';

export const notice = defineStatic({
	$type: 'notice',
	appearanceAxes: ['tone'],
	schema: z.extend(BaseFieldSchema, { $type: z.literal('notice'), text: z.string() }),
	metadata: { name: 'Notice', category: 'content' },
	render: () => null,
});

For a recipe, defineRecipeSpec({ ..., appearanceAxes: { shell: ['size', 'surface'] } }) lists the axes of each slot; a slot that declares axes must accept an appearance key in its schema, so authored configs type-check. The engine does not pass appearance to the schema when it parses the view; it writes the resolved pick back. An element schema never sees the key either: the engine strips it before parsing and writes it back, so a strict custom element schema still supports axes.

The engine build throws when a registration declares an axis the theme lacks, naming the registration: Element 'notice' declares unknown appearance axis 'tone'. Declared axes: size, surface. Add it with createFormEngine({ layout: { appearance: [...builtInAxes, defineAxis({ $type: 'tone', ... })] } }). The form and each step accept every axis of the theme.

Add a host axis

defineAxis builds an axis. The built-ins are two of them; tone and emphasis are the usual host additions.

import { builtInAxes, createLayoutTheme, defineAxis } from '@schema-engine/layout';

const tone = defineAxis({
	$type: 'tone',
	metadata: { name: 'Tone', description: 'Accent colour of a form' },
	default: 'neutral',
	values: {
		neutral: {},
		brand: { '--primary': '#c2410c', '--on-primary': '#ffffff' },
		forest: { '--primary': '#15803d', '--on-primary': '#ffffff' },
	},
});

export const theme = createLayoutTheme({ appearance: [...builtInAxes, tone] });

Save it as theme.ts.

FieldMeaning
$typeThe axis name and the data-se-<axis> attribute. Lowercase letters, digits and hyphens, starting with a letter.
valuesEach value name, mapped to its tokens. Token names start with --. A value may set none (neutral: {}).
defaultThe value that stands for no pick. It must be one of values.
metadataThe name and description an editor or a catalog shows.

defineAxis also builds the axis's Standard Schema (an enum of the value names), because the registry requires one. It throws on a bad name, fewer than 2 or more than 5 values, a value name that would break a selector, a token that is not a custom property or whose value contains {, }, ;, < or a comment, and a default that is not a value. Axes whose names collide with an attribute a renderer already writes (step, theme, control, and the rest) are rejected by the engine.

Pass the theme to the engine and pick a value:

import { createFormEngine } from '@schema-engine/forms';
import { elements } from './registrations';
import { theme } from './theme';

const engine = createFormEngine({ elements, layout: theme });

export const config = engine.defineForm({
	id: 'newsletter',
	appearance: { tone: 'brand' },
	steps: [
		{
			id: 'signup',
			title: 'Sign up',
			elements: [{ $type: 'input', id: 'email', name: 'email', label: 'Email' }],
		},
	],
});

The renderer writes data-se-tone="brand" on the form, and the theme's stylesheet sets the colour roles below it (--primary, --on-primary, and the container roles). Radiant UI components read those roles, and shadcn components read --primary and --primary-foreground, so a button inside recolors with no further CSS. The themed form example is this axis, live.

Tokens are custom properties and inherit. Pick tone on the form and it reaches every field, until a nested form picks a value that declares the same tokens. Keep the axis list inline in createLayoutTheme or as const, so typed defineForm narrows the picks.

Override a built-in axis

List an axis with the same $type after builtInAxes: the last one of a name wins.

import { builtInAxes, createLayoutTheme, defineAxis } from '@schema-engine/layout';

const size = defineAxis({
	$type: 'size',
	metadata: { name: 'Size' },
	default: 'default',
	values: {
		compact: { '--se-space': '0.5rem' },
		default: { '--se-space': 'initial' },
		comfortable: { '--se-space': '2rem' },
	},
});

export const theme = createLayoutTheme({ appearance: [...builtInAxes, size] });

This replaces every token of size, so the card width (--se-measure) and control height (--se-control-height) of the built-in axis are gone. To retune only the numbers, set the hooks and token overrides in CSS instead; see Theming and the themed form example.

Identity tokens: when not to use an axis

An axis is a look that an author picks among a few. Some variation is not a pick: a colour per machine, per brand or per product follows from which entity a node is, and a domain can have seventeen of them or a hundred. That value is domain data. It does not belong in the theme, and defineAxis refuses it, because an axis holds at most five values.

QuestionAn axisIdentity tokens
Who decides the valueThe author of the document, among a few looksThe data: every entity has its own value
How many values2 to 5As many as the domain has
Where the values liveThe layout themeThe host's data and stylesheet
Which attribute carries itdata-se-<axis>, written by the rendererdata-<domain>, written by the host
Examplessize, surface, toneThe colour of a machine, a brand or a tenant

The pattern has three parts, and the layout package needs no new concept for it:

  1. The host writes its own attribute from the data (data-machine="sampler"). A data-se-* name is reserved for the renderers, so it is never used for this.
  2. The host's stylesheet maps each value to the semantic tokens that components already read, here --primary. Generate it from the same data that renders the nodes, and scope it under [data-se-theme="<id>"] when you want it to apply to one theme only.
  3. Axes still apply on top. An axis value may read the identity token, so the pick stays a choice among a few looks while the colour stays the entity's.
import { builtInAxes, createLayoutTheme, defineAxis, getAppearanceAttributes } from '@schema-engine/layout';
import { machines } from './machines.helper';

export const machineCss = machines.map(({ id, color }) => `[data-machine="${id}"] { --primary: ${color}; }`).join('\n');

const tint = defineAxis({
	$type: 'tint',
	metadata: { name: 'Tint' },
	default: 'none',
	values: {
		none: {},
		tinted: { '--se-surface-background': 'color-mix(in srgb, var(--primary) 12%, transparent)' },
	},
});

export const theme = createLayoutTheme({ appearance: [...builtInAxes, tint] });

export function machineAttributes(id: string): Record<string, string> {
	return { 'data-machine': id, ...getAppearanceAttributes({ tint: 'tinted' }) };
}

machines is the host's own list, one { id, color } for each of the 17 machines. machineCss is one rule for each of them, which you ship as a stylesheet or generate at build time:

[data-machine='sampler'] {
	--primary: #e4572e;
}
[data-machine='synth'] {
	--primary: #f2a541;
}

A node of the sampler carries data-machine="sampler" and the data-se-tint="tinted" that the document picked, so it is the sampler's colour, tinted. Every component below it that reads --primary follows, with no axis value for the sampler. Choose by the rule of thumb: an axis when an author chooses among two to five looks, identity tokens when every entity has its own value.

Style the attributes in CSS

An axis value is a plain attribute, so CSS can key on it:

.brand-form[data-se-tone='forest'] {
	border-inline-start-style: dashed;
}

[data-se-size='compact'] .se-form-field {
	font-size: 0.8125rem;
}

Write the selector with at least the specificity of a class: the theme's token rules are zero-specificity, so a class of yours on the same element wins. The renderers' own data-se-* attributes (step, theme, control, constraint-field, and the others) are reserved and cannot be axis names.

For editors: a JSON Schema enum

The catalog and the JSON Schema export list each axis and its values, so appearance.size on a form and its steps is an enum an editor completes. On an element or a recipe slot, appearance lists only the axes its registration declares and is closed, so an undeclared axis is rejected in the editor as validateForm rejects it. The children of a fieldset or an array row get the same per-element schema as top-level elements. An element with a lazy schema keeps its own appearance in the export; validateForm checks it.

When to use something else

You wantUse
To hide the description, change labels or switch orientation of one recipeSlot config: view.header.showDescription, view.header.labels
A wider card, or a different media widthSlot config that changes layout (contentWidth, sideWidth), or --se-measure in your CSS
Fields on one row, a drawn layout, spacing between rowsThe grid: width, areas, the gap tokens
A one-off colour or size on one formclassName with a custom property, or style: { '--primary': '#c2410c' }
A colour for each of many entities (17 machines, every brand)Your own data-<domain> attribute and CSS that sets the tokens (Identity tokens)
A look no axis names, onceA class in className

The size and surface tokens set the card's padding, border and shadow, and its width is --se-measure.