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
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
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | — | The file name. It also names the progress bar ("<name> upload"). |
type | string | — | A short type tag shown in the box, e.g. "CSV". |
size | string | — | A formatted size for the status line, e.g. "2.4 MB". |
progress | number | — | How far the upload is, 0 to 100. Values outside that range are clamped. |
status | 'uploading' | 'done' | 'failed' | done at 100, else uploading | Colours the bar and picks the status text. |
onRetry | () => void | — | Shows a Retry button on a failed upload. |
retryLabel | string | messages.retry | The Retry button's text. |
statusText | ReactNode | messages.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. |
removeLabel | string | messages.removeFile(name) ("Remove <name>") | The remove button's accessible name. |
…rest | Omit<HTMLAttributes<HTMLLIElement>, 'children'> | — | className, style, other attributes and the ref go on the li. It takes no children. |
Keyboard
| Tab | reaches the Retry button, on a failed item with onRetry, then the remove button, with onRemove |
| Enter / Space | runs 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 itstitleshows the rest on hover. - The bar is a
progressbarnamed "<name> upload" (messages.upload), with the clamped percent asaria-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, orremoveLabel), 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
onRetryandonRemove, 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.