# File Item (/docs/file-item)





`FileItem` shows one file as a row: an icon or a thumbnail, the name, a meta line with the size and date, and the buttons that go with it. The same row works for a `File` the visitor just picked and for a document your server stores, so a list of uploads and a list of a student's documents look alike. [`FileUpload`](/docs/file-upload) renders its file list with it.

```tsx
import { FileItem } from '@42-central/ui-react/file-item';

<FileItem file={file} onRemove={() => remove(file)} />
```

## A picked file [#a-picked-file]

Pass a `File`. The name, the size (formatted for the [`IntlProvider`](/docs/intl) locale) and the icon all come from it; the icon follows the file's kind, read from its type or, when the browser reports none (it often doesn't for `.csv` or `.docx`), from its extension. `onRemove` adds the × button, named "Remove grades.csv" for screen readers.

<Preview align="block" code="&#x22;const [files, setFiles] = useState<File[]>([]);\n\n{files.map((file) => (\n  <FileItem\n    key={`${file.name}-${file.lastModified}`}\n    file={file}\n    onRemove={() => setFiles((current) => current.filter((f) => f !== file))}\n  />\n))}\n\n<FileTrigger multiple onSelect={(picked) => setFiles((current) => [...current, ...picked])}>\n  Add files\n</FileTrigger>&#x22;">
  <FileItemPickedDemo />
</Preview>

## A stored document [#a-stored-document]

A document on your server isn't a `File`: describe it with `{ name, size?, type?, date?, src? }`. The `date` (a `Date`, a timestamp or an ISO string) shows after the size, as a medium date in the provider's locale and time zone. `actions` holds your buttons; give each an accessible name that includes the file, since a page of "Download" buttons is otherwise impossible to tell apart.

<Preview align="block" code="&#x22;<FileItem\n  file={{\n    name: 'internship-agreement-signed.pdf',\n    size: 248_213,\n    type: 'application/pdf',\n    date: document.signedAt,\n  }}\n  actions={\n    <>\n      <Button variant=\&#x22;outline\&#x22; color=\&#x22;neutral\&#x22; size=\&#x22;xs\&#x22; aria-label={`View ${name}`}>\n        View\n      </Button>\n      <ActionIcon variant=\&#x22;subtle\&#x22; color=\&#x22;neutral\&#x22; size=\&#x22;xs\&#x22; aria-label={`Download ${name}`}>\n        <Download className={iconStroke} aria-hidden />\n      </ActionIcon>\n    </>\n  }\n/>&#x22;">
  <FileItemStoredDemo />
</Preview>

A date-only ISO string (`"2026-10-01"`) is midnight UTC, which reads as the day before west of UTC. Pass a full timestamp, or replace the line with `meta` (the size and date go, the status stays):

```tsx
<FileItem file={document} meta={`Signed by ${document.signer}`} />
```

## A list of documents [#a-list-of-documents]

`asChild` makes the row your element, so a list of documents can be a real list: screen readers announce it as one, with its length.

<Preview align="block" code="&#x22;<ul className=\&#x22;flex flex-col gap-2\&#x22;>\n  {documents.map((document) => (\n    <FileItem key={document.id} asChild file={document} actions={<DownloadButton document={document} />}>\n      <li />\n    </FileItem>\n  ))}\n</ul>&#x22;">
  <FileItemListDemo />
</Preview>

The photo shows its `src` as a thumbnail. Images and `src` thumbnails load lazily and fall back to the kind icon if they fail; a picked image `File` gets an object URL, revoked when the row goes. Pass `thumbnails={false}` to show kind icons only and make no object URLs, for a list of hundreds of photos.

<Callout type="warn" title="An uploaded SVG never gets an object URL">
  An object URL has your app's origin. The `<img>` never runs an SVG's script, but "Open image in new tab" on the thumbnail would, as your app. So a picked `File` goes through [`useObjectUrl`](/docs/utilities/files#useobjecturl): a PNG, JPEG, GIF, WebP, AVIF or BMP is re-wrapped under that type, an SVG is drawn from a `data:` URL (opaque origin, up to `SVG_DATA_URL_LIMIT`, 5 MB), and any other type shows the kind icon. A descriptor's `src` is your server's URL, shown as it is: see [FilePreview's Security section](/docs/file-preview#security) for the headers to send.
</Callout>

## Upload status [#upload-status]

`status` takes a file through an upload: `idle`, `queued`, `uploading`, `processing`, then `done` or `error`. `progress` (from 0 to 1) fills the bar while uploading. Without a `progress`, the bar is indeterminate, as it is while processing. An `error` replaces the meta line with your message, and `onRetry` adds a Retry button next to it.

<Preview align="block" code="&#x22;<FileItem file={file} status=\&#x22;idle\&#x22; />\n<FileItem file={file} status=\&#x22;queued\&#x22; />\n<FileItem file={file} status=\&#x22;uploading\&#x22; progress={0.42} />\n<FileItem file={file} status=\&#x22;processing\&#x22; />\n<FileItem file={file} status=\&#x22;done\&#x22; />\n<FileItem file={file} status=\&#x22;error\&#x22; error=\&#x22;The server is unreachable.\&#x22; onRetry={retry} />&#x22;">
  <FileItemStatusesDemo />
</Preview>

While the file is queued or in flight, the × button is named "Cancel upload of …" instead of "Remove …", and calls `onCancel` (falling back to `onRemove`). Wire both: `onCancel` stops the upload, `onRemove` drops a settled file. [`useFileQueue`](/docs/hooks/use-file-queue) hands you all of these through `itemProps`.

### Driving it from an upload [#driving-it-from-an-upload]

`FileItem` doesn't upload anything: you feed it the state of yours, or let [`useFileQueue`](/docs/hooks/use-file-queue) run the uploads and spread its `itemProps(id)`. Here a fake queue uploads two files at a time, and the third fails once at 60%. Press Upload, then Retry.

<Preview align="block" code="&#x22;<FileItem\n  file={upload.file}\n  status={upload.status}\n  progress={upload.progress}\n  error={upload.error}\n  onRetry={() => retry(upload)}\n  onRemove={() => cancel(upload)}\n/>&#x22;">
  <FileItemUploadDemo />
</Preview>

Pass `status` from the first render, `"idle"` or `"queued"`: the status region screen readers listen to only exists once there is a status, and it speaks up on changes, not on the status it starts with. See [Accessibility](#accessibility).

## Icons [#icons]

`icons` replaces any default icon, by kind (`image`, `video`, `audio`, `pdf`, `text`, `archive`, `spreadsheet`, `document`, `code`, `font`, `other`) or by button (`remove`, `retry`, `done`). An icon you pass is drawn as given; add the kit's `iconStroke` class to keep its 1.5px line.

<Preview align="block" code="&#x22;import { iconStroke } from '@42-central/ui-react';\n\nconst icons = {\n  pdf: <FileBadge className={iconStroke} aria-hidden />,\n  document: <Presentation className={iconStroke} aria-hidden />,\n  code: <FileCode2 className={iconStroke} aria-hidden />,\n};\n\n<FileItem icons={icons} file={{ name: 'certificate.pdf', size: 98_000 }} />&#x22;">
  <FileItemIconsDemo />
</Preview>

## In another language [#in-another-language]

Every string goes through `translations`, and a partial override keeps the English default for the rest. Sizes, dates and the percentage come from the [`IntlProvider`](/docs/intl) locale, so French reads "1,23 Mo · 1 oct. 2026" and "68 %" with no extra work. Here 23:30 UTC on September 30th is already October 1st in Paris.

<Preview align="block" code="&#x22;const FR: FileItemTranslations = {\n  remove: (name) => `Retirer ${name}`,\n  cancel: (name) => `Annuler l'envoi de ${name}`,\n  retry: 'Réessayer',\n  queued: 'En attente',\n  processing: 'Traitement…',\n  done: 'Envoyé',\n  failed: \&#x22;Échec de l'envoi\&#x22;,\n  announcement: (status, name) =>\n    status === 'uploading'\n      ? `Envoi de ${name}`\n      : status === 'done'\n        ? `${name} envoyé`\n        : `Échec de l'envoi de ${name}`,\n};\n\n<IntlProvider locale=\&#x22;fr-FR\&#x22; timeZone=\&#x22;Europe/Paris\&#x22;>\n  <FileItem translations={FR} file={{ name: 'convention-de-stage.pdf', size: 1_234_567, date }} />\n  <FileItem translations={FR} file={releve} status=\&#x22;uploading\&#x22; progress={0.68} />\n  <FileItem translations={FR} file={attestation} status=\&#x22;error\&#x22; error=\&#x22;Le serveur ne répond pas.\&#x22; onRetry={retry} />\n</IntlProvider>&#x22;">
  <FileItemFrenchDemo />
</Preview>

## Right-to-left [#right-to-left]

The row is laid out with logical properties, so an RTL locale mirrors it: the icon on the right, the buttons on the left, the bar filling from the right. Numbers use the locale's digits.

<Preview align="block" code="&#x22;<IntlProvider locale=\&#x22;ar-EG\&#x22;>\n  <div dir=\&#x22;rtl\&#x22; lang=\&#x22;ar\&#x22;>\n    <FileItem translations={AR} file={certificate} onRemove={remove} />\n    <FileItem translations={AR} file={transcript} status=\&#x22;uploading\&#x22; progress={0.35} />\n  </div>\n</IntlProvider>&#x22;">
  <FileItemRtlDemo />
</Preview>

## Parts [#parts]

For a layout of your own, compose the parts inside `FileItem.Root`, which takes the file, the status and the overrides. `FileItem.Name` takes `asChild` to become your link. The parts render whenever you place them, except `FileItem.Progress`, which only shows while uploading or processing: gate `FileItem.Retry` on the error yourself.

<Preview align="block" code="&#x22;<FileItem.Root file={syllabus}>\n  <FileItem.Preview />\n  <FileItem.Body>\n    <FileItem.Name asChild>\n      <a href={syllabus.url}>{syllabus.name}</a>\n    </FileItem.Name>\n    <FileItem.Meta />\n    <FileItem.Progress />\n  </FileItem.Body>\n  <FileItem.Actions>\n    <DownloadButton />\n  </FileItem.Actions>\n</FileItem.Root>&#x22;">
  <FileItemPartsDemo />
</Preview>

| Part                | Renders                                                                                                                         |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `FileItem.Root`     | The row, and the status region. Takes `file`, `status`, `progress`, `error`, `disabled`, `thumbnails`, `icons`, `translations`. |
| `FileItem.Preview`  | The thumbnail or the kind icon. Hidden from assistive tech: the name is right next to it.                                       |
| `FileItem.Body`     | The name, meta and progress column, `aria-busy` while the file uploads or is processed.                                         |
| `FileItem.Name`     | The name on one line, truncated by CSS only, with the full name in a `title`.                                                   |
| `FileItem.Meta`     | Size and date (or its `children`), then the status. An error replaces the line.                                                 |
| `FileItem.Progress` | The bar, only while uploading or processing.                                                                                    |
| `FileItem.Actions`  | Your buttons.                                                                                                                   |
| `FileItem.Retry`    | A small Retry [`Button`](/docs/button), described by the file name.                                                             |
| `FileItem.Remove`   | The × button, named after the file.                                                                                             |

## Helpers [#helpers]

The row's formatting is exported for your own cells and messages: [`formatFileSize` and `fileKind`](/docs/utilities/files).

```tsx
import { fileKind, formatFileSize, useLocale } from '@42-central/ui-react';

formatFileSize(document.size, useLocale()); // "248 kB", "248 ko"
fileKind('', 'grades.csv'); // "spreadsheet"
```

## API [#api]

<TypeTable
  type="{
  file: {
    type: 'File | { name: string; size?: number; type?: string; date?: Date | string | number; src?: string }',
    description: 'A picked File, or a stored document. src is a thumbnail or preview URL.',
    required: true,
  },
  status: {
    type: '&#x22;idle&#x22; | &#x22;queued&#x22; | &#x22;uploading&#x22; | &#x22;processing&#x22; | &#x22;done&#x22; | &#x22;error&#x22;',
    description: 'Upload state. Pass it from the first render: the status region exists only with a status.',
  },
  progress: {
    type: 'number',
    description: 'From 0 to 1, read while uploading. Without it, the bar is indeterminate.',
  },
  error: { type: 'ReactNode', description: 'The failure message, shown and announced while status is &#x22;error&#x22;.' },
  announce: {
    type: 'boolean',
    default: 'true',
    description: &#x22;Keep the status region that announces this row's upload. useFileQueue's itemProps pass false: one FileQueueSummary speaks for the queue instead.&#x22;,
  },
  meta: { type: 'ReactNode', description: 'Replaces the size and date on the meta line; the status still follows.' },
  actions: { type: 'ReactNode', description: 'Your buttons, before the retry and remove buttons.' },
  onRemove: { type: '() => void', description: 'Renders the × button. Named as a cancel while the file is queued or in flight, when it calls onCancel if there is one.' },
  onCancel: { type: '() => void', description: 'What the × does while the file is queued or in flight. Falls back to onRemove; alone, the × shows only while there is an upload to stop.' },
  onRetry: { type: '() => void', description: 'Renders a Retry button while status is &#x22;error&#x22;.' },
  disabled: { type: 'boolean', default: 'false', description: &#x22;Disables the row's own buttons.&#x22; },
  thumbnails: {
    type: 'boolean',
    default: 'true',
    description: 'Show image files and src as lazy thumbnails. Off, kind icons only, and no object URLs.',
  },
  icons: {
    type: 'Partial<Record<FileKind | &#x22;remove&#x22; | &#x22;retry&#x22; | &#x22;done&#x22;, ReactNode>>',
    description: 'Replaces the default icons. A key set to undefined keeps its default.',
  },
  translations: {
    type: '{ remove?; cancel?; retry?; queued?; processing?; done?; failed?; announcement? }',
    description: 'remove(name) / cancel(name) name the × button, retry is the Retry text, queued / processing / done / failed the status words, announcement(status, name) what the status region says on each transition. A partial override keeps the other defaults.',
  },
  asChild: { type: 'boolean', description: 'Render the row as your element (an <li>), with the row folded in.' },
  classNames: {
    type: '{ root?, preview?, body?, name?, meta?, progress?, actions?, retry?, remove? }',
    description: 'Per-part class overrides.',
  },
  testId: { type: 'string', description: 'data-testid on the row.' },
}"
/>

## Accessibility [#accessibility]

* The row reads in order: name, size and date, status, then its buttons. The thumbnail or icon is hidden from assistive tech, since the name beside it says the same thing.
* The name is truncated by CSS only: the full name stays in the text screen readers read, and in a `title` for the pointer.
* The × button is named after the file ("Remove cv.pdf"), and "Cancel upload of cv.pdf" while it is queued or in flight. Retry is described by the file name ("Retry, cv.pdf").
* The upload bar is a `role="progressbar"` named after the file, with `aria-valuenow` while uploading; while processing it is indeterminate, with the value text "Processing…". The name and meta column is `aria-busy` meanwhile.
* With a `status`, the row keeps a polite `role="status"` region. It speaks when an upload starts ("Uploading cv.pdf"), ends ("cv.pdf uploaded") or fails ("cv.pdf failed to upload", then your `error`), never for the status the row mounts with and never per progress tick. It sits outside the busy column, so it isn't held back while the column is busy.
* A row fed by a [`useFileQueue`](/docs/hooks/use-file-queue#what-screen-readers-hear) (`{...queue.itemProps(id)}`) has no region: `itemProps` passes `announce: false`, and one `FileQueueSummary` speaks for the whole upload, so 400 rows don't make 800 announcements. Pass `announce` after the spread to bring a row's own back.
* Status is never color alone: done says "Uploaded" next to its check, and an error shows its message.
* RTL follows the locale, through [`IntlProvider`](/docs/intl#text-direction).
