# UI Schemas

These instructions apply to the current Admin Console.

UI Schemas customize how Contextual renders Object Type records in the admin experience.

At a high level, Contextual uses JSON Forms-style UI schemas for form layouts, but it also supports additional styles and options that go beyond vanilla JSON Forms.

## Supported styles

Contextual UI Schemas can define different layouts for different experiences:

- `createStyle` - layout for creating a new record
- `updateStyle` - layout for editing an existing record
- `readStyle` - layout for read-only record views
- `duplicateStyle` - layout used when duplicating an existing record
- `listStyle` - table/list configuration for collections of records
- `relatedStyle` - related-record presentation used by relation-aware views

### Create form example

This `createStyle` layout displays four fields in a single column. Each `scope` points to a property in the Object Type’s data schema.

```json
{
  "type": "VerticalLayout",
  "elements": [
    {
      "type": "Control",
      "scope": "#/properties/id"
    },
    {
      "type": "Control",
      "scope": "#/properties/viewerQuestion"
    },
    {
      "type": "Control",
      "scope": "#/properties/aiClassification"
    },
    {
      "type": "Control",
      "scope": "#/properties/aiRecommendedAction"
    }
  ]
}
```

## How this differs from vanilla JSON Forms

The form-oriented styles (`createStyle`, `updateStyle`, `readStyle`) follow the usual JSON Forms idea of composing controls and layouts.

Contextual also adds platform-specific styles and behavior, especially for:

- list/table configuration
- duplicate views
- related-record views
- specialized renderers selected by schema `renderer` values or UI schema `options.renderer`

## List-style configuration

`listStyle` controls how records appear in grids and list views. In the current product, it supports concepts such as:

- `columns`
- default `order`
- pagination options such as including or excluding the total-count request
- column sizing such as `width`, `minWidth`, `maxWidth`, and `flex`

When you do not define a custom list schema, Contextual generates a default one from the scalar properties in your Object Type and uses the `primaryKey` as the default sort.

## Custom renderers

Contextual supports custom renderers that are not part of standard JSON Forms. Examples visible in the current admin console include `code-editor`, `relation`, and `flow-relation`.

These renderers can be selected either:

- directly on a schema property via `renderer`
- through UI schema options such as `options.renderer`

For schema-level extensions that drive these behaviors, see [Contextual Schema Extensions](https://docs.contextual.io/build/object-types/object-type-details/data-schema/contextual-schema-extensions.md).

## Practical guidance

- start with the generated defaults and customize only where the default UX is not sufficient
- use form styles for layout and grouping
- use `listStyle` when the record grid needs custom columns, order, or pagination behavior
- use renderer-driven customization sparingly and intentionally, since it couples the schema to Contextual-specific UI behavior
