jws-frontend/src/components/button/ImportButton.vue

55 lines
1.1 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
2025-04-22 13:58:26 +07:00
import { ref } from 'vue';
import MainButton from './MainButton.vue';
2025-04-22 13:58:26 +07:00
const emit = defineEmits<{
(e: 'click', v: MouseEvent): void;
2025-04-22 13:58:26 +07:00
(e: 'fileSelected', v: File[]): void;
}>();
defineProps<{
iconOnly?: boolean;
solid?: boolean;
outlined?: boolean;
disabled?: boolean;
dark?: boolean;
2025-04-22 13:58:26 +07:00
importFile?: boolean;
label?: string;
icon?: string;
}>();
2025-04-22 13:58:26 +07:00
const inputRef = ref<HTMLInputElement | null>(null);
function triggerFileInput() {
inputRef.value?.click();
}
function handleFileChange(event: Event) {
const files = (event.target as HTMLInputElement).files;
if (files && files.length > 0) {
emit('fileSelected', Array.from(files));
}
}
</script>
<template>
<MainButton
2025-04-22 13:58:26 +07:00
@click="(e) => (importFile ? triggerFileInput() : $emit('click', e))"
v-bind="{ ...$props, ...$attrs }"
:icon="icon || 'mdi-import'"
color="var(--info-bg)"
:title="iconOnly ? $t('general.import') : undefined"
>
{{ label || $t('general.import') }}
</MainButton>
2025-04-22 13:58:26 +07:00
<input
ref="inputRef"
type="file"
@change="(e) => handleFileChange(e)"
hidden
accept=".xls, .xlsx , .csv"
multiple
/>
</template>