added upload button
This commit is contained in:
26
src/components/FileUploadButton.tsx
Normal file
26
src/components/FileUploadButton.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from "react"
|
||||
import { useRef } from "react"
|
||||
|
||||
interface Props {
|
||||
onUpload?: (files: FileList)=>void
|
||||
}
|
||||
|
||||
const FileUploadButton: React.FC<Props> = (props) => {
|
||||
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
return (
|
||||
<>
|
||||
<button onClick={()=>inputRef.current?.click()} >
|
||||
Upload files
|
||||
</button>
|
||||
<input type="file" multiple style={{display:"none"}} ref={inputRef} onInput={()=>{
|
||||
if (inputRef.current && inputRef.current.files){
|
||||
props.onUpload?.(inputRef.current.files)
|
||||
}
|
||||
}}/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default FileUploadButton
|
||||
Reference in New Issue
Block a user