-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInputExample.tsx
More file actions
52 lines (46 loc) · 1.49 KB
/
FileInputExample.tsx
File metadata and controls
52 lines (46 loc) · 1.49 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
import { useState } from "react";
import { FileInput, UploadedFile } from "../components/form/FileInput";
export function FileInputExample() {
const [profilePicture, setProfilePicture] = useState<UploadedFile | null>(
null
);
const [files, setFiles] = useState<UploadedFile[]>([]);
return (
<div className="p-8 space-y-4">
<h1 className="font-bold">All File inputs</h1>
<h2 className="text-lg font-bold">Single file</h2>
<FileInput.Root>
<FileInput.Dropzone className="h-[200px]">
<FileInput.Input
name="profilePicture"
files={profilePicture ? [profilePicture] : []}
onFilesChange={(f) => setProfilePicture(f[0])}
/>
<FileInput.Preview
visible={Boolean(profilePicture)}
onRemove={() => setProfilePicture(null)}
>
<FileInput.FilePreview file={profilePicture as UploadedFile} />
</FileInput.Preview>
</FileInput.Dropzone>
</FileInput.Root>
<h2 className="text-lg font-bold">Multiple files</h2>
<FileInput.Root>
<FileInput.Dropzone>
<FileInput.Input
name="photos"
files={files}
onFilesChange={setFiles}
/>
</FileInput.Dropzone>
<FileInput.List
files={files}
onFilesChange={setFiles}
onFileRemove={(file) => {
console.log("Removed file:", file);
}}
/>
</FileInput.Root>
</div>
);
}