Files
better-auth/examples/nuxt-example/components/ui/auto-form/AutoFormFieldBoolean.vue
Bereket Engida 9f2e45b8c7 chore: cleanup
2025-01-06 14:30:39 +03:00

41 lines
1.2 KiB
Vue

<script setup lang="ts">
import { computed } from "vue";
import type { FieldProps } from "./interface";
import { Switch } from "@/components/ui/switch";
import { Checkbox } from "@/components/ui/checkbox";
const props = defineProps<FieldProps>();
const booleanComponent = computed(() =>
props.config?.component === "switch" ? Switch : Checkbox,
);
</script>
<template>
<FormField v-slot="slotProps" :name="fieldName">
<FormItem>
<div class="space-y-0 mb-3 flex items-center gap-3">
<FormControl>
<slot v-bind="slotProps">
<component
:is="booleanComponent"
v-bind="{ ...slotProps.componentField }"
:disabled="disabled"
:checked="slotProps.componentField.modelValue"
@update:checked="slotProps.componentField['onUpdate:modelValue']"
/>
</slot>
</FormControl>
<AutoFormLabel v-if="!config?.hideLabel" :required="required">
{{ config?.label || beautifyObjectName(label ?? fieldName) }}
</AutoFormLabel>
</div>
<FormDescription v-if="config?.description">
{{ config.description }}
</FormDescription>
<FormMessage />
</FormItem>
</FormField>
</template>