<script setup lang="ts">
import { ref } from 'vue'
import { useForm } from 'vee-validate'
import { toTypedSchema } from '@vee-validate/zod'
import * as z from 'zod'
import {
BrUpload,
BrUploadTrigger,
BrUploadFileList,
BrUploadFileItem,
BrUploadPreview,
BrForm,
BrFormItem,
BrFormLabel,
BrFormControl,
BrFormMessage,
BrButton
} from '@breezeui/vue'
import { Upload } from 'lucide-vue-next'
const schema = toTypedSchema(
z.object({
documents: z.array(z.any()).min(1, 'Please upload at least one document')
})
)
const form = useForm({
validationSchema: schema,
initialValues: {
documents: []
}
})
const onSubmit = form.handleSubmit((values) => {
console.log('Form submitted with values:', values)
alert('Form submitted successfully!')
})
const previewFile = ref<any>(null)
const previewOpen = ref(false)
const handlePreview = (file: any) => {
previewFile.value = file
previewOpen.value = true
}
</script>
<template>
<div>
<BrForm class="space-y-6 max-w-md" @submit="onSubmit">
<BrFormItem name="documents">
<BrFormLabel>Important Documents *</BrFormLabel>
<BrFormControl>
<BrUpload
action="https://jsonplaceholder.typicode.com/posts/"
@preview="handlePreview"
>
<BrUploadTrigger>
<BrButton variant="outline" type="button">
<Upload class="w-4 h-4 mr-2" />
Select Document
</BrButton>
</BrUploadTrigger>
<BrUploadFileList v-slot="{ files }">
<BrUploadFileItem v-for="file in files" :key="file.id" :file="file" />
</BrUploadFileList>
</BrUpload>
</BrFormControl>
<BrFormMessage />
</BrFormItem>
<BrButton type="submit">Submit Form</BrButton>
</BrForm>
<BrUploadPreview v-model:open="previewOpen" :file="previewFile" />
</div>
</template>