Fields

Size

A number with a CSS unit, for spacing and widths that editors set.
The size field in the admin

Example

cms/blocks/section.ts
fields: {
  gap: { type: "size", units: ["px", "rem"], min: 0 },
  maxWidth: { type: "size", units: ["px", "%", "ch"], default: { value: 720, unit: "px" } },
}

The first unit in units is preselected. A read returns the number and the unit:

section.gap; // { value: 2, unit: "px" | "rem" } | null | undefined

Render it

Join the two parts to get a CSS value:

<section style={{ gap: section.gap && `${section.gap.value}${section.gap.unit}` }}>
  <slot />
</section>

Options

The CSS units the editor can pick, like ["px", "rem", "vh"]. The first is preselected.The smallest number.The largest number.The number MUST be min (or 0) plus a whole number of steps.Shown in the empty input.