mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 04:19:20 +00:00
46 lines
1.2 KiB
Vue
46 lines
1.2 KiB
Vue
<script setup lang="ts" generic="U extends ZodAny">
|
|
import { computed } from "vue";
|
|
import type { Config, ConfigItem, Shape } from "./interface";
|
|
import useDependencies from "./dependencies";
|
|
|
|
const props = defineProps<{
|
|
fieldName: string;
|
|
shape: Shape;
|
|
config?: ConfigItem | Config<U>;
|
|
}>();
|
|
|
|
function isValidConfig(config: any): config is ConfigItem {
|
|
return !!config?.component;
|
|
}
|
|
|
|
const delegatedProps = computed(() => {
|
|
if (["ZodObject", "ZodArray"].includes(props.shape?.type))
|
|
return { schema: props.shape?.schema };
|
|
return undefined;
|
|
});
|
|
|
|
const { isDisabled, isHidden, isRequired, overrideOptions } = useDependencies(
|
|
props.fieldName,
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<component
|
|
:is="isValidConfig(config)
|
|
? typeof config.component === 'string'
|
|
? INPUT_COMPONENTS[config.component!]
|
|
: config.component
|
|
: INPUT_COMPONENTS[DEFAULT_ZOD_HANDLERS[shape.type]] "
|
|
v-if="!isHidden"
|
|
:field-name="fieldName"
|
|
:label="shape.schema?.description"
|
|
:required="isRequired || shape.required"
|
|
:options="overrideOptions || shape.options"
|
|
:disabled="isDisabled"
|
|
:config="config"
|
|
v-bind="delegatedProps"
|
|
>
|
|
<slot />
|
|
</component>
|
|
</template>
|