-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFileUpload.tsx
More file actions
101 lines (95 loc) · 2.35 KB
/
Copy pathFileUpload.tsx
File metadata and controls
101 lines (95 loc) · 2.35 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React, { useState } from 'react';
import styled from 'styled-components';
/*
interface FileUploadProps{
handleFileUpload: (value: string) => void;
}
*/
const FileUpload = ({
name,
multiple,
handleFileUpload,
}: {
name: string;
multiple: boolean;
handleFileUpload: (value:File) => void;
}) => {
const FileInput = styled.input`
opacity: 0;
position: absolute;
z-index: -1;
`;
const Label = styled.label`
display: grid;
padding: 20px 10px;
cursor: pointer;
font-family: IBM Plex Sans;
font-style: normal;
font-size: 24px;
line-height: 140%;
text-align: center;
color: rgba(0, 0, 0, 0.5);
width: 100%;
border: 1.2px dashed #c4c4c4;
box-sizing: border-box;
border-radius: 6px;
background: #ffffff;
`;
let [fileName, setFileName] = useState("")
return (
<div>
<Label htmlFor="file">
<span>
<svg
width="24"
height="33"
viewBox="0 0 24 33"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M9.08325 32.75H14.9166V15.25H23.6666L11.9999 0.666687L0.333252 15.25H9.08325V32.75Z"
fill="black"
fillOpacity="0.4"
/>
</svg>
</span>
<span>
<svg
width="60"
height="27"
viewBox="0 0 60 27"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M53.3333 20.5H6.66659V0.083313H0.833252V20.5C0.833252 23.7171 3.4495 26.3333 6.66659 26.3333H53.3333C56.5503 26.3333 59.1666 23.7171 59.1666 20.5V0.083313H53.3333V20.5Z"
fill="black"
fillOpacity="0.4"
/>
</svg>
</span>
<p style={{ margin: 0 }}>
<strong>Choose a file</strong> or drag it here.
</p>
</Label>
<FileInput
id="file"
type="file"
name={name}
accept={'application/pdf'}
onChange={(e) => {
if(e.target.files != null){
// update file in state
handleFileUpload(e.target.files[0])
setFileName(e.target.files[0].name)
}
}
}
multiple={multiple}
/>
{fileName && <p>{fileName}</p>}
</div>
);
};
export default FileUpload;