Skip to content

Commit 5121d5b

Browse files
authored
Merge branch 'main' into da/flow
2 parents a6bf47c + 53efd95 commit 5121d5b

File tree

6 files changed

+67
-22
lines changed

6 files changed

+67
-22
lines changed

src/assets/icons/icon-file-jpg.svg

Lines changed: 6 additions & 0 deletions
Loading

src/assets/icons/icon-file-pdf.svg

Lines changed: 6 additions & 0 deletions
Loading

src/assets/icons/icon-file-png.svg

Lines changed: 6 additions & 0 deletions
Loading

src/assets/icons/icon-trashcan.svg

Lines changed: 3 additions & 0 deletions
Loading

src/components/Common/UI/FileInput/FileInput.module.scss

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
width: 100%;
1515
background: transparent;
1616
border: none;
17+
border-radius: var(--g-inputRadius);
1718
font-size: var(--g-fontSizeSmall);
1819
padding: toRem(16) toRem(8);
1920

@@ -49,6 +50,13 @@
4950
font-weight: var(--g-fontWeightBold);
5051
}
5152

53+
.hintContainer {
54+
display: flex;
55+
flex-direction: column;
56+
margin-top: toRem(6);
57+
gap: toRem(6);
58+
}
59+
5260
.hint {
5361
color: var(--g-colorBodySubContent);
5462
}
@@ -66,11 +74,11 @@
6674
display: flex;
6775
align-items: center;
6876
justify-content: center;
69-
flex-basis: toRem(24);
77+
flex-basis: toRem(40);
7078

7179
svg {
72-
width: toRem(24);
73-
height: toRem(24);
80+
width: toRem(40);
81+
height: toRem(40);
7482
color: var(--g-colorPrimaryAccent);
7583
}
7684
}

src/components/Common/UI/FileInput/FileInput.tsx

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,27 @@ import { applyMissingDefaults } from '@/helpers/applyMissingDefaults'
1515
import { FieldLayout } from '@/components/Common/FieldLayout'
1616
import { Flex } from '@/components/Common/Flex'
1717
import { 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'
1919
import 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

2140
function 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

5060
function 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

Comments
 (0)