-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6350486
commit 4db6bd3
Showing
2 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Typography, Box } from '@mui/material'; | ||
import CloudUploadIcon from '@mui/icons-material/CloudUpload'; | ||
|
||
export default function FileUpload({ onFileSelect, label }) { | ||
const [fileName, setFileName] = useState(''); | ||
|
||
const handleFileChange = (event) => { | ||
const selectedFile = event.target.files[0]; | ||
setFileName(selectedFile ? selectedFile.name : ''); | ||
if (onFileSelect) { | ||
onFileSelect(selectedFile); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, margin: '10px 0' }}> | ||
<input | ||
accept="*/*" | ||
style={{ display: 'none' }} | ||
id={`contained-button-file-${label}`} | ||
type="file" | ||
onChange={handleFileChange} | ||
/> | ||
<label htmlFor={`contained-button-file-${label}`}> | ||
<Button variant="contained" component="span" startIcon={<CloudUploadIcon />}> | ||
{label || 'Select File'} | ||
</Button> | ||
</label> | ||
<Typography variant="body2" noWrap> | ||
{fileName ? `Selected file: ${fileName}` : '선택된 파일이 없습니다.'} | ||
</Typography> | ||
</Box> | ||
); | ||
} |