AI Attachments Input
File upload component for providing context and reference materials to AI conversations. Supports drag & drop, multiple files, progress tracking, and token counting.
Preview
Drag & drop file upload with attachment list
Drag & drop files or click to browse
Max 10.0 MB per file • 3/5 files
quarterly-report.pdf
data-analysis.xlsx
screenshot.png
Upload States
Files being uploaded and processed
large-dataset.csv
analysis.py
Error State
Failed uploads with retry option
document.pdf
corrupted-file.zip
Inline Variant
Compact list with add button
quarterly-report.pdf
data-analysis.xlsx
Compact Variant
Minimal inline file chips
Button Variant
Simple button trigger
Interactive Demo
Try adding and removing files
Drop files here or click to browse (max 5MB)
Max 5.0 MB per file • 0/3 files
Props
AIAttachmentsInput component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
attachments | Attachment[] | — | Current attachments |
onAdd | (files: File[]) => void | — | Callback when files are added |
onRemove | (attachmentId: string) => void | — | Callback when an attachment is removed |
onPreview | (attachment: Attachment) => void | — | Callback when an attachment is previewed |
onDownload | (attachment: Attachment) => void | — | Callback when an attachment is downloaded |
onRetry | (attachmentId: string) => void | — | Callback when retrying failed upload |
accept | string | — | Accepted file types (MIME types or extensions) |
maxFileSize | number | — | Maximum file size in bytes |
maxFiles | number | — | Maximum number of attachments |
multiple | boolean | true | Whether multiple files can be selected |
showTokenCount | boolean | true | Show token counts for text files |
variant | 'dropzone' | 'inline' | 'compact' | 'button' | 'inline' | Display variant |
placeholder | string | 'Drag & drop files or click to browse' | Placeholder text for dropzone |
disabled | boolean | false | Disabled state |
Attachment Type
Structure for file attachments
interface Attachment { id: string // Unique identifier name: string // File name size: number // File size in bytes mimeType: string // MIME type type: FileType // 'image' | 'document' | 'code' | 'spreadsheet' | 'video' | 'audio' | 'archive' | 'other' status: AttachmentStatus // 'uploading' | 'processing' | 'ready' | 'error' progress?: number // Upload progress (0-100) error?: string // Error message if status is error previewUrl?: string // Preview URL for images thumbnailUrl?: string // Thumbnail URL tokenCount?: number // Token count for text files}Usage
Import and implementation example
import { AIAttachmentsInput, type Attachment } from '@/blocks/ai-conversation/ai-attachments-input'
export default function Example() { const [attachments, setAttachments] = useState<Attachment[]>([])
const handleAdd = async (files: File[]) => { // Create placeholder attachments with uploading status const newAttachments: Attachment[] = files.map((file, i) => ({ id: `${Date.now()}-${i}`, name: file.name, size: file.size, mimeType: file.type, type: getFileType(file.type, file.name), status: 'uploading', progress: 0, }))
setAttachments(prev => [...prev, ...newAttachments])
// Upload files and update status... }
const handleRemove = (id: string) => { setAttachments(prev => prev.filter(a => a.id !== id)) }
return ( <AIAttachmentsInput variant="dropzone" attachments={attachments} onAdd={handleAdd} onRemove={handleRemove} onPreview={(a) => openPreviewModal(a)} maxFiles={5} maxFileSize={10 * 1024 * 1024} accept="image/*,.pdf,.doc,.docx" showTokenCount /> )}Built With
2 componentsThis block uses the following UI components from the design system:
Features
Built-in functionality
- Four variants: Dropzone, inline, compact, and button display modes
- Drag & drop: Native drag and drop file upload
- Multiple files: Upload multiple files at once
- Progress tracking: Show upload progress with visual indicators
- File type icons: Automatic icons based on file type
- Token counting: Display token counts for text files
- Image thumbnails: Preview thumbnails for image files
- Error handling: Display errors and retry failed uploads
- File limits: Enforce max file size and count
- Type filtering: Accept specific file types
Accessibility
Accessibility considerations
ARIA Attributes
Hidden file input is properly labeledStatus changes announced to screen readersError messages associated with file itemsKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Navigate between interactive elements |
| Enter / Space | Trigger file picker or remove file |
Notes
- Dropzone is keyboard accessible
- File type conveyed through icons and text
- Consider adding live region for upload status