import React from 'react'; import { useTransition } from 'react-spring'; import { Img, ImgProgress, OverLay, PicWrap, PlusIcon, Preview, ProgressClose, ProgressTips, Remove, Span, UploadBtn, UploadedPic, AnimatedWrap, } from '../style'; type IProps = { state: any; onRemove: (index: number, isLoading: boolean) => void; maxUpload: number; fileInput: any; }; const Component = function({ state, onRemove, maxUpload, fileInput }: IProps) { const transitions = useTransition(state.files, k => k.uid, { from: { width: 0, height: 0 }, leave: { width: 0, height: 0 }, enter: { width: 100, height: 100 }, config: { tension: 300, clamp: true, }, }); return ( {transitions.map(({ item, props, key }, index) => ( {(item.isLoading || item.isError) && ( <> {item.isError ? '上传失败' : '文件上传中'} { onRemove(index, item.isLoading); }} /> )} {!item.isLoading && !item.isError && } {!item.isLoading && !item.isError && (
{ onRemove(index, item.isLoading); }} />
)}
))} {state.files.length < maxUpload && ( (fileInput.current as HTMLInputElement).click()}> 上传图片 )}
); }; export default Component;