npm install react-aria-components
"use client";
import type { ReactNode } from "react";
import { Button } from "react-aria-components";
export interface AttachmentProps {
name: ReactNode;
/** A line under the name: its type and size. */
meta?: ReactNode;
/** An image to show in place of the file mark. */
src?: string;
/** Shows a remove button and is called when it is pressed. */
onRemove?: () => void;
className?: string;
}
/** A file that has been added to a prompt or sent with a message. */
export function Attachment({ name, meta, src, onRemove, className }: AttachmentProps) {
return (
<div
data-slot="attachment"
className={[
"group/attachment relative inline-flex max-w-(--tui-attachment-max-width) items-center gap-(--tui-attachment-gap) rounded-(--tui-attachment-radius) border-solid border-(length:--tui-attachment-border-width) border-(--tui-attachment-border) bg-(--tui-attachment-bg) py-(--tui-attachment-padding) pr-[calc(var(--tui-attachment-padding)_*_2.5)] pl-(--tui-attachment-padding) font-(family-name:--tui-font)",
className,
]
.filter(Boolean)
.join(" ")}
>
<span className="flex size-(--tui-attachment-thumb-size) shrink-0 items-center justify-center overflow-hidden rounded-[calc(var(--tui-attachment-radius)_*_0.6)] bg-(--tui-attachment-thumb-bg) text-(--tui-attachment-thumb-fg)">
{src ? (
<img src={src} alt="" className="size-full object-cover" />
) : (
<svg aria-hidden viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" className="size-[52%]">
<path d="M9 2H5a1.5 1.5 0 0 0-1.5 1.5v9A1.5 1.5 0 0 0 5 14h6a1.5 1.5 0 0 0 1.5-1.5V5.5z" />
<path d="M9 2v3.5h3.5" />
</svg>
)}
</span>
<span className="flex min-w-0 flex-col gap-1">
<span className="truncate text-(length:--tui-attachment-font-size) leading-none font-medium text-(--tui-attachment-fg)">{name}</span>
{meta && <span className="truncate text-(length:--tui-attachment-meta-size) leading-none text-(--tui-attachment-muted)">{meta}</span>}
</span>
{onRemove && (
<Button
aria-label="Remove"
onPress={onRemove}
className="absolute -top-1.5 -right-1.5 flex size-4.5 cursor-default items-center justify-center rounded-full border-none bg-(--tui-attachment-remove-bg) text-(--tui-attachment-remove-fg) opacity-0 outline-none transition-opacity duration-(--tui-duration) group-hover/attachment:opacity-100 data-focus-visible:opacity-100 data-focus-visible:[outline:2px_solid_var(--tui-ring)]"
>
<svg aria-hidden viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" className="size-2.5">
<path d="M4 4l8 8M12 4l-8 8" />
</svg>
</Button>
)}
</div>
);
}:root {
color-scheme: light;
--tui-bg: #ffffff;
--tui-fg: #0a0a0a;
--tui-muted: #f5f5f5;
--tui-muted-fg: #737373;
--tui-border: #e5e5e5;
--tui-primary: #171717;
--tui-primary-fg: #fafafa;
--tui-ring: #a3a3a3;
--tui-success: #16a34a;
--tui-warning: #d97706;
--tui-danger: #dc2626;
--tui-radius: 8px;
--tui-border-width: 1px;
--tui-space: 4px;
--tui-shadow: none;
--tui-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
--tui-text: 14px;
--tui-duration: 150ms;
/* Attachment */
--tui-attachment-padding: calc(var(--tui-space) * 1.5);
--tui-attachment-gap: calc(var(--tui-space) * 2.5);
--tui-attachment-thumb-size: calc(var(--tui-space) * 9);
--tui-attachment-max-width: 240px;
--tui-attachment-radius: calc(var(--tui-radius) * 1.5);
--tui-attachment-border-width: var(--tui-border-width);
--tui-attachment-font-size: 13px;
--tui-attachment-meta-size: 12px;
--tui-attachment-bg: var(--tui-bg);
--tui-attachment-fg: var(--tui-fg);
--tui-attachment-muted: var(--tui-muted-fg);
--tui-attachment-border: var(--tui-border);
--tui-attachment-thumb-bg: var(--tui-muted);
--tui-attachment-thumb-fg: var(--tui-muted-fg);
--tui-attachment-remove-bg: var(--tui-fg);
--tui-attachment-remove-fg: var(--tui-bg);
}
.dark,
[data-theme="dark"] {
color-scheme: dark;
--tui-bg: #0a0a0a;
--tui-fg: #fafafa;
--tui-muted: #1c1c1c;
--tui-muted-fg: #a3a3a3;
--tui-border: #2a2a2a;
--tui-primary: #fafafa;
--tui-primary-fg: #171717;
--tui-ring: #737373;
--tui-success: #22c55e;
--tui-warning: #f59e0b;
--tui-danger: #ef4444;
}Needs Tailwind CSS v4. Import the stylesheet once, after Tailwind.