Syed Hasnain

Attachments

AI chats 57

About

File and image attachments with progress, failure recovery, metadata, and removal actions.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Attachments to your project and fits it to your theme.

Code

How Attachments is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { useState } from 'react'
import Attachments, { AttachmentItem } from '@/components/ui/attachments'

function AttachmentVariantPreview({
  variant,
  showAll = false,
}: {
  variant: 'default' | 'uploading' | 'failed'
  showAll?: boolean
}) {
  const [items, setItems] = useState<AttachmentItem[]>(() => {
    const examples: AttachmentItem[] = [
      { id: 'design', kind: 'image', name: 'component-layout.png', size: '2.4 MB', progress: 72 },
      { id: 'spec', kind: 'pdf', name: 'agent-spec.pdf', size: '1.8 MB', progress: 45 },
      { id: 'notes', kind: 'document', name: 'project-notes.docx', size: '340 KB', progress: 88 },
      { id: 'trace', kind: 'file', name: 'trace.json', size: '24 KB', progress: 28 },
    ]
    return showAll ? examples : [examples[1]]
  })
  return (
    <div className={showAll ? 'w-full max-w-xl' : 'w-full max-w-sm'}>
      <Attachments
        className={showAll ? undefined : 'sm:grid-cols-1'}
        variant={variant}
        items={items}
        onRemove={(id) => setItems((current) => current.filter((item) => item.id !== id))}
        onRetry={(id) =>
          setItems((current) =>
            current.map((item) =>
              item.id === id ? { ...item, status: 'uploading', progress: 0 } : item,
            ),
          )
        }
      />
    </div>
  )
}

export default function Demo() {
  return <AttachmentVariantPreview variant="default" showAll />
}

Dependencies

More by Syed Hasnain

View all
  • Color Picker

    Color Picker

    246
  • Cost Meter

    Cost Meter

    65
  • Message Scroller

    Message Scroller

    56
  • Background Inbox

    Background Inbox

    49
  • Commit

    Commit

    48
  • Approval Card

    Approval Card

    39
  • Quota Banner

    Quota Banner

    38
  • Environment Variables

    Environment Variables

    35

More in AI chats

View all
  • Agent Chat

    Agent Chat

    21
  • AI Suggestions

    AI Suggestions

    27
  • Interactive LLM Token & Context Window Visualizer

    Interactive LLM Token & Context Window Visualizer

    30
  • AI Actions

    AI Actions

    372
  • Aquarium Prompt

    Aquarium Prompt

    223
  • Message Parts

    Message Parts

    11
  • AI SaaS Workflow Hero

    AI SaaS Workflow Hero

    36
  • AI Chat Composer

    AI Chat Composer

    22

Explore more

Part of Pasta UI — browse the full library on 21st.dev.