Компоненты
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Calendar
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Date Picker
- Dialog
- DrawerNew
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Meter
- Number Field
- OTP FieldNew
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
AI Components
- AI Components
- Chat Conversation
- Chat Message
- Chat Response
- Chat Suggestion
- Chat Prompt Input
- Chat Attachments
- Chat Code Block
- Chat Image
- Chat Inline Citation
- Chat Reasoning
- Chat Sources
- Chat Actions
- Chat Context
- Chat Loader
- Chat Task
- Chat Tool
- Chat Web Preview
- Chat Snippet
- Chat Terminal
- Chat Stack Trace
- Chat Test Results
- Chat File Tree
- Chat Environment Variables
- Chat Audio Player
- Chat Transcription
- Chat Speech Input
- Chat Mic Selector
- Chat Voice Selector
- Chat Agent
- Chat Persona
- Chat Connection
- Chat Queue
- Chat Checkpoint
- Chat Confirmation
- Chat Artifact
- Chat JSX Preview
- Chat Schema Display
- Chat Package Info
- Chat Commit
- Chat Plan
- Chat Panel
- Chat Open In Chat
- Chat Sandbox
- Chat Model Selector
- Chat Canvas
- Chat Node
- Chat Edge
Resources
Chat Attachments
Превью прикреплённых файлов с removable-чипами и тремя вариантами layout.
Grid (над текстом)
List (внутри prompt-input)
hero.png
121.6 KB
spec.pdf
883.3 KB
demo.mp4
3.9 MB
Next.js docs
Inline (в сообщении)
hero.png
spec.pdf
demo.mp4
Next.js docs
"use client";
import { useState } from "react";
import {
ChatAttachment,
type ChatAttachmentData,
ChatAttachments,
} from "@/components/ui/chat-attachments";
const initial: ChatAttachmentData[] = [
{
id: "1",
name: "hero.png",
mediaType: "image/png",
url: "https://picsum.photos/seed/jenny-hero/200/200",
size: 124_503,
},
{
id: "2",
name: "spec.pdf",
mediaType: "application/pdf",
size: 904_502,
},
{
id: "3",
name: "demo.mp4",
mediaType: "video/mp4",
size: 4_120_400,
},
{
id: "4",
name: "Source: nextjs.org",
source: { url: "https://nextjs.org", title: "Next.js docs" },
},
];
export default function Particle() {
const [grid, setGrid] = useState(initial);
const [list, setList] = useState(initial);
return (
<div className="flex w-full max-w-2xl flex-col gap-6 p-4">
<section className="space-y-2">
<p className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
Grid (над текстом)
</p>
<ChatAttachments variant="grid">
{grid.map((a) => (
<ChatAttachment
data={a}
key={a.id}
onRemove={() =>
setGrid((items) => items.filter((i) => i.id !== a.id))
}
/>
))}
</ChatAttachments>
</section>
<section className="space-y-2">
<p className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
List (внутри prompt-input)
</p>
<ChatAttachments variant="list">
{list.map((a) => (
<ChatAttachment
data={a}
key={a.id}
onRemove={() =>
setList((items) => items.filter((i) => i.id !== a.id))
}
/>
))}
</ChatAttachments>
</section>
<section className="space-y-2">
<p className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
Inline (в сообщении)
</p>
<ChatAttachments variant="inline">
{initial.map((a) => (
<ChatAttachment data={a} key={a.id} />
))}
</ChatAttachments>
</section>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @jenny/chat-attachments
Usage
import {
ChatAttachment,
type ChatAttachmentData,
ChatAttachments,
} from "@/components/ui/chat-attachments";
const items: ChatAttachmentData[] = [
{ id: "1", name: "screenshot.png", mediaType: "image/png", url: blobUrl, size: 124_503 },
{ id: "2", name: "spec.pdf", mediaType: "application/pdf", size: 904_502 },
];
<ChatAttachments variant="grid">
{items.map((a) => (
<ChatAttachment data={a} key={a.id} onRemove={() => remove(a.id)} />
))}
</ChatAttachments>Варианты layout
variant | Когда использовать |
|---|---|
grid | Над текстом, превью-плитки 96×96 с removable-кнопкой сверху. |
list | Внутри prompt-input — строки с превью, именем и размером. |
inline | Компактные чипы внутри сообщения. |
Тип данных
type ChatAttachmentData = {
id: string;
name?: string;
filename?: string;
mediaType?: string; // 'image/png', 'application/pdf', ...
url?: string; // object URL или remote URL
size?: number; // в байтах
source?: { url, title? }; // когда это веб-источник, а не файл
};Категория определяется автоматически из mediaType (image/video/audio/document/source/unknown), иконка подбирается из lucide.
Кастомизация
Если стандартного <ChatAttachment> тебе мало — собирай вручную через ChatAttachmentPreview, ChatAttachmentInfo, ChatAttachmentRemove (они читают контекст). Для очень кастомного payload используй хук useChatAttachment().