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 className="hidden" ref={inputRef} onInput={()=>{
				if (inputRef.current && inputRef.current.files){
					props.onUpload?.(inputRef.current.files)
				}
			}}/>
		</>
	)
}

export default FileUploadButton
