Skip to content

Commit a3f57b1

Browse files
committed
feat: docs revisit
1 parent 158b802 commit a3f57b1

File tree

15 files changed

+2516
-2329
lines changed

15 files changed

+2516
-2329
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script setup lang="ts">
2+
import type { TabsItem } from '#ui/components/Tabs.vue'
3+
import * as z from 'zod'
4+
5+
const items: TabsItem[] = [
6+
{
7+
label: 'Code',
8+
icon: 'i-lucide-user',
9+
slot: 'code' as const,
10+
},
11+
{
12+
label: 'Preview',
13+
icon: 'i-lucide-lock',
14+
slot: 'preview' as const,
15+
},
16+
]
17+
18+
const org = `z.object({
19+
username: z.string().nonempty().meta({ title: 'Username' }),
20+
favoriteLanguage: z.enum(['JavaScript', 'TypeScript', 'Java', 'CoffeeScript'])
21+
.meta({
22+
title: 'Favorite Language',
23+
description: 'Choose wisely',
24+
}),
25+
yearsOfExperience: z.number().min(0).max(100),
26+
deployedOnFriday: z.boolean().default(true),
27+
text_description: z.string(),
28+
})`
29+
30+
function runEval(code: any, context = {}) {
31+
// eslint-disable-next-line no-new-func
32+
return new Function(...Object.keys(context), `return ${code}`)(...Object.values(context))
33+
}
34+
35+
const schema = runEval(org, { z })
36+
37+
const code = computed(() => {
38+
return [
39+
'```ts',
40+
`const schema = ${org}`,
41+
'```',
42+
].join('\n')
43+
})
44+
</script>
45+
46+
<template>
47+
<UTabs class="w-full" :items="items">
48+
<template #code>
49+
<MDC :value="code" />
50+
</template>
51+
52+
<template #preview>
53+
<div class="p-4 border rounded">
54+
<AutoForm :schema="schema" />
55+
</div>
56+
</template>
57+
</UTabs>
58+
</template>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// composables/useMarkdownParser.ts
2+
// Import package exports
3+
import {
4+
createMarkdownParser,
5+
createShikiHighlighter,
6+
rehypeHighlight,
7+
} from '@nuxtjs/mdc/runtime'
8+
import HtmlLang from '@shikijs/langs/html'
9+
import MdcLang from '@shikijs/langs/mdc'
10+
import ScssLang from '@shikijs/langs/scss'
11+
import TsLang from '@shikijs/langs/typescript'
12+
import VueLang from '@shikijs/langs/vue'
13+
import YamlLang from '@shikijs/langs/yaml'
14+
// Import desired Shiki themes and languages
15+
import MaterialThemePalenight from '@shikijs/themes/material-theme-palenight'
16+
17+
export default function useMarkdownParser() {
18+
let parser: Awaited<ReturnType<typeof createMarkdownParser>>
19+
20+
const parse = async (markdown: string) => {
21+
if (!parser) {
22+
parser = await createMarkdownParser({
23+
rehype: {
24+
plugins: {
25+
highlight: {
26+
instance: rehypeHighlight,
27+
options: {
28+
// Pass in your desired theme(s)
29+
theme: 'material-theme-palenight',
30+
// Create the Shiki highlighter
31+
highlighter: createShikiHighlighter({
32+
bundledThemes: {
33+
'material-theme-palenight': MaterialThemePalenight,
34+
},
35+
// Configure the bundled languages
36+
bundledLangs: {
37+
html: HtmlLang,
38+
mdc: MdcLang,
39+
vue: VueLang,
40+
yml: YamlLang,
41+
scss: ScssLang,
42+
ts: TsLang,
43+
typescript: TsLang,
44+
},
45+
}),
46+
},
47+
},
48+
},
49+
},
50+
})
51+
}
52+
return parser(markdown)
53+
}
54+
55+
return parse
56+
}

docs/content/1.getting-started/1.index.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,58 @@ Read more about them below:
5454
- **Good Looking**: Leverages Nuxt UI components for a consistent and modern design.
5555
- **Dynamic Field Rendering**: Supports various field types, including text inputs, selects, checkboxes, and more.
5656
- **Customizable**: Easily customize any button, field and input
57+
58+
::code-preview
59+
---
60+
class: "[&>div]:*:w-full"
61+
---
62+
:::collapsible
63+
| Prop | Default | Type |
64+
| ------- | --------- | -------- |
65+
| `name` | | `string` |
66+
| `size` | `md` | `string` |
67+
| `color` | `neutral` | `string` |
68+
:::
69+
70+
#code
71+
```mdc
72+
::collapsible
73+
74+
| Prop | Default | Type |
75+
|---------|-----------|--------------------------|
76+
| `name` | | `string`{lang="ts-type"} |
77+
| `size` | `md` | `string`{lang="ts-type"} |
78+
| `color` | `neutral` | `string`{lang="ts-type"} |
79+
80+
::
81+
```
82+
::
83+
84+
::code-group
85+
```md [Code]
86+
# H1 Heading
87+
```
88+
89+
:::code-preview{.pt-4 label="Preview"}
90+
<!-- markdownlint-disable-next-line -->
91+
# H1 Heading
92+
:::
93+
::
94+
95+
::code-preview
96+
`inline code`
97+
98+
#code
99+
100+
```mdc
101+
`inline code`
102+
```
103+
::
104+
105+
asdasd
106+
107+
::form-preview
108+
109+
::
110+
111+
asdasd
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Config
3+
description: Configure Nuxt Auto Form module
4+
---
5+
6+
You do not need to configure Nuxt Auto Form, but you can do so for finer-grained control
7+
you can override the config in the `nuxt.config.ts` file or per form basis.
8+
9+
The configuration is merged using [defu](https://github.com/unjs/defu).
10+
11+
## Global Configuration
12+
13+
You can set global configuration options for the module in your `nuxt.config.ts` file in the `autoForm` field
14+
Here you should define your universal styles like submit button color.
15+
16+
```ts [nuxt.config.ts]
17+
export default defineNuxtConfig({
18+
modules: ['@norbiros/nuxt-auto-form'],
19+
fonts: {
20+
// Options
21+
}
22+
})
23+
```
24+
25+
## Per-Form Configuration
26+
27+
Sometimes you may want to override the global configuration for individual forms.
28+
You can do this by passing a `config` prop to the `<AutoForm>` component:
29+
30+
```vue
31+
<template>
32+
<AutoForm
33+
:schema="schema"
34+
:config="{
35+
submit: {
36+
component: 'CustomSubmitButton',
37+
},
38+
}"
39+
/>
40+
</template>
41+
```
42+
43+
## Fields
44+
45+
### `components`
46+
47+
When a field in a form is rendered, the module automatically generates key
48+
```ts
49+
zodType._def.format ?? zodType._def.type
50+
```
51+
52+
This key is used to look up the component to render the field.
53+
You can override the default components used for rendering fields by specifying a mapping in the `components` option.
54+
55+
::caution
56+
If you use string to define the component it **must** be [globally registered](https://nuxt.com/docs/4.x/guide/directory-structure/app/components#dynamic-components) to work.
57+
To do this, name your component with the `.global.vue` suffix, or place it in `components/global/` directory.
58+
::
59+
60+
```
61+
components: {
62+
email: () => ({ component: 'UInput', componentProps: { type: 'email' } }),
63+
}
64+
```
65+
66+
For default values consult the source code.
67+
68+
### `submit`
69+
70+
This option allows you to customize the submit button used in forms.
71+
72+
```
73+
{
74+
component?: undefined
75+
props?: Record<string, any>
76+
}
77+
```
78+
79+
If the component is unset, the props will be redefined to be the [`UButton`](https://ui.nuxt.com/components/button) props.

docs/content/2.customization/1.index.md

Lines changed: 0 additions & 82 deletions
This file was deleted.

docs/content/2.customization/3.submit_button.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: <SubmitButton/>
2+
title: Submit Button
33
description: Customizable submit button component for Nuxt Auto Form.
44
---
55

@@ -17,11 +17,6 @@ export default defineAppConfig({
1717
})
1818
```
1919

20-
::caution
21-
The component **must** be [globally registered](https://nuxt.com/docs/4.x/guide/directory-structure/app/components#dynamic-components) to work.
22-
To do this, name your component with the `.global.vue` suffix, or place it in `components/global/` directory.
23-
::
24-
2520
## Fields
2621

2722
::field-group
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: Components
2+
icon: i-lucide-shapes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: <AutoForm/>
3-
description: The most important component of Nuxt Auto FOrm.
3+
description: The most important component of Nuxt Auto Form.
44
---
55

66
# Usage

docs/nuxt.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// https://nuxt.com/docs/api/configuration/nuxt-config
22
export default defineNuxtConfig({
33
modules: [
4+
'@norbiros/nuxt-auto-form',
45
'@nuxt/eslint',
56
'@nuxt/image',
67
'@nuxt/ui-pro',
@@ -13,6 +14,12 @@ export default defineNuxtConfig({
1314
enabled: true,
1415
},
1516

17+
mdc: {
18+
highlight: {
19+
langs: ['ts'], // add 'ts' here
20+
},
21+
},
22+
1623
css: ['~/assets/css/main.css'],
1724

1825
content: {

0 commit comments

Comments
 (0)