Components

Attachment

A file drawn as a card: its preview, name and size, with upload progress or an error in place of the size while it transfers.

Usage

import {
  Attachment,
  AttachmentActions,
  AttachmentContent,
  AttachmentMeta,
  AttachmentName,
  AttachmentPreview,
  AttachmentProgress,
  AttachmentRemove,
} from 'nyctoui/attachment'

<Attachment status="uploading">
  <AttachmentPreview />
  <AttachmentContent>
    <AttachmentName>report.pdf</AttachmentName>
    <AttachmentProgress value={62} />
  </AttachmentContent>
  <AttachmentActions>
    <AttachmentRemove aria-label="Cancel report.pdf" />
  </AttachmentActions>
</Attachment>

Attachment draws a file; it doesn’t upload one. Pair it with File Upload to show the files someone chose, or use it alone for files already sent. AttachmentProgress takes the place of AttachmentMeta at the same height, so the card doesn’t move as an upload starts and ends.

Good for

  • Files attached to a message in a chat or email composer, each with its upload progress.
  • Receipts on an expense report, with a thumbnail and the file size.
  • Contracts and briefs on a project page, linking to the stored file.
  • Files sent in a support ticket thread, after the upload finished.

Examples

States

The demo at the top of the page. status sets data-status; at error the preview and meta turn red, and uploading marks the card busy. The actions are yours: here a retry for the failed file.

Image preview

Give AttachmentPreview a src for a thumbnail. For a file someone just chose, create an object URL and revoke it when the card goes away, as the File Upload demo does.

Pass render to make the whole card a link to the file. It takes the row hover and the focus ring.

Best practices

Do
  • Pair it with File Upload for files someone just chose, and use it alone for files already stored.
  • Show progress with AttachmentProgress while the file transfers; it takes the size’s place at the same height, so the card holds still.
  • Give an image an AttachmentPreview with a src, and let other files show their type icon.
  • Say what went wrong when an upload fails, such as “Too large” or “Network error”, and offer a retry or remove action.
Don’t
  • Expect it to upload anything. It draws the file; your app moves the bytes.
  • Leave AttachmentRemove without an aria-label that names the file, such as “Remove invoice.pdf”, when several cards sit together.
  • Use it for a gallery of photos. A card per file is for documents and a handful of images, not a camera roll.

API reference

Attachment

The card, a <div> by default.

PropTypeDefault
status
Sets data-status. error turns the preview and meta red; uploading sets aria-busy.
'idle' | 'uploading' | 'complete' | 'error''idle'
render
Another element to render, such as a link.
ReactElement—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AttachmentPreview

The 32px tile at the start. Decorative.

PropTypeDefault
src
An image to show in place of the icon.
string—
children
A 16px icon for the file’s type.
ReactNodefile icon
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AttachmentContent

Stacks the name over the meta or progress.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AttachmentName

The file name on one line, with an ellipsis.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AttachmentMeta

Size, type or an error, in 12px text.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AttachmentProgress

A Progress track and percentage on the meta line. Takes Progress’s props.

PropTypeDefault
value
How far the upload has got, 0 to 100. null while unknown.
number | null—
showValue
Shows the percentage after the track.
booleantrue
aria-label
What screen readers call the bar.
string'Upload progress'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AttachmentActions

Buttons at the end of the card.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AttachmentRemove

A small ghost Button with an ×. Takes Button’s props; name it for the file.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—