-
-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathFileInput.tsx
More file actions
47 lines (40 loc) · 1.1 KB
/
FileInput.tsx
File metadata and controls
47 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { useState } from "react";
function FileInput({ value, FileContent, ...rest }) {
const [filePresent, setFilePresent] = useState(false);
const [Files, setFiles] = useState([]);
function noop(filePresent) {
setFilePresent(true);
}
return (
<div>
<label
className="wrapper"
style={{
width: "50px",
background: "#fff",
padding: "30px",
boxShadow:
"0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)"
}}
>
Click to here to select file for upload...
<input
{...rest}
style={{ display: "none" }}
type="file"
onChange={(e) => {
setFiles([...e.target.files]);
FileContent(e.target.files);
setFilePresent(true);
}}
/>
</label>
{Boolean(filePresent) && (
<div style={{ marginTop: "40px", marginBottom: "10px" }}>
Selected files: {Files.map((f) => f.name).join(", ")}
</div>
)}
</div>
);
}
export default FileInput;