import { UploadOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Tooltip, Upload, message } from 'antd'; import React from 'react'; import { convertFileSize } from '../../utils'; interface UploadAudioProps { accept?: string; maxCount?: number; type?: 'text' | 'primary' | 'default'; icon?: React.ReactNode; size?: 'small' | 'middle' | 'large'; shape?: 'circle' | 'round' | 'default'; maxFileSize?: number; // in bytes onChange?: (data: { file: any; fileList: any[] }) => void; } const UploadAudio: React.FC = (props) => { const [messageApi, contextHolder] = message.useMessage(); const { icon, accept, type, size = 'large', shape = 'circle' } = props; const intl = useIntl(); const beforeUpload = (file: any) => { return false; }; const isFileSizeValid = (file: File) => { if (props.maxFileSize && file.size > props.maxFileSize) { messageApi.open({ type: 'warning', content: intl.formatMessage( { id: 'playground.uploadfile.sizeError' }, { size: `${convertFileSize(props.maxFileSize)}` } // Convert bytes to MB ) }); return false; } return true; }; const handleOnChange = (data: { file: any; fileList: any }) => { if (!isFileSizeValid(data.file)) { return; } props.onChange?.(data); }; return (
{contextHolder}
); }; export default UploadAudio;