@@ -15,8 +15,27 @@ import { applyMissingDefaults } from '@/helpers/applyMissingDefaults'
1515import { FieldLayout } from '@/components/Common/FieldLayout'
1616import { Flex } from '@/components/Common/Flex'
1717import { ButtonIcon } from '@/components/Common/UI/Button/ButtonIcon'
18- import TrashCanIcon from '@/assets/icons/trashcan.svg?react'
18+ import TrashCanIcon from '@/assets/icons/icon- trashcan.svg?react'
1919import FileIcon from '@/assets/icons/icon-file-outline.svg?react'
20+ import PdfIcon from '@/assets/icons/icon-file-pdf.svg?react'
21+ import PngIcon from '@/assets/icons/icon-file-png.svg?react'
22+ import JpgIcon from '@/assets/icons/icon-file-jpg.svg?react'
23+
24+ function getFileIcon ( mimeType : string ) {
25+ if ( mimeType === 'application/pdf' ) {
26+ return PdfIcon
27+ }
28+
29+ if ( mimeType === 'image/png' ) {
30+ return PngIcon
31+ }
32+
33+ if ( mimeType === 'image/jpeg' || mimeType === 'image/jpg' ) {
34+ return JpgIcon
35+ }
36+
37+ return FileIcon
38+ }
2039
2140function isFileDropItem ( item : DropItem ) : item is FileDropItem {
2241 return item . kind === 'file'
@@ -35,16 +54,7 @@ const mimeToExtension: Record<string, string> = {
3554 'image/jpeg' : 'JPG' ,
3655 'image/jpg' : 'JPG' ,
3756 'image/png' : 'PNG' ,
38- 'image/gif' : 'GIF' ,
39- 'image/webp' : 'WEBP' ,
40- 'image/svg+xml' : 'SVG' ,
4157 'application/pdf' : 'PDF' ,
42- 'application/msword' : 'DOC' ,
43- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' : 'DOCX' ,
44- 'application/vnd.ms-excel' : 'XLS' ,
45- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' : 'XLSX' ,
46- 'text/plain' : 'TXT' ,
47- 'text/csv' : 'CSV' ,
4858}
4959
5060function formatAcceptedTypes ( accept : string [ ] | undefined ) : string | null {
@@ -120,6 +130,8 @@ export function FileInput(rawProps: FileInputProps) {
120130 onChange ( null )
121131 }
122132
133+ const FileTypeIcon = value ? getFileIcon ( value . type ) : null
134+
123135 return (
124136 < FieldLayout
125137 label = { label }
@@ -143,7 +155,7 @@ export function FileInput(rawProps: FileInputProps) {
143155 >
144156 < Flex alignItems = "center" gap = { 12 } >
145157 < div className = { styles . fileIcon } >
146- < FileIcon aria-hidden = "true" />
158+ { FileTypeIcon && < FileTypeIcon aria-hidden = "true" /> }
147159 </ div >
148160 < div className = { styles . fileInfo } >
149161 < Flex flexDirection = "column" gap = { 0 } >
@@ -182,14 +194,18 @@ export function FileInput(rawProps: FileInputProps) {
182194 components = { { clickToUpload : < span className = { styles . clickToUpload } /> } }
183195 />
184196 </ span >
185- { formatAcceptedTypes ( accept ) && (
186- < span className = { styles . hint } >
187- { t ( 'fileInput.acceptedTypes' , { types : formatAcceptedTypes ( accept ) } ) }
188- </ span >
189- ) }
190- { description && (
191- < span id = { descriptionId } className = { styles . hint } >
192- { description }
197+ { ( formatAcceptedTypes ( accept ) || description ) && (
198+ < span className = { styles . hintContainer } >
199+ { formatAcceptedTypes ( accept ) && (
200+ < span className = { styles . hint } >
201+ { t ( 'fileInput.acceptedTypes' , { types : formatAcceptedTypes ( accept ) } ) }
202+ </ span >
203+ ) }
204+ { description && (
205+ < span id = { descriptionId } className = { styles . hint } >
206+ { description }
207+ </ span >
208+ ) }
193209 </ span >
194210 ) }
195211 </ span >
0 commit comments