-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
5 changed files
with
189 additions
and
189 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
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 |
---|---|---|
@@ -1,51 +1,49 @@ | ||
import React, {useEffect, useRef, useState} from 'react'; | ||
import { Button, Input } from '@mui/material'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { Input } from '@mui/material'; | ||
|
||
/** | ||
* File Upload Component | ||
* @author vadim.chilinciuc | ||
* | ||
*/ | ||
|
||
function FileUpload({ onChange, value }: any) { | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
const [selectedFile, setSelectedFile] = useState<any>(value); | ||
|
||
// Function to handle file selection | ||
const handleFileSelect = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const file = event.target.files && event.target.files[0]; | ||
setSelectedFile(file); | ||
|
||
if (onChange) { | ||
onChange(file); | ||
} | ||
}; | ||
|
||
if(!value){ | ||
if (inputRef.current) { | ||
inputRef.current.value = ''; | ||
} | ||
} | ||
|
||
|
||
|
||
useEffect(() => { | ||
inputRef.current = document.querySelector("#file-input"); | ||
|
||
}, []); | ||
|
||
|
||
|
||
return ( | ||
<div> | ||
<Input | ||
type="file" | ||
onChange={handleFileSelect} | ||
style={{ border: '1px solid black' }} | ||
id="file-input" | ||
/> | ||
</div> | ||
); | ||
export interface FileUploadProps { | ||
value?: File; | ||
onChange?: (e: any) => void; | ||
} | ||
|
||
export default FileUpload; | ||
export function FileUpload({ onChange, value }: FileUploadProps) { | ||
const inputRef = useRef<HTMLInputElement | null>(null); | ||
const [selectedFile, setSelectedFile] = useState<any>(value); | ||
|
||
// Function to handle file selection | ||
const handleFileSelect = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const file = event.target.files && event.target.files[0]; | ||
setSelectedFile(file); | ||
|
||
if (onChange) { | ||
onChange(file); | ||
} | ||
}; | ||
|
||
if (!value) { | ||
if (inputRef.current) { | ||
inputRef.current.value = ''; | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
inputRef.current = document.querySelector('#file-input'); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<Input | ||
type="file" | ||
onChange={handleFileSelect} | ||
disableUnderline | ||
id="file-input" | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.