feat: expose custom auto form slot
This commit is contained in:
parent
baa83ecec8
commit
9769d10209
|
|
@ -45,6 +45,20 @@ const shapes = computed(() => {
|
||||||
return val
|
return val
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const fields = computed(() => {
|
||||||
|
// @ts-expect-error ignore {} not assignable to object
|
||||||
|
const val: { [key in keyof z.infer<T>]: { shape: Shape, fieldName: string, config: ConfigItem } } = {}
|
||||||
|
for (const key in shapes.value) {
|
||||||
|
const shape = shapes.value[key]
|
||||||
|
val[key as keyof z.infer<T>] = {
|
||||||
|
shape,
|
||||||
|
config: props.fieldConfig?.[key] as ConfigItem,
|
||||||
|
fieldName: key,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
})
|
||||||
|
|
||||||
const formComponent = computed(() => props.form ? 'form' : Form)
|
const formComponent = computed(() => props.form ? 'form' : Form)
|
||||||
const formComponentProps = computed(() => {
|
const formComponentProps = computed(() => {
|
||||||
if (props.form) {
|
if (props.form) {
|
||||||
|
|
@ -68,6 +82,7 @@ const formComponentProps = computed(() => {
|
||||||
:is="formComponent"
|
:is="formComponent"
|
||||||
v-bind="formComponentProps"
|
v-bind="formComponentProps"
|
||||||
>
|
>
|
||||||
|
<slot name="customAutoForm" :fields="fields">
|
||||||
<template v-for="(shape, key) of shapes" :key="key">
|
<template v-for="(shape, key) of shapes" :key="key">
|
||||||
<slot
|
<slot
|
||||||
:shape="shape"
|
:shape="shape"
|
||||||
|
|
@ -82,6 +97,7 @@ const formComponentProps = computed(() => {
|
||||||
/>
|
/>
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
|
</slot>
|
||||||
|
|
||||||
<slot :shapes="shapes" />
|
<slot :shapes="shapes" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user