1
1
import React , { useCallback , useState } from 'react' ;
2
- import { FileUploadIcon } from '@/public/icons' ;
2
+ import { ImageFileIcon , PdfFileIcon } from '@/public/icons' ;
3
3
import { FileItem } from '@/components/common/FileUpload/FileItem' ;
4
4
import { styled } from '@/stitches.config' ;
5
5
6
6
const StyledFileUpload = styled ( 'div' , {
7
7
width : '100%' ,
8
- height : '180px ' ,
8
+ height : '100px ' ,
9
9
backgroundColor : '$backgroundPrimary' ,
10
10
border : '2px solid $textPrimary' ,
11
11
} ) ;
@@ -37,7 +37,16 @@ const FileItemLabel = styled('label', {
37
37
padding : 24 ,
38
38
} ) ;
39
39
40
- const StyledFileUploadIcon = styled ( FileUploadIcon , {
40
+ const StyledPdfFileIcon = styled ( PdfFileIcon , {
41
+ width : '24px' ,
42
+ height : '24px' ,
43
+
44
+ '& path' : {
45
+ fill : '$textPrimary' ,
46
+ } ,
47
+ } ) ;
48
+
49
+ const StyledImageFileIcon = styled ( ImageFileIcon , {
41
50
width : '24px' ,
42
51
height : '24px' ,
43
52
@@ -48,14 +57,21 @@ const StyledFileUploadIcon = styled(FileUploadIcon, {
48
57
49
58
interface FileUploadProps {
50
59
labelText : string ;
60
+ fileType : 'pdf' | 'image' ;
51
61
onFileUpload : ( file : FileList ) => void ;
52
62
}
53
63
54
64
type FileUploadType = React . InputHTMLAttributes < HTMLInputElement > &
55
65
FileUploadProps ;
56
66
67
+ const fileTypeList = {
68
+ pdf : { icon : < StyledPdfFileIcon /> , accept : '.pdf' } ,
69
+ image : { icon : < StyledImageFileIcon /> , accept : 'image/png, image/jpg' } ,
70
+ } ;
71
+
57
72
export const FileUpload = ( {
58
73
labelText,
74
+ fileType,
59
75
onFileUpload,
60
76
...props
61
77
} : FileUploadType ) => {
@@ -122,6 +138,9 @@ export const FileUpload = ({
122
138
id = { fileInputId }
123
139
type = "file"
124
140
onChange = { handleFileUpload }
141
+ multiple
142
+ accept = { fileTypeList [ fileType ] . accept }
143
+ required
125
144
{ ...props }
126
145
/>
127
146
{ uploadedFiles ?. length ? (
@@ -130,6 +149,7 @@ export const FileUpload = ({
130
149
< FileItem
131
150
key = { file . name }
132
151
file = { file }
152
+ fileType = { fileType }
133
153
onRemove = { ( e ) => handleFileRemove ( e , index ) }
134
154
/>
135
155
) ) }
@@ -140,7 +160,7 @@ export const FileUpload = ({
140
160
onDragOver = { stopSyntheticEvent }
141
161
onDrop = { handleDrop }
142
162
>
143
- < StyledFileUploadIcon />
163
+ { fileTypeList [ fileType ] . icon }
144
164
{ labelText }
145
165
</ FileUploadLabel >
146
166
) }
0 commit comments