mirror of
https://github.com/hanzo-io/chat.git
synced 2026-10-30 18:57:58 +00:00
68 lines
6.7 KiB
React
68 lines
6.7 KiB
React
import React, { useMemo } from 'react'
|
|
|
|
// <!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc
|
|
|
|
const getFileType = (ext) => {
|
|
switch (ext) {
|
|
case 'pdf': return 'pdf'
|
|
case 'doc': return 'word'
|
|
case 'docx': return 'word'
|
|
case 'xls': return 'excel'
|
|
case 'xlsx': return 'excel'
|
|
case 'ppt': return 'powerpoint'
|
|
case 'pptx': return 'powerpoint'
|
|
case 'mp3': return 'audio'
|
|
case 'wav': return 'audio'
|
|
case 'ogg': return 'audio'
|
|
case 'flac': return 'audio'
|
|
case 'mp4': return 'video'
|
|
case 'mkv': return 'video'
|
|
case 'webm': return 'video'
|
|
case 'avi': return 'video'
|
|
case 'mov': return 'video'
|
|
case 'jpeg': return 'image'
|
|
case 'jpg': return 'image'
|
|
case 'png': return 'image'
|
|
default: return 'file'
|
|
}
|
|
}
|
|
const FileExtensionIcon = ({ ext, size = '20', ...props }) => {
|
|
|
|
const fileType = useMemo(() => getFileType(ext), [ext])
|
|
|
|
if (fileType === 'pdf') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} {...props} viewBox="0 0 384 512">
|
|
<path d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm250.2-143.7c-12.2-12-47-8.7-64.4-6.5-17.2-10.5-28.7-25-36.8-46.3 3.9-16.1 10.1-40.6 5.4-56-4.2-26.2-37.8-23.6-42.6-5.9-4.4 16.1-.4 38.5 7 67.1-10 23.9-24.9 56-35.4 74.4-20 10.3-47 26.2-51 46.2-3.3 15.8 26 55.2 76.1-31.2 22.4-7.4 46.8-16.5 68.4-20.1 18.9 10.2 41 17 55.8 17 25.5 0 28-28.2 17.5-38.7zm-198.1 77.8c5.1-13.7 24.5-29.5 30.4-35-19 30.3-30.4 35.7-30.4 35zm81.6-190.6c7.4 0 6.7 32.1 1.8 40.8-4.4-13.9-4.3-40.8-1.8-40.8zm-24.4 136.6c9.7-16.9 18-37 24.7-54.7 8.3 15.1 18.9 27.2 30.1 35.5-20.8 4.3-38.9 13.1-54.8 19.2zm131.6-5s-5 6-37.3-7.8c35.1-2.6 40.9 5.4 37.3 7.8z" /></svg>
|
|
}
|
|
if (fileType === 'excel') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} {...props} viewBox="0 0 384 512"><path d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm212-240h-28.8c-4.4 0-8.4 2.4-10.5 6.3-18 33.1-22.2 42.4-28.6 57.7-13.9-29.1-6.9-17.3-28.6-57.7-2.1-3.9-6.2-6.3-10.6-6.3H124c-9.3 0-15 10-10.4 18l46.3 78-46.3 78c-4.7 8 1.1 18 10.4 18h28.9c4.4 0 8.4-2.4 10.5-6.3 21.7-40 23-45 28.6-57.7 14.9 30.2 5.9 15.9 28.6 57.7 2.1 3.9 6.2 6.3 10.6 6.3H260c9.3 0 15-10 10.4-18L224 320c.7-1.1 30.3-50.5 46.3-78 4.7-8-1.1-18-10.3-18z" /></svg>
|
|
}
|
|
|
|
if (fileType === 'word') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} {...props} viewBox="0 0 384 512"><path d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm220.1-208c-5.7 0-10.6 4-11.7 9.5-20.6 97.7-20.4 95.4-21 103.5-.2-1.2-.4-2.6-.7-4.3-.8-5.1 .3 .2-23.6-99.5-1.3-5.4-6.1-9.2-11.7-9.2h-13.3c-5.5 0-10.3 3.8-11.7 9.1-24.4 99-24 96.2-24.8 103.7-.1-1.1-.2-2.5-.5-4.2-.7-5.2-14.1-73.3-19.1-99-1.1-5.6-6-9.7-11.8-9.7h-16.8c-7.8 0-13.5 7.3-11.7 14.8 8 32.6 26.7 109.5 33.2 136 1.3 5.4 6.1 9.1 11.7 9.1h25.2c5.5 0 10.3-3.7 11.6-9.1l17.9-71.4c1.5-6.2 2.5-12 3-17.3l2.9 17.3c.1 .4 12.6 50.5 17.9 71.4 1.3 5.3 6.1 9.1 11.6 9.1h24.7c5.5 0 10.3-3.7 11.6-9.1 20.8-81.9 30.2-119 34.5-136 1.9-7.6-3.8-14.9-11.6-14.9h-15.8z" /></svg>
|
|
}
|
|
|
|
if (fileType === 'powerpoint') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} {...props} viewBox="0 0 384 512"><path d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm72-60V236c0-6.6 5.4-12 12-12h69.2c36.7 0 62.8 27 62.8 66.3 0 74.3-68.7 66.5-95.5 66.5V404c0 6.6-5.4 12-12 12H132c-6.6 0-12-5.4-12-12zm48.5-87.4h23c7.9 0 13.9-2.4 18.1-7.2 8.5-9.8 8.4-28.5 .1-37.8-4.1-4.6-9.9-7-17.4-7h-23.9v52z" /></svg>
|
|
}
|
|
|
|
if (fileType === 'audio') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" width={size} height={size} {...props}><path d="M369.9 97.9l-83.9-83.9A48 48 0 0 0 252.1 0H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9a48 48 0 0 0 -14.1-33.9zM332.1 128H256V51.9L332.1 128zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm144-76c0 10.7-12.9 16-20.5 8.5L136 360.5h-28c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h28l35.5-36.9c7.6-7.6 20.5-2.2 20.5 8.5v136zm41.2-47.1c9.1-9.3 9.1-24.1 0-33.4-22.1-22.8 12.2-56.2 34.4-33.5 27.2 27.9 27.2 72.4 0 100.4-21.8 22.4-56.9-10.3-34.4-33.5z" /></svg>
|
|
}
|
|
|
|
if (fileType === 'file') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} {...props} viewBox="0 0 384 512"><path d="M288 248v28c0 6.6-5.4 12-12 12H108c-6.6 0-12-5.4-12-12v-28c0-6.6 5.4-12 12-12h168c6.6 0 12 5.4 12 12zm-12 72H108c-6.6 0-12 5.4-12 12v28c0 6.6 5.4 12 12 12h168c6.6 0 12-5.4 12-12v-28c0-6.6-5.4-12-12-12zm108-188.1V464c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V48C0 21.5 21.5 0 48 0h204.1C264.8 0 277 5.1 286 14.1L369.9 98c9 8.9 14.1 21.2 14.1 33.9zm-128-80V128h76.1L256 51.9zM336 464V176H232c-13.3 0-24-10.7-24-24V48H48v416h288z" /></svg>
|
|
}
|
|
|
|
if (fileType === 'video') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} {...props} viewBox="0 0 384 512"><path d="M369.9 97.9l-83.9-83.9A48 48 0 0 0 252.1 0H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9a48 48 0 0 0 -14.1-33.9zM332.1 128H256V51.9L332.1 128zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm228.7-211.3L224 305.4V268c0-11-9-20-20-20H100c-11 0-20 9-20 20v104c0 11 9 20 20 20h104c11 0 20-9 20-20v-37.4l52.7 52.7C286.7 397.3 304 390.3 304 376V264c0-14.3-17.3-21.3-27.3-11.3z" /></svg>
|
|
}
|
|
|
|
if (fileType === 'image') {
|
|
return <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} {...props} viewBox="0 0 384 512"><path d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm32-48h224V288l-23.5-23.5c-4.7-4.7-12.3-4.7-17 0L176 352l-39.5-39.5c-4.7-4.7-12.3-4.7-17 0L80 352v64zm48-240c-26.5 0-48 21.5-48 48s21.5 48 48 48 48-21.5 48-48-21.5-48-48-48z" /></svg>
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export default FileExtensionIcon |