Sha256: ce4a3f3713a2c36015e25ed86391ba6138c4b2b41c355e38bca750f6f312223a
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
import { ChangeEvent, MouseEvent, useRef } from "react"; type Props = { callback: (files: File[]) => void; type?: string; multiline?: boolean; multiple?: boolean; }; export default function FileUploadButton(props: Props) { const inputRef = useRef<HTMLInputElement>(); const handleChange = (evt: ChangeEvent<HTMLInputElement>) => { const fileList = evt.target.files; const files: File[] = []; for (let i = 0; i < fileList.length; i++) { files.push(fileList[i]); } if (files.length > 0) { props.callback(files); } }; const triggerDialog = (evt: MouseEvent) => { evt.preventDefault(); inputRef.current.click(); }; return ( <div className="upload-button"> <span> Drag and drop {props.type || "file"} {props.multiple && "s"} here, or {props.multiline && <br />} <button onClick={triggerDialog}>choose a file</button> </span> <input type="file" onChange={handleChange} ref={inputRef} style={{ display: "none" }} multiple={props.multiple || false} /> </div> ); }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pages_core-3.15.5 | app/javascript/components/FileUploadButton.tsx |