Skip to main content

items

Describes the controls the editor renders. Each entry maps a control to a value in values and carries its label, validation, and layout options.

Usage

items?: IItemConfig[];

Each IItemConfig has the following shape:

interface IItemConfig {
comp?: string;
key?: TID;
keys?: TID[];
id?: TID;
label?: string;
column?: string;
batch?: string;
section?: string;
sectionMode?: "exclusive" | "accordion";
activeSection?: boolean;
hidden?: boolean;
required?: boolean;
validation?: (value: any) => boolean;
validationMessage?: string;
config?: Record<string, any>;
getter?: (obj: any) => any;
setter?: (obj: any, value: any) => void;
css?: string;
fill?: boolean;
[key: string]: any;
}
FieldTypeDescription
compstringRenderer key. Built-in: "text", "textarea", "checkbox", "readonly", "section". Omitted falls back to "text"; "hidden" removes the item. See built-in controls.
key / keysTID / TID[]Use key to map the item to a single values[key] (dotted strings address nested paths - see value mapping). Use keys instead to bind one control to several fields, receiving and emitting a composite object - see multi-field items. The two are mutually exclusive.
idTIDItem identifier, used for action targeting. See onaction.
labelstringField label text.
columnstring"left" places the field in the left pane under layout="columns"; any other value goes right. See two-column layout.
batchstringGroup tag; the item shows only when activeBatch matches. See batches for tabbed forms.
sectionstringSection header key this item belongs to. See collapsible sections.
hiddenbooleanHides the item.
requiredbooleanMarks the field invalid when its value is falsy. See required fields and custom validation.
validation(value: any) => booleanCustom validator; return false to mark the field invalid. See required fields and custom validation.
validationMessagestringMessage shown under the field on validation failure. See required fields and custom validation.
configRecord<string, any>Extra props promoted onto the item before rendering; on conflict, config wins over the top-level value. See item specific configuration.
getter(obj: any) => anyReads the item value from a custom record shape. See value mapping.
setter(obj: any, value: any) => voidWrites the item value back into a custom record shape. See value mapping.
cssstringExtra CSS class on the item.
fillbooleanRenders edge-to-edge with no label; effective only as the single visible item. See full-height single field.

Unlisted properties are forwarded to the rendered component. TID is string | number.

Section header properties

These apply only to a comp: "section" header item. See collapsible sections.

FieldTypeDescription
sectionMode"exclusive" | "accordion"Collapse behavior for the header. See accordion and exclusive modes.
activeSectionbooleanWhether the section starts expanded.

Example

import { Editor } from "@svar-ui/react-editor";

const items = [
{ comp: "text", key: "name", label: "Name", required: true },
{ comp: "textarea", key: "notes", label: "Notes" },
{ comp: "checkbox", key: "admin", label: "Is Admin" },
];

const values = { name: "Alex", notes: "", admin: false };

export default function App() {
return <Editor items={items} values={values} />;
}