Skip to content

Commit 08fd177

Browse files
authored
docs(studio): form generation with zod (#3165)
1 parent 7191516 commit 08fd177

File tree

1 file changed

+92
-7
lines changed

1 file changed

+92
-7
lines changed

docs/content/docs/8.studio/3.content.md

+92-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Edit your content
33
navigation:
4-
title: Content editors
4+
title: Content Editors
55
description: Discover and select your favorite way to manage your content
66
between the visual or the code editor.
77
seo:
@@ -38,7 +38,11 @@ You want to know how we've built this editor and how it works under the hood? Ch
3838

3939
Based on the user [collection and schema](/docs/collections/define) provided, a form is generated to edit this metadata from the editor.
4040

41-
:video{autoplay controls loop poster="/home/videos/HomeNotionLikePoster.webp" src="https://res.cloudinary.com/nuxt/video/upload/v1729157955/frontmatterform2_rmh58v.mp4"}
41+
:video{autoplay controls loop poster="/home/videos/HomeNotionLikePoster.webp" src="https://res.cloudinary.com/nuxt/video/upload/v1739982761/frontmatterform_yjafgt.mp4"}
42+
43+
::prose-note{to="#form-editor-yaml-and-json-files"}
44+
Check this section to learn more about form generation based on schema.
45+
::
4246

4347
### Toolbar
4448

@@ -61,7 +65,6 @@ One of this editor standout features is its ability to integrate and customize a
6165
A developer can create any kind of visually complex components and editors will be able to use them and focus on the content. An editor can also play with the component properties, styles, and behaviour to fit its specific requirements as long as the developer made it customisable.
6266

6367
::steps{level="4"}
64-
6568
#### Create your component
6669

6770
You can create Vue components and integrate them into Markdown. They just need to be located in the `/components/content` folder to be available.
@@ -140,13 +143,95 @@ export default defineNuxtConfig({
140143
})
141144
```
142145

143-
## Form editor (`YAML` and `JSON` files)
146+
## Form editor
147+
148+
![YAML and JSON edition with auto generated form](/blog/frontmatters.png)
149+
150+
This editor is used whether you’re editing the [frontmatter]() of a `Markdown` file or a `JSON` / `YAML` file.
151+
152+
It eliminates the need to interact directly with complex file syntax. Instead, a form is automatically generated based on the provided user [collection schema](/docs/collections/define).
153+
154+
### **Defining your form with** `zod` Schema
155+
156+
::prose-note{to="/docs/collections/define"}
157+
Learn more about schema collection definition in the dedicated section.
158+
::
159+
160+
Once the `schema` property has been defined in your collection, this will automatically generate the corresponding form on Studio interface.
161+
162+
::prose-code-group
163+
```ts [content.config.ts]
164+
export default defineContentConfig({
165+
collections: {
166+
posts: defineCollection({
167+
type: 'page',
168+
source: 'blog/*.md',
169+
schema: z.object({
170+
draft: z.boolean().default(false),
171+
category: z.enum(['Alps', 'Himalaya', 'Pyrenees']).optional(),
172+
date: z.date(),
173+
image: z.object({
174+
src: z.string().editor({ input: 'media' }),
175+
alt: z.string(),
176+
}),
177+
slug: z.string().editor({ hidden: true }),
178+
icon: z.string().optional().editor({ input: 'icon' }),
179+
authors: z.array(z.object({
180+
slug: z.string(),
181+
username: z.string(),
182+
name: z.string(),
183+
to: z.string(),
184+
avatar: z.object({
185+
src: z.string(),
186+
alt: z.string(),
187+
}),
188+
})),
189+
}),
190+
}),
191+
},
192+
})
193+
```
194+
195+
:::preview-card{icon="i-lucide-eye" label="Generated Form"}
196+
![Form preview](/blog/generated-form.png)
197+
:::
198+
::
199+
200+
### **Native Inputs Mapping**
201+
202+
Primitive Zod types are automatically mapped to appropriate form inputs in:
203+
204+
- **String** → Text input
205+
- **Date** → Date picker
206+
- **Number** → Number input (counter)
207+
- **Boolean** → Toggle switch
208+
- **Enum** → Select dropdown
209+
210+
### Custom Inputs Mapping
211+
212+
Studio goes beyond primitive types. You can customise form fields using the `editor` method, which extends Zod types with metadata to empower editor interface.
213+
214+
This allows you to define custom inputs or hide fields.
215+
216+
#### Usage
217+
218+
```ts [content.config.ts]
219+
mainScreen: z.string().editor({ input: 'media' })
220+
```
221+
222+
#### Options
144223

145-
![YAML and JSON edition with auto generated form](/docs/studio/json-yml-forms.png)
224+
##### `input: 'media' | 'icon'`
146225

147-
This editor removes the need for users to interact directly with complex file syntax such as `YAML` or `JSON`.
226+
You can set the editor input type. Currently `icon` and `media` are available.
148227

149-
Based on the user [collection and schema](/docs/collections/define) provided, a form is generated for both `YAML` and `JSON` files.
228+
##### `hidden: Boolean`
229+
230+
This option can be set to avoid the display of a field in the Studio editor.
231+
232+
::prose-tip
233+
Studio inputs are fully extensible. We can create as many input as we want based on our users needs.
234+
::
150235

151236
::warning
152237
Arrays are not yet handled but should be generated soon thanks to collections and user-defined schemas.

0 commit comments

Comments
 (0)