|
1 | 1 | <script setup lang="ts" generic="T extends z.ZodObject<any>"> |
2 | 2 | import type { FormSubmitEvent, InferInput, InferOutput } from '@nuxt/ui' |
3 | | -import type { AutoFormConfig } from '../types' |
| 3 | +import type { AutoFormConfig, ComponentsMap } from '../types' |
4 | 4 | import { useAppConfig } from '#app' |
5 | 5 | import UButton from '@nuxt/ui/components/Button.vue' |
6 | 6 | import UCheckbox from '@nuxt/ui/components/Checkbox.vue' |
@@ -43,7 +43,7 @@ interface ComponentDefinition { |
43 | 43 | componentProps?: Record<string, any> |
44 | 44 | } |
45 | 45 |
|
46 | | -const COMPONENTS_MAP: Record<string, (key: string, zodType: any) => ComponentDefinition | null> = { |
| 46 | +const COMPONENTS_MAP: ComponentsMap = { |
47 | 47 | number: () => ({ component: UInputNumber }), |
48 | 48 | string: () => ({ component: UInput }), |
49 | 49 | boolean: () => ({ component: UCheckbox }), |
@@ -99,7 +99,7 @@ function parseMeta(meta: any, key: string) { |
99 | 99 |
|
100 | 100 | function mapZodTypeToComponent(key: string, zodType: any): ComponentDefinition | null { |
101 | 101 | const zodTypeKey = zodType._def.format ?? zodType._def.type |
102 | | - const component = COMPONENTS_MAP[zodTypeKey] |
| 102 | + const component = defu(useAppConfig().autoForm?.components, COMPONENTS_MAP)[zodTypeKey] |
103 | 103 | if (!component) { |
104 | 104 | console.warn(`Unsupported Zod type: ${zodTypeKey}`) |
105 | 105 | return null |
|
0 commit comments