Attachment
File cards with image previews, upload progress, retry and remove actions, built on UI SDK core.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/attachmentThis adds components/keyframery/attachment.tsx and its primitive to your project, and installs UI SDK, along with message-scroller, button, which it builds on. The motion tokens are added to your global CSS the first time you install a component.
Usage
import {
Attachment,
AttachmentAction,
AttachmentActions,
AttachmentContent,
AttachmentDescription,
AttachmentGroup,
AttachmentMedia,
AttachmentProgress,
AttachmentRemove,
AttachmentTitle,
AttachmentTrigger,
} from "@/components/keyframery/attachment"Motion
| Move | What you see |
|---|---|
| Unfold | New files grow from 80% through a soft blur on a pop spring. |
| Height | Removing a file shrinks it and closes the space it occupied. |
| Roll | Upload progress fills on a spring and fades once complete. |
Timing and springiness follow the motion style you set. To change how fast this attachment moves, pass speed:
<Attachment speed="fast">
…
</Attachment>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--attachment-face | File surface | bg-background |
--attachment-ink | File text | text-foreground |
--attachment-muted | File details | text-muted-foreground |
--attachment-radius | File corners | rounded-[12px] |
--attachment-font | Filename size | text-[13px] |
--attachment-media-size | Preview size | size-10 |
--attachment-gap | File gap | gap-2.5 |
--attachment-padding | File padding | p-1.5 |
API reference
Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.
Attachment
Renders a <div>, and takes its props too.
Prop
Type
AttachmentAction
Renders a <button>, and takes its props too.
Prop
Type
AttachmentGroup
Renders a <div>, and takes its props too.
Prop
Type
AttachmentMedia
Renders a <div>, and takes its props too.
Prop
Type
AttachmentRemove
Renders a <button>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
AttachmentActions: a<div>AttachmentContent: a<div>AttachmentDescription: a<span>AttachmentProgress: a<span>AttachmentTitle: a<span>AttachmentTrigger: a<button>
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves between each file’s preview and actions. |
| Enter | Activates the focused preview or action. |
| Space | Presses a focused file action. |
Accessibility
Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.
Built on UI SDK's core
UI SDK doesn't ship a attachment, so this one is defined with its core: one definePrimitive in components/keyframery/core/attachment-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/attachment.
Questions
How does the animated Attachment for UI SDK move?
Unfold: New files grow from 80% through a soft blur on a pop spring. Height: Removing a file shrinks it and closes the space it occupied. Roll: Upload progress fills on a spring and fades once complete.
Do I need Motion or Framer Motion for the animated Attachment?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
UI SDK has no attachment. How is this one built on UI SDK?
Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/attachment-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.
What happens to the Attachment when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.