Overview
TheFileList component displays all selected files in a formatted list with file metadata, icons, and removal options. It provides users with a clear overview of files queued for conversion and allows individual file removal or clearing all files at once.
Key Features
- File type-specific icons
- File size formatting (B, KB, MB, GB)
- Individual file removal
- Clear all files option
- Automatic hiding when no files selected
Props
Array of File objects to display in the list.
Callback function triggered when a user clicks the remove button on a file. Receives the file index as a parameter.
Callback function triggered when the user clicks the βClear allβ button to remove all files.
Usage Example
File Type Icons
The component automatically displays appropriate icons based on file extensions:| File Type | Extension(s) | Icon |
|---|---|---|
.pdf | π | |
| Word | .docx, .doc | π |
| PowerPoint | .pptx, .ppt | π |
| Excel | .xlsx, .xls | π |
| Image | .png, .jpg, .jpeg, .gif | πΌοΈ |
| Text | .txt | π |
| HTML | .html | π |
| JSON | .json | π |
| Other | Any other | π |
Component Behavior
Empty State
Whenfiles array is empty, the component returns null and renders nothing. This automatically hides the file list when no files are selected.
File Display
Each file item shows:- Icon: Type-specific emoji based on file extension
- File name: Full filename as provided
- File size: Formatted size with appropriate unit (B, KB, MB, GB)
- Status: βReadyβ indicator
- Remove button: β icon to remove individual file
Header Actions
The file list header includes:- Title: βSelected filesβ
- Clear all button: Removes all files at once
Integration with Hooks
TheFileList component works with the useFileUpload hook:
Styling & Customization
The component uses CSS classes fromFileList.css:
.filelist-card- Main container.file-list-header- Header with title and clear button.selected-files- Container for file items.file-item- Individual file row.file-icon- File type icon.file-details- File name and size container.remove-file-btn- Individual remove button.clear-all-btn- Clear all button
Helper Functions
getFileIcon
Determines the appropriate emoji icon based on file extension:formatFileSize
Converts bytes to human-readable format:1024bytes β"1 KB"1536000bytes β"1.5 MB"500bytes β"500 B"
Implementation Details
Source Code Location
~/workspace/source/src/components/FileList/FileList.tsx:48-84
TypeScript Interface
Key Implementation Notes
- Component returns
nullwhen file array is empty (conditional rendering) - Uses array index as key for file items (suitable since order is stable)
- File size calculated from
file.sizeproperty (bytes) - File extension extracted using string split on filename