Files
rustfs-console/components/ui/auto-form/AutoFormFieldInput.vue
T
2025-10-25 16:04:31 +08:00

37 lines
1.3 KiB
Vue

<script setup lang="ts">
import type { FieldProps } from "./interface"
import { computed } from "vue"
import { FormControl, FormDescription, FormField, FormItem, FormMessage } from '@/components/ui/form'
import { Input } from '@/components/ui/input'
import { Textarea } from '@/components/ui/textarea'
import AutoFormLabel from "./AutoFormLabel.vue"
import { beautifyObjectName } from "./utils"
const props = defineProps<FieldProps>()
const inputComponent = computed(() => props.config?.component === "textarea" ? Textarea : Input)
</script>
<template>
<FormField v-slot="slotProps" :name="fieldName">
<FormItem v-bind="$attrs">
<AutoFormLabel v-if="!config?.hideLabel" :required="required">
{{ config?.label || beautifyObjectName(label ?? fieldName) }}
</AutoFormLabel>
<FormControl>
<slot v-bind="slotProps">
<component
:is="inputComponent"
type="text"
v-bind="{ ...slotProps.componentField, ...config?.inputProps }"
:disabled="config?.inputProps?.disabled ?? disabled"
/>
</slot>
</FormControl>
<FormDescription v-if="config?.description">
{{ config.description }}
</FormDescription>
<FormMessage />
</FormItem>
</FormField>
</template>