Files
015/front/components/FileIcon/Index.vue

49 lines
1.5 KiB
Vue

<script setup lang="ts">
import { cx } from 'class-variance-authority'
import FileIcon from './File.vue'
import ImageIcon from './Image.vue'
import VideoIcon from './Video.vue'
export type filePreview = {
type: string
name: string
size: number
}
import { LucideFileAudio, LucideFileVideo, LucideFile, LucideFileCode, LucideFileArchive, LucideFileText } from 'lucide-vue-next'
const props = withDefaults(
defineProps<{
file: File | filePreview
class?: string
size?: 'sm' | 'md' | 'lg'
}>(),
{
size: 'md',
}
)
const isImage = computed(() => props?.file?.type?.startsWith('image/'))
const isVideo = computed(() => props?.file?.type?.startsWith('video/'))
</script>
<template>
<div v-if="isImage || isVideo" :class="cx('flex overflow-hidden', size === 'sm' && 'max-w-20 max-h-16', size === 'md' && 'max-w-30 max-h-20')">
<component
:is="isImage ? ImageIcon : VideoIcon"
:file="props?.file"
class="block max-w-full max-h-full object-contain border border-black/20 rounded"
/>
</div>
<div
v-else
:class="
cx(
'flex justify-center items-center bg-white/80',
size === 'sm' && 'size-7 rounded-md',
size === 'md' && 'size-16 rounded-xl',
props?.class
)
"
>
<component :is="FileIcon" :file="props?.file" class="size-[62.5%]" />
</div>
</template>