import CancelIcon from '@mui/icons-material/Cancel'; import CloudUploadIcon from '@mui/icons-material/CloudUpload'; import { Box, Button, LinearProgress, Typography, useTheme } from '@mui/material'; import { Fragment } from 'react'; import { useDropzone } from 'react-dropzone'; import type { Theme } from '@mui/material'; import type { Progress } from 'alova'; import type { FC } from 'react'; import type { DropzoneState } from 'react-dropzone'; import { useI18nContext } from 'i18n/i18n-react'; const getBorderColor = (theme: Theme, props: DropzoneState) => { if (props.isDragAccept) { return theme.palette.success.main; } if (props.isDragReject) { return theme.palette.error.main; } if (props.isDragActive) { return theme.palette.info.main; } return theme.palette.grey[700]; }; export interface SingleUploadProps { onDrop: (acceptedFiles: File[]) => void; onCancel: () => void; isUploading: boolean; progress: Progress; } const SingleUpload: FC = ({ onDrop, onCancel, isUploading, progress }) => { const uploading = isUploading && progress.total > 0; const dropzoneState = useDropzone({ onDrop, accept: { 'application/octet-stream': ['.bin'], 'application/json': ['.json'], 'text/plain': ['.md5'] }, disabled: isUploading, multiple: false }); const { getRootProps, getInputProps } = dropzoneState; const theme = useTheme(); const { LL } = useI18nContext(); const progressText = () => { if (uploading) { if (progress.total) { return LL.UPLOADING() + ': ' + Math.round((progress.loaded * 100) / progress.total) + '%'; } } return LL.UPLOAD_DROP_TEXT(); }; return ( {progressText()} {uploading && ( )} ); }; export default SingleUpload;