added upload button
This commit is contained in:
parent
4655f2f8c1
commit
4d85a419cc
@ -8,6 +8,7 @@ import DragAndDrop from "./DragAndDrop"
|
|||||||
import FileBrowserContextMenu, { Action, CONTEXT_MENU_DIR, CONTEXT_MENU_FILE } from "./FileBrowserContextMenu"
|
import FileBrowserContextMenu, { Action, CONTEXT_MENU_DIR, CONTEXT_MENU_FILE } from "./FileBrowserContextMenu"
|
||||||
import FileBrowserElement from "./FileBrowserElement"
|
import FileBrowserElement from "./FileBrowserElement"
|
||||||
import FileOpen from "./FileOpen"
|
import FileOpen from "./FileOpen"
|
||||||
|
import FileUploadButton from "./FileUploadButton"
|
||||||
|
|
||||||
const FileBrowser: React.FC = () => {
|
const FileBrowser: React.FC = () => {
|
||||||
const [path,setPath] = useState("/")
|
const [path,setPath] = useState("/")
|
||||||
@ -80,6 +81,9 @@ const FileBrowser: React.FC = () => {
|
|||||||
await handleDrop(files)
|
await handleDrop(files)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<FileUploadButton
|
||||||
|
onUpload={(files)=>handleDrop(files)}
|
||||||
|
/>
|
||||||
<Breadcrum path={path} onDirClick={(newPath)=>{
|
<Breadcrum path={path} onDirClick={(newPath)=>{
|
||||||
setPath(newPath)
|
setPath(newPath)
|
||||||
}}/>
|
}}/>
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user