added upload button

This commit is contained in:
Niklas 2021-08-15 17:27:06 +02:00
parent 4655f2f8c1
commit 4d85a419cc
2 changed files with 30 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import DragAndDrop from "./DragAndDrop"
import FileBrowserContextMenu, { Action, CONTEXT_MENU_DIR, CONTEXT_MENU_FILE } from "./FileBrowserContextMenu"
import FileBrowserElement from "./FileBrowserElement"
import FileOpen from "./FileOpen"
import FileUploadButton from "./FileUploadButton"
const FileBrowser: React.FC = () => {
const [path,setPath] = useState("/")
@ -80,6 +81,9 @@ const FileBrowser: React.FC = () => {
await handleDrop(files)
}}
>
<FileUploadButton
onUpload={(files)=>handleDrop(files)}
/>
<Breadcrum path={path} onDirClick={(newPath)=>{
setPath(newPath)
}}/>

View 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