-
Notifications
You must be signed in to change notification settings - Fork 16
feat(fe): make container and file upload component for TCManage page #3579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
5d459fb
fa21110
5be81a3
01bf392
316c742
ad6af10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| 'use client' | ||
|
|
||
| import { cn } from '@/libs/utils' | ||
| import InfoIconGray from '@/public/icons/info-icon-gray.svg' | ||
| import { useRef, useState } from 'react' | ||
|
|
||
| interface FileUploadProps { | ||
| primaryText: string | ||
| secondaryText: string | ||
| multiple?: boolean | ||
| onFilesChange: (files: File[]) => void | ||
| className?: string | ||
| } | ||
|
|
||
| export function FileUpload({ | ||
| primaryText, | ||
| secondaryText, | ||
| multiple = false, | ||
| onFilesChange, | ||
| className | ||
| }: FileUploadProps) { | ||
| const [files, setFiles] = useState<File[]>([]) | ||
| const inputRef = useRef<HTMLInputElement | null>(null) | ||
|
|
||
| const handleFiles = (incoming: FileList | null) => { | ||
| if (!incoming) { | ||
| return | ||
| } | ||
| const next = Array.from(incoming) | ||
| setFiles(next) | ||
| onFilesChange(next) | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| onClick={() => inputRef.current?.click()} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. div 요소에 onClick 이벤트를 사용하여 버튼처럼 동작하게 할 때는 웹 접근성(A11y)을 위해 role="button"과 tabIndex={0}, 그리고 키보드 이벤트 핸들러(onKeyDown)를 추가하여 키보드 사용자가 상호작용할 수 있도록 개선하는 것이 좋습니다. |
||
| onDragOver={(e) => e.preventDefault()} | ||
| onDrop={(e) => { | ||
| e.preventDefault() | ||
| handleFiles(e.dataTransfer.files) | ||
| }} | ||
| className={cn( | ||
| 'border-color-cool-neutral-80 bg-color-neutral-99 flex cursor-pointer flex-col items-center justify-center rounded-[12px] py-20', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TC 인풋 자동 생성처럼 border가 먼저 적용되면 피그마 디자인처럼 안 나오는 부분이 있어서 border는 빼고 컴포넌트화 한 뒤에, 사용할 때 border를 필요에 따라 추가해야 할 것 같아요!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확인 부탁드립니다! |
||
| className | ||
| )} | ||
| > | ||
| <input | ||
| ref={inputRef} | ||
| type="file" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| multiple={multiple} | ||
| className="hidden" | ||
| onChange={(e) => handleFiles(e.target.files)} | ||
| /> | ||
| {files.length === 0 ? ( | ||
| <div className="flex flex-col items-center gap-[10px]"> | ||
| <InfoIconGray className="mb-2" height={24} width={24} /> | ||
| <div className="text-body1_m_16 text-color-cool-neutral-50 whitespace-pre-wrap text-center"> | ||
| <p>{primaryText}</p> | ||
| <p>{secondaryText}</p> | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <ul className="flex flex-col items-center gap-1"> | ||
| {files.map((f) => ( | ||
| <li | ||
| key={f.name} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| className="text-sub4_sb_14 text-color-cool-neutral-30" | ||
| > | ||
| {f.name} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onDrop을 통해 여러 파일이 한꺼번에 들어올 수 있으므로, multiple 옵션이 false인 경우에는 첫 번째 파일만 선택되도록 로직을 보강하는 것이 안전합니다.