File tree Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @matechat/react " : patch:feat
3
+ ---
4
+
5
+ Add ` FileUpload ` component for file selections.
Original file line number Diff line number Diff line change
1
+ import clsx from "clsx" ;
2
+ import type React from "react" ;
3
+ import { useRef } from "react" ;
4
+ import { twMerge } from "tailwind-merge" ;
5
+ import Appendix from "./icons/appendix.svg" ;
6
+
7
+ export interface FileUploadProps extends React . ComponentProps < "button" > {
8
+ onFilesSelect : ( files : File [ ] ) => void ;
9
+ }
10
+
11
+ export function FileUpload ( {
12
+ className,
13
+ onFilesSelect,
14
+ ...props
15
+ } : FileUploadProps ) {
16
+ const fileInputRef = useRef < HTMLInputElement > ( null ) ;
17
+ const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
18
+ const files = Array . from ( e . target . files ?? [ ] ) ;
19
+ onFilesSelect ( files ) ;
20
+ if ( fileInputRef . current ) fileInputRef . current . value = "" ;
21
+ } ;
22
+
23
+ return (
24
+ < button
25
+ data-slot = "file-upload"
26
+ type = "button"
27
+ className = { twMerge (
28
+ clsx ( "cursor-pointer text-gray-500 hover:text-gray-500/80" , className ) ,
29
+ ) }
30
+ onClick = { ( ) => fileInputRef . current ?. click ( ) }
31
+ { ...props }
32
+ >
33
+ < img
34
+ src = { Appendix }
35
+ alt = "upload"
36
+ className = "w-5 h-5 dark:filter dark:filter-invert hover:scale-105"
37
+ />
38
+ < input
39
+ type = "file"
40
+ className = "hidden"
41
+ ref = { fileInputRef }
42
+ onChange = { handleChange }
43
+ multiple
44
+ />
45
+ </ button >
46
+ ) ;
47
+ }
Original file line number Diff line number Diff line change 1
1
export * from "./bubble" ;
2
2
export * from "./button" ;
3
+ export * from "./file-upload" ;
3
4
export * from "./list" ;
4
5
export * from "./prompt" ;
5
6
export * from "./sender" ;
You can’t perform that action at this time.
0 commit comments