Skip to content

Commit 00be16c

Browse files
committed
[docs] Add ui schema evaluation rules paragraph
1 parent 808d76e commit 00be16c

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

.changeset/three-donuts-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"docs": patch
3+
---
4+
5+
Add ui schema evaluation rules paragraph
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Schema, UiSchemaRoot } from "@sjsf/form";
2+
3+
const schema: Schema = {
4+
oneOf: [
5+
{
6+
properties: {
7+
foo: {
8+
type: "string",
9+
},
10+
},
11+
},
12+
{
13+
properties: {
14+
bar: {
15+
type: "number",
16+
},
17+
},
18+
},
19+
],
20+
};
21+
22+
const uiSchema: UiSchemaRoot = {
23+
foo: {
24+
// ui schema for `foo` field
25+
},
26+
bar: {
27+
// ui schema for `bar` field
28+
},
29+
};

apps/docs/src/content/docs/api-reference/ui-schema.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ sidebar:
44
order: 2
55
---
66

7+
import { Code } from '@astrojs/starlight/components'
8+
9+
import uiSchemaExampleCode from './_ui-schema-example.ts?raw'
10+
711
UI schema allows you to customize the appearance of the form and influence its behavior.
812

913
The UI schema object follows the tree structure of the form field hierarchy, and defines how each property should be rendered.
@@ -130,3 +134,49 @@ interface UiOptions {
130134
emptyValue?: SchemaValue;
131135
}
132136
```
137+
138+
## UI schema evaluation rules
139+
140+
Usually ui schema corresponds to the data structure described by json schema.
141+
142+
For example, with this json schema, the following ui schema would be correct:
143+
144+
<Code code={uiSchemaExampleCode} lang="typescript" />
145+
146+
Special cases:
147+
148+
### Array
149+
150+
Instead of defining indices in the ui schema, the `items` keyword should be used
151+
to specify the ui schema for the elements of the array.
152+
153+
For a fixed array `items` also can be an array.
154+
If you have additional items you should use `additionalItems` keyword
155+
to specify the ui schema for them.
156+
157+
```
158+
{
159+
items: [<uiSchema>, ...],
160+
additionalItems: <uiSchema>
161+
}
162+
```
163+
164+
### Object
165+
166+
You should use `additionalProperties` keyword to specify the ui schema for
167+
additional properties.
168+
169+
You can use `additionalPropertyKeyInput` keyword to define an ui schema for
170+
the additional property key input field.
171+
172+
### oneOf/anyOf
173+
174+
You can define separate ui schemas for each `oneOf/anyOf` branch
175+
using the corresponding keyword in the ui schema.
176+
Otherwise the ui schema of the current field will be used.
177+
178+
```
179+
{
180+
oneOf: [<uiSchema>, ...]
181+
}
182+
```

0 commit comments

Comments
 (0)