From 003535048709b3952e54ae54caee819aca4c6d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=BC=A6=E8=AF=AD?= Date: Sun, 29 Jun 2025 21:41:43 +0800 Subject: [PATCH 1/3] feat(file-upload): add file-upload component --- src/file-upload.tsx | 41 +++++++++++++++++++++++++++++++++++++++++ src/index.ts | 1 + 2 files changed, 42 insertions(+) create mode 100644 src/file-upload.tsx diff --git a/src/file-upload.tsx b/src/file-upload.tsx new file mode 100644 index 0000000..cba53cf --- /dev/null +++ b/src/file-upload.tsx @@ -0,0 +1,41 @@ +import clsx from "clsx"; +import type React from "react"; +import { useRef } from "react"; +import { twMerge } from "tailwind-merge"; + +export interface FileUploadProps extends React.ComponentProps<"button"> { + onFilesSelect: (files: File[]) => void; +} + +export function FileUpload({ + className, + onFilesSelect, + ...props +}: FileUploadProps) { + const fileInputRef = useRef(null); + const handleChange = (e: React.ChangeEvent) => { + const files = Array.from(e.target.files ?? []); + onFilesSelect(files); + if (fileInputRef.current) fileInputRef.current.value = ""; + }; + + return ( + + ); +} diff --git a/src/index.ts b/src/index.ts index 34a7e78..e4e1636 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from "./bubble"; export * from "./button"; +export * from "./file-upload"; export * from "./list"; export * from "./prompt"; export * from "./sender"; From 346135f2c592994d1add976b9d592078587b8ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=BC=A6=E8=AF=AD?= Date: Sun, 29 Jun 2025 21:51:50 +0800 Subject: [PATCH 2/3] feat(file-upload): use svg icon instead of text --- src/file-upload.tsx | 8 +++++++- src/icons/appendix.svg | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/icons/appendix.svg diff --git a/src/file-upload.tsx b/src/file-upload.tsx index cba53cf..08d5c96 100644 --- a/src/file-upload.tsx +++ b/src/file-upload.tsx @@ -2,6 +2,7 @@ import clsx from "clsx"; import type React from "react"; import { useRef } from "react"; import { twMerge } from "tailwind-merge"; +import Appendix from "./icons/appendix.svg"; export interface FileUploadProps extends React.ComponentProps<"button"> { onFilesSelect: (files: File[]) => void; @@ -21,6 +22,7 @@ export function FileUpload({ return (