diff --git a/src/components/file/VFileUpload.vue b/src/components/file/VFileUpload.vue index 9f47ec5..64dad30 100644 --- a/src/components/file/VFileUpload.vue +++ b/src/components/file/VFileUpload.vue @@ -11,17 +11,16 @@ import type { FileUploadErrorEvent, FileUploadProgressEvent, FileUploadRemoveEve import { computed, useId, ref, onMounted } from 'vue'; import styles from '@visua/typography.module.css'; +const fileUploadRef = ref(); +const fileProgressMap = ref>({}); +const fileSelected = ref(false); +const hasActiveError = ref(false); +const lastSelectedFile = ref(null); + defineOptions({ inheritAttrs: false, }) -const fileUploadRef = ref(); -const fileProgressMap = ref>({}); - -defineExpose({ - upload: () => fileUploadRef.value.upload() -}); - const props = withDefaults(defineProps(), { id: () => useId(), label: 'Ajouter un fichier', @@ -43,7 +42,7 @@ const props = withDefaults(defineProps(), { cancelLabel: 'Annuler', showCancelButton: true, showUploadButton: true, - advanced: false, + advanced: false }) const emit = defineEmits([ @@ -58,22 +57,21 @@ const emit = defineEmits([ 'removeUploadFile', 'uploader', ]); -const fileSelected = ref(false); -const hasActiveError = ref(false); -const lastSelectedFile = ref(null); +defineExpose({ + upload: () => fileUploadRef.value.upload() +}); const handleSelect = (event: FileUploadSelectEvent) => { emit('select', event); - if (!props.advanced && event.files.length > 0 && fileUploadRef.value) { - fileUploadRef.value.clear(); - fileUploadRef.value.files.push(event.files[event.files.length - 1]); + fileUploadRef.value.files = [event.files.at(-1)]; + lastSelectedFile.value = event.files.at(-1); + } fileSelected.value = true; }; - const handleClear = () => { emit('clear'); fileSelected.value = false; @@ -82,13 +80,9 @@ const handleClear = () => { }; const handleUpload = (event: FileUploadUploadEvent) => { - totalSize.value = 0; - totalSizePercent.value = 100; emit('upload', event); - hasActiveError.value = false; }; - const handleRemove = (event: FileUploadRemoveEvent) => { emit('remove', event); fileSelected.value = false; @@ -110,34 +104,19 @@ const handleError = (event: FileUploadErrorEvent) => { hasActiveError.value = true; } -const error = computed(() => hasActiveError.value); - - -const isSimpleAndEmpty = computed(() => { - return !props.advanced && !fileSelected.value; -}); +const uploadEvent = (callback: () => void) => { + callback(); +}; onMounted(() => { const currentFiles = fileUploadRef.value?.files || []; fileSelected.value = currentFiles.length > 0; }); -const totalSize = ref(0); -const totalSizePercent = ref(0); - -const uploadEvent = (callback: () => void) => { - totalSizePercent.value = totalSize.value / 10; - callback(); - fileUploadRef.value.upload(); -}; - const padding = computed(() => props.advanced ? '1.125rem' : '0rem') const borderColor = computed(() => props.advanced ? 'var(--border-default-grey)' : 'transparent'); -const getLastFileSelected = (files: File[]) => { - const indexOfLastFileSelected = files.length - 1; - return files[indexOfLastFileSelected]; -} +const error = computed(() => hasActiveError.value); const labelState = computed(() => { if(!error.value && !props.disabled) return 'default'; @@ -163,7 +142,6 @@ const globalStatusMessage = computed<{ return null; }); -