fix: file form fix
parent
ee132cbdbb
commit
cecc51f29a
@ -0,0 +1,46 @@
|
||||
import * as React from 'react';
|
||||
import { Button, Grid, InputAdornment, TextField } from '@mui/material';
|
||||
import { FileDownload, FileUpload } from '@mui/icons-material';
|
||||
|
||||
const FileForm = ({ isDownload = false, labelName, selectedFile, handleChangeFile, handleFileDownload, alert }) => {
|
||||
const onChangeFile = (e) => {
|
||||
const file = e.target.files[0];
|
||||
if (file.type.includes('image')) {
|
||||
alert.show(<img alt={`${file.name}`} src={URL.createObjectURL(file)} style={{ margin: 'auto' }} />);
|
||||
}
|
||||
handleChangeFile(file);
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container item spacing={0.5}>
|
||||
<Grid item sm={7.5}>
|
||||
{isDownload ? (
|
||||
<TextField
|
||||
placeholder={labelName}
|
||||
value={selectedFile}
|
||||
size="small"
|
||||
InputProps={{
|
||||
display: 'none',
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<FileDownload stroke={1.5} size="1rem" cursor="pointer" />
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
onClick={handleFileDownload}
|
||||
/>
|
||||
) : (
|
||||
<TextField placeholder={labelName} value={selectedFile} size="small" />
|
||||
)}
|
||||
</Grid>
|
||||
<Grid item sm={4.5}>
|
||||
<Button variant="contained" component="label" color="primary" size="small" startIcon={<FileUpload />}>
|
||||
파일 업로드
|
||||
<input type="file" hidden onChange={onChangeFile} />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
|
||||
export default FileForm;
|
Loading…
Reference in New Issue