File item

Slant / Data

One attachment: its name, size, upload progress and state, with Retry when it fails and an optional remove button.

Demo

Usage

@tuttn/slant
import { FileItem, FileList, Slant } from '@tuttn/slant'

// Each item is an li: put it in a FileList.
<FileList>
  {/* Without a status, progress decides: done at 100, uploading below. */}
  <FileItem name="eval-results.csv" type="CSV" size="2.4 MB" progress={38} />
  <FileItem name="agent-handoff.md" type="MD" size="12 KB" progress={100} />

  {/* Failed turns the bar danger; onRetry adds the Retry button. */}
  <FileItem name="model-weights.safetensors" type="BIN" size="1.8 GB" progress={61}
    status="failed" onRetry={retry} retryLabel="Try again" />

  {/* onRemove adds a remove button (named "Remove notes.md") at the end of the head row. */}
  <FileItem name="notes.md" type="MD" progress={100} onRemove={() => remove('notes.md')} />

  {/* Your own status line. */}
  <FileItem name="notes.md" type="MD" progress={0} statusText="Waiting for Wi-Fi" />
</FileList>

// Or rename the built-in strings for every item under a root.
<Slant messages={{ uploaded: 'Sent', uploadFailed: 'Not sent', retry: 'Try again', upload: name => `Sending ${name}`, removeFile: name => `Discard ${name}` }}>…</Slant>

Props

PropTypeDefaultDescription
namestring—The file name. It also names the progress bar ("<name> upload").
typestring—A short type tag shown in the box, e.g. "CSV".
sizestring—A formatted size for the status line, e.g. "2.4 MB".
progressnumber—How far the upload is, 0 to 100. Values outside that range are clamped.
status'uploading' | 'done' | 'failed'done at 100, else uploadingColours the bar and picks the status text.
onRetry() => void—Shows a Retry button on a failed upload.
retryLabelstringmessages.retryThe Retry button's text.
statusTextReactNodemessages.uploaded, messages.uploadFailed, or messages.percent(progress)Replaces the status text.
onRemove() => void—Shows a remove button, a ghost ×, at the end of the head row, which calls this. Move focus somewhere that stays when the item goes.
removeLabelstringmessages.removeFile(name) ("Remove <name>")The remove button's accessible name.
…restOmit<HTMLAttributes<HTMLLIElement>, 'children'>—className, style, other attributes and the ref go on the li. It takes no children.

Keyboard

Tabreaches the Retry button, on a failed item with onRetry, then the remove button, with onRemove
Enter / Spaceruns onRetry or onRemove

Accessibility

  • The type box is aria-hidden. The name is read in full even when it's cut short on screen, where its title shows the rest on hover.
  • The bar is a progressbar named "<name> upload" (messages.upload), with the clamped percent as aria-valuenow.
  • The status line is a polite live region, so a screen reader hears it change: the percent, then "Uploaded" or "Upload failed". Failure is in those words, not only in the danger colour.
  • The remove button is an icon button named "Remove <name>" (messages.removeFile, or removeLabel), so each one says which file it removes.
  • Retry unmounts as soon as the item stops being failed, and the remove button with its item, and focus falls back to the page. In onRetry and onRemove, move focus to something that stays, as the demo does with Reset.

Progress outside 0–100 is clamped, in the status text and on the bar, and the percent is rounded down: 99.6 reads 99%. failed only comes from you; without status, an item is done at 100 and uploading below. The default strings (uploaded, uploadFailed, percent, upload, retry and removeFile) come from the nearest <Slant messages>; retryLabel, removeLabel and statusText override them for one item.