Skip to content

Commit bec8be4

Browse files
authored
Add folder icon option for the file input (#1536)
2 parents ac7f809 + e9b3efe commit bec8be4

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

gui/src/components/commons/FileInput.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { FileIcon } from './icon/FileIcon';
1212
import { UploadFileIcon } from './icon/UploadFileIcon';
1313
import { Typography } from './Typography';
1414
import { CloseIcon } from './icon/CloseIcon';
15+
import { FolderIcon } from './icon/FolderIcon';
16+
import { UploadFolderIcon } from './icon/UploadFolderIcon';
1517

1618
interface InputProps {
1719
variant?: 'primary' | 'secondary';
@@ -22,9 +24,11 @@ interface InputProps {
2224
export const FileInputContentBlank = ({
2325
isDragging,
2426
label,
27+
directory = false,
2528
}: {
2629
isDragging: boolean;
2730
label: string;
31+
directory?: boolean;
2832
}) => {
2933
return (
3034
<div
@@ -36,7 +40,11 @@ export const FileInputContentBlank = ({
3640
)}
3741
>
3842
<span className="flex items-center space-x-2 pointer-events-none">
39-
<UploadFileIcon isDragging={isDragging} />
43+
{directory ? (
44+
<UploadFolderIcon isDragging={isDragging} />
45+
) : (
46+
<UploadFileIcon isDragging={isDragging} />
47+
)}
4048
<div>
4149
<Localized
4250
id={label}
@@ -57,10 +65,12 @@ export const FileInputContentBlank = ({
5765

5866
export const FileInputContentFile = ({
5967
importedFileName,
68+
directory = false,
6069
onClearPicker,
6170
}: {
6271
importedFileName: string;
6372
onClearPicker: () => any;
73+
directory?: boolean;
6474
}) => {
6575
return (
6676
<div
@@ -72,7 +82,7 @@ export const FileInputContentFile = ({
7282
>
7383
<div className="flex items-center space-x-2">
7484
<div className="flex items-center space-x-2 px-4">
75-
<FileIcon />
85+
{directory ? <FolderIcon /> : <FileIcon />}
7686
<span>{importedFileName}</span>
7787
</div>
7888
<span className="flex-grow"></span>

gui/src/components/commons/TauriFileInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ export function InnerTauriFileInput({
2424
<div ref={ref} onClick={async () => onChange(await open({ directory }))}>
2525
{value !== null
2626
? FileInputContentFile({
27+
directory,
2728
importedFileName: value,
2829
onClearPicker: () => onChange(null),
2930
})
30-
: FileInputContentBlank({ isDragging: false, label })}
31+
: FileInputContentBlank({ isDragging: false, label, directory })}
3132
</div>
3233
);
3334
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function FolderIcon({ width = 24 }: { width?: number }) {
2+
return (
3+
<svg
4+
xmlns="http://www.w3.org/2000/svg"
5+
viewBox="0 0 24 24"
6+
fill="currentColor"
7+
width={width}
8+
>
9+
<path d="M19.5 21a3 3 0 0 0 3-3v-4.5a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3V18a3 3 0 0 0 3 3h15ZM1.5 10.146V6a3 3 0 0 1 3-3h5.379a2.25 2.25 0 0 1 1.59.659l2.122 2.121c.14.141.331.22.53.22H19.5a3 3 0 0 1 3 3v1.146A4.483 4.483 0 0 0 19.5 9h-15a4.483 4.483 0 0 0-3 1.146Z" />
10+
</svg>
11+
);
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import classNames from 'classnames';
2+
3+
export function UploadFolderIcon({
4+
width = 24,
5+
isDragging = false,
6+
}: {
7+
width?: number;
8+
isDragging?: boolean;
9+
}) {
10+
return (
11+
<svg
12+
xmlns="http://www.w3.org/2000/svg"
13+
viewBox="0 0 5.5499997 4.7600007"
14+
width={width}
15+
fill="currentColor"
16+
className={classNames('transition-transform', isDragging && 'scale-150')}
17+
>
18+
<path
19+
fill-rule="evenodd"
20+
d="m 4.76,4.76 c 0.44,0 0.79,-0.36 0.79,-0.79 v -2.39 c 0,-0.44 -0.36,-0.79 -0.79,-0.79 H 3.34 c -0.05,0 -0.1,-0.02 -0.14,-0.06 L 2.64,0.17 C 2.53,0.06 2.38,0 2.22,0 H 0.79 C 0.35,0 0,0.36 0,0.79 V 3.97 C 0,4.41 0.36,4.76 0.79,4.76 Z M 2.58,3.71 c 0,0.26 0.4,0.26 0.4,0 V 2.6 L 3.44,3.06 C 3.63,3.23 3.89,2.97 3.72,2.78 L 2.93,1.99 c -0.08,-0.08 -0.2,-0.08 -0.28,0 L 1.86,2.78 C 1.65,2.97 1.95,3.26 2.14,3.06 L 2.6,2.6 Z"
21+
clip-rule="evenodd"
22+
/>
23+
</svg>
24+
);
25+
}

0 commit comments

Comments
 (0)