파일업로드 작업
This commit is contained in:
@@ -12,10 +12,12 @@ const dropZoneConfig = {
|
||||
files: File[]; // 파일 배열
|
||||
setFiles: (files: File[] | null) => void; // 파일 배열 세터
|
||||
fileTypes?: string; // 옵션 (파일 확장자 문자열)
|
||||
onFileClick?:(index:number)=> void; // 파일 클릭 핸들러
|
||||
|
||||
}
|
||||
|
||||
export const FileUpload =
|
||||
({ files, setFiles, fileTypes }: FileUploadProps) => {
|
||||
({ files, setFiles, fileTypes ,onFileClick}: FileUploadProps) => {
|
||||
return (
|
||||
<FileUploader
|
||||
value={files}
|
||||
@@ -43,9 +45,9 @@ export const FileUpload =
|
||||
{files&&
|
||||
files.length > 0 &&
|
||||
files.map((file:File, i:number) => (
|
||||
<FileUploaderItem key={i} index={i}>
|
||||
<FileUploaderItem key={i} index={i} onFileClick={onFileClick }>
|
||||
<Paperclip className="h-4 w-4 stroke-current" />
|
||||
<span>{file.name}</span>
|
||||
<span className="w-4/5 overflow-hidden">{file.name}</span>
|
||||
</FileUploaderItem>
|
||||
))}
|
||||
</FileUploaderContent>
|
||||
|
||||
@@ -286,9 +286,9 @@ FileUploaderContent.displayName = "FileUploaderContent";
|
||||
|
||||
export const FileUploaderItem = forwardRef<
|
||||
HTMLDivElement,
|
||||
{ index: number } & React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, index, children, ...props }, ref) => {
|
||||
const { removeFileFromSet, activeIndex, direction } = useFileUpload();
|
||||
{ index: number } & React.HTMLAttributes<HTMLDivElement> &{onFileClick?:(index:number)=>void}
|
||||
>(({ className, index, children, onFileClick, ...props }, ref) => {
|
||||
const { removeFileFromSet , activeIndex, direction } = useFileUpload();
|
||||
const isSelected = index === activeIndex;
|
||||
return (
|
||||
<div
|
||||
@@ -300,8 +300,13 @@ export const FileUploaderItem = forwardRef<
|
||||
isSelected ? "bg-muted" : "",
|
||||
)}
|
||||
{...props}
|
||||
|
||||
>
|
||||
<div className="font-medium leading-none tracking-tight flex items-center gap-1.5 h-full w-full">
|
||||
<div className="font-medium leading-none tracking-tight flex items-center gap-1.5 h-full !w-4/5 overflow-hidden "
|
||||
onClick={() =>{
|
||||
|
||||
|
||||
}}>
|
||||
{children}
|
||||
</div>
|
||||
<button
|
||||
@@ -309,8 +314,10 @@ export const FileUploaderItem = forwardRef<
|
||||
className={cn(
|
||||
"absolute",
|
||||
direction === "rtl" ? "top-1 left-1" : "top-1 right-1",
|
||||
|
||||
)}
|
||||
onClick={() => removeFileFromSet(index)}
|
||||
onClick={() =>{
|
||||
removeFileFromSet(index)}}
|
||||
>
|
||||
<span className="sr-only">remove item {index}</span>
|
||||
<RemoveIcon className="w-4 h-4 hover:stroke-destructive duration-200 ease-in-out" />
|
||||
|
||||
Reference in New Issue
Block a user