import React from "react"; import { FileItem } from '../upload/interface'; import Image from '../image'; import { IconAlertCircle, IconBriefStroked, IconClear } from '@douyinfe/semi-icons'; import { strings, cssClasses } from '@douyinfe/semi-foundation/chat/constants'; import cls from 'classnames'; import { Progress } from "../index"; const { PREFIX_ATTACHMENT, } = cssClasses; const { PIC_SUFFIX_ARRAY, PIC_PREFIX } = strings; interface AttachmentProps { className?: string; attachment?: FileItem[]; onClear?: (item: FileItem) => void; showClear?: boolean } interface FileItemProps { url?: string; name?: string; size?: string; type?: string } export const FileAttachment = React.memo((props: FileItemProps) => { const { url, name, size, type } = props; return
{name} {type} {type ? ' ยท ' : ''}{size}
; }); export const ImageAttachment = React.memo((props: {src: string}) => { const { src } = props; return ; }); const Attachment = React.memo((props: AttachmentProps) => { const { attachment, onClear, showClear = true, className } = props; return (
{ attachment.map(item => { const { percent, status } = item; const suffix = item?.name.split('.').pop(); const isImg = item?.fileInstance?.type?.startsWith(PIC_PREFIX) || PIC_SUFFIX_ARRAY.includes(suffix); const realType = suffix ?? item?.fileInstance?.type?.split('/').pop(); const showProcess = !(percent === 100 || typeof percent === 'undefined') && status === strings.FILE_STATUS.UPLOADING; return
{isImg ? ( ) : ( )} {showClear && { onClear && onClear(item); }} />} {showProcess && } {[strings.FILE_STATUS.UPLOAD_FAIL, strings.FILE_STATUS.VALID_FAIL].includes(status) && }
; }) }
); }); export default Attachment;