Skip to content
Haze UI

Attachment

A file chip or card with a type icon, a middle-truncated name, size, upload progress, an error state and a remove button.

pnpm dlx shadcn@latest add @haze/attachment
Open preview in a new tab
Liveno JavaScript

When to use

  • Files queued under a message box or attached to a sent message
  • A list of downloadable documents, each with its size
  • Showing one file's upload progress or error next to its name

When not to use

  • The user still has to choose the files. Use file-upload or file-input.
  • You show a person's profile picture. Use avatar or avatar-upload.

Installation

Add the Haze registry to components.json once, then install Attachment with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/attachment
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
name*string–Full file name with extension; the accessible name and tooltip. The visible text is cut in the middle so the end stays readable.
bytesnumber–Size in bytes, shown as B, KB or MB.
typestring""MIME type; with the extension it picks the icon (image, document, sheet, code, archive or generic).
variant"chip" | "card""chip"Compact inline chip or a larger card.
state"uploading" | "ready" | "error""ready"Uploading shows a progress bar, error shows the message in the destructive color with a warning icon.
progressnumber–0 to 100. Leave out while uploading for a bar with no value.
errorMessagestring"Upload failed"Text of the error state.
hrefstring–Turns the name into a download link.
removablebooleanfalseAdds a remove button with data-attachment-remove; the action is yours to wire.
removeLabelstring"Remove {name}"Accessible name of the remove button; {name} becomes the file name.
progressLabelstring"Uploading {name}"Accessible name of the progress bar.
previewboolean–Card only: shows a picture placeholder on top. Defaults to true for images.
previewLabelstring""Describes the real preview image; leave empty while it is a placeholder.
classstring–Extra classes on the root.
...restHTML attributes–Passed to the root element.

Keyboard interactions

Tab
Move to the download link, then to the remove button.
Enter
Follow the download link or activate the remove button.

Accessibility

  • The full file name is in the accessible name and the tooltip; the visibly shortened text is hidden from assistive technology so it is not read twice.
  • Upload progress is a progressbar named with the file name and shows the percentage as text, and the error state has an icon and a message, so neither relies on color.
  • The remove button is named "Remove <file name>" so several chips stay distinguishable, and it is 28 px square.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Attachment" with `npx shadcn@latest add @haze/attachment`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Attachment from "@/components/haze/ui/attachment.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/attachment.md

  • Customize with real content

    Adapt the Haze attachment ui for our product. Replace the demo values of these props with our real content: name, bytes, type, variant, state, progress, errorMessage, href, removable, removeLabel, progressLabel, preview, previewLabel, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The full file name is in the accessible name and the tooltip; the visibly shortened text is hidden from assistive technology so it is not read twice. Upload progress is a progressbar named with the file name and shows the percentage as text, and the error state has an icon and a message, so neither relies on color. The remove button is named "Remove <file name>" so several chips stay distinguishable, and it is 28 px square. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using attachment, check it fits: use it when files queued under a message box or attached to a sent message; a list of downloadable documents, each with its size; showing one file's upload progress or error next to its name. Avoid it when the user still has to choose the files. use file-upload or file-input.; you show a person's profile picture. use avatar or avatar-upload.. Alternatives: @haze/file-upload, @haze/file-input, @haze/chip.

Dependencies

  • npm: @lucide/astro
  • @haze/placeholder
  • @haze/progress
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog