import {ChatAttachment, ChatAttachmentGroup, ChatAttachmentInput} from "@peakui-pro/react";export default () => ( <> <ChatAttachmentGroup> {/* Without children: Preview, then Info. An image or video with a `src` is a thumbnail. */} <ChatAttachment mimeType="application/pdf" name="brief.pdf" size={824120}> <ChatAttachment.Preview> <ChatAttachment.Icon /> </ChatAttachment.Preview> <ChatAttachment.Info> <ChatAttachment.Name /> <ChatAttachment.Size /> </ChatAttachment.Info> <ChatAttachment.Remove onPress={remove} /> </ChatAttachment> </ChatAttachmentGroup> <ChatAttachmentInput onFilesSelected={setFiles}> {/* The picker. An icon alone needs `isIconOnly` or an `aria-label` to be named. */} <ChatAttachmentInput.Trigger isIconOnly aria-label="Attach file"> <Paperclip /> </ChatAttachmentInput.Trigger> {/* The drop target is your element: spread the props, and render `props.children`. */} <ChatAttachmentInput.Dropzone render={(props) => <div {...props} />}> {content} </ChatAttachmentInput.Dropzone> </ChatAttachmentInput> </>);
@layer components { .chat-attachment { --chat-attachment-height: 3.5rem; --chat-attachment-radius: var(--radius-lg); } /* * A core component used as the drop target writes its own `data-slot` over the dropzone's, so * style the target by the class and the attribute, which always arrive. */ .chat-attachment-dropzone[data-drop-target] { outline-color: var(--color-success); }}
data-variant and data-media-type mark the root; a thumbnail reveals its overlay on hover and focus:
Variant: [data-variant="media"] for an image or video with a src, [data-variant="file"] otherwise
Media type: [data-media-type="image"], "video", "audio", "document" or "unknown"
Hover: :hover shows the overlay and the remove button on a thumbnail
Focus: :focus-within shows them too, so a keyboard user can reach Remove
No hover: @media (hover: none) shows them at rest
Drop target: [data-drop-target] draws a dashed outline while a drag is over it
Reduced motion: @media (prefers-reduced-motion: reduce) ends the fade
Forced colors: @media (forced-colors: active) draws the border in ButtonBorder, the icon in CanvasText, the overlay as solid Canvas and the drop outline in Highlight
Renders your element as the drop target; it must return a div. A core component used as the target writes its own data-slot over the dropzone's, so merge props.className and style by .chat-attachment-dropzone and [data-drop-target]
children
ReactNode
-
Content for your element, delivered as props.children together with React Aria's hidden drop button, which keyboards and screen readers drop onto. Render props.children and the button survives
Exported for a host that formats its own rows, which must match ChatAttachment; call it from a client component. The kind that picks the icon: the MIME type first, then the extension, then 'generic'. One of 'archive', 'audio', 'code', 'document', 'generic', 'image', 'pdf', 'spreadsheet' or 'video'
formatChatAttachmentSize(bytes?)
string | undefined
Exported for the same reason. 1024-based: "0 B", whole "805 KB", then one decimal "14.5 MB" and "3.0 GB". undefined for no size
import {ChatAttachment, ChatAttachmentGroup} from "@peakui-pro/react";export function Formats() { return ( <ChatAttachmentGroup className="max-w-2xl">
project-brief.pdf805 KB
screenshot.png243 KB
"use client";import {ChatAttachment, ChatAttachmentGroup} from "@peakui-pro/react";import {useState} from "react";
"use client";import {ArrowUp, Paperclip} from "@gravity-ui/icons";import {Button, TextArea} from "@peakui/react";import {ChatAttachment, ChatAttachmentGroup, ChatAttachmentInput} from "@peakui-pro/react";
"use client";import {ArrowUp, Paperclip} from "@gravity-ui/icons";import {Button, TextArea} from "@peakui/react";import {ChatAttachmentInput} from "@peakui-pro/react";
Drop one image or PDF here
"use client";import {ChatAttachmentInput} from "@peakui-pro/react";import {useState} from "react";
project-brief.pdf · pdf · 805 KB
design-assets.zip · archive · 14.5 MB
notes · generic · 0 B
"use client";import {formatChatAttachmentSize, inferChatAttachmentFileKind} from "@peakui-pro/react";const files = [