Examples

Uploader

Demo adapter: progress is simulated. Try a file named “fail.pdf”.

Preview

Attachments

Drag files here or

PDF, images or spreadsheets, up to 10 MB each. Name a file “fail…” to try Retry.

Example.tsx
import { FileUploader } from '@reactloom/files';
import { demoUpload } from './demo-adapter';

export default function Example() {
  return (
    <div style={{ width: '100%', maxWidth: 520 }}>
      <FileUploader
        label="Attachments"
        hint="PDF, images or spreadsheets, up to 10 MB each. Name a file “fail…” to try Retry."
        accept="image/*,.pdf,.xlsx,.csv"
        maxSize={10_000_000}
        upload={demoUpload}
      />
    </div>
  );
}

Single file, compact

Preview

Drop a photo or

Example.tsx
import { FileUploader } from '@reactloom/files';
import { demoUpload } from './demo-adapter';

export default function Example() {
  return (
    <div style={{ width: '100%', maxWidth: 520 }}>
      <FileUploader size="sm" multiple={false} maxFiles={1} accept="image/*" upload={demoUpload} messages={{ browse: 'Choose a photo', dropHere: 'Drop a photo or' }} />
    </div>
  );
}

Compose your own

FileDropZone + useFileUpload + FileList, without the built-in layout.

Preview

Drag files here or

CSV or Excel

Example.tsx
import { FileDropZone, FileList, useFileUpload } from '@reactloom/files';
import { Stack } from '@reactloom/ui';
import { demoUpload } from './demo-adapter';

// Build your own layout from the pieces: the drop zone, the headless queue and the list.
export default function Example() {
  const queue = useFileUpload({ upload: demoUpload, concurrency: 2 });
  return (
    <Stack gap="3" style={{ width: '100%', maxWidth: 520 }}>
      <FileDropZone size="sm" accept=".csv,.xlsx" hint="CSV or Excel" onFilesAccepted={queue.add} />
      <FileList items={queue.items} onCancel={queue.cancel} onRetry={queue.retry} onRemove={queue.remove} aria-label="Imports" />
    </Stack>
  );
}

Writing an adapter

Receives an AbortSignal and a progress callback; resolve or reject.

Preview

See the code: an adapter is one function from a file to a promise.

Example.tsx
import type { UploadAdapter } from '@reactloom/files';

// A real adapter with XMLHttpRequest (fetch cannot report upload progress yet).
export const xhrUpload: UploadAdapter = (file, { signal, onProgress }) =>
  new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.open('POST', '/api/uploads');
    xhr.upload.onprogress = (e) => e.lengthComputable && onProgress(e.loaded / e.total);
    xhr.onload = () => (xhr.status < 300 ? resolve(JSON.parse(xhr.responseText)) : reject(new Error(xhr.statusText)));
    xhr.onerror = () => reject(new Error('Network error'));
    signal.addEventListener('abort', () => xhr.abort());
    const body = new FormData();
    body.append('file', file);
    xhr.send(body);
  });

export default function Example() {
  return <p style={{ margin: 0 }}>See the code: an adapter is one function from a file to a promise.</p>;
}

API reference

FileUploader props

FileUploader props
PropTypeDefault
uploadrequired
Your transport.
(file, { signal, onProgress }) => Promise<unknown>—
accept
MIME types, wildcards, extensions: image/*,.pdf
string—
maxSize · minSize
Bytes, per file.
number—
maxFiles
Total files; the drop zone disables when reached.
number—
multiple
booleantrue
concurrency
Uploads in parallel.
number3
autoStart
booleantrue
onStatusChange
Collect uploaded URLs on success.
(item) => void—
label · hint
hint describes the Browse button.
ReactNode—
size
'sm' | 'md''md'
messages
Override any text (translation).
Partial<FileMessages>—
renderList
Custom list UI.
(queue) => ReactNode—

Also exported

Also exported
PropTypeDefault
FileDropZone
Picking + validation only.
component—
FileList
Items with progress and actions.
component—
useFileUpload
The queue without UI.
hook—
validateFiles · matchesAccept · formatBytes
functions—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

FileUploader

Renders FileDropZone, so its hooks apply too.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-disabled]present when on
[data-dragging]present when on
[data-size]sm · md

Theme tokens it reads

--pl-color-accent-fg --pl-color-accent-solid --pl-color-accent-subtle --pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-input --pl-color-danger-fg --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-font-size-sm --pl-font-size-xs --pl-radius-lg

FileDropZone

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-disabled]present when on
[data-dragging]present when on
[data-size]sm · md

Theme tokens it reads

--pl-color-accent-fg --pl-color-accent-solid --pl-color-accent-subtle --pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-input --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-font-size-sm --pl-font-size-xs --pl-radius-lg

FileList

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-status]present when on

Theme tokens it reads

--pl-color-bg-surface --pl-color-border-default --pl-color-danger-border --pl-color-danger-fg --pl-color-fg-default --pl-color-fg-muted --pl-color-success-fg --pl-font-size-sm --pl-font-size-xs --pl-radius-md

Accessibility

  • A real file input behind a Browse button: keyboard, screen readers, mobile pickers and camera capture all work. Drag and drop is an enhancement.
  • Added, rejected, uploaded and failed files are announced politely; rejections are also shown in text.
  • Every action names its file (“Retry upload of report.pdf”).
Keyboard interactions
KeyAction
TabBrowse button, then each file’s actions
Enter / SpaceOpen the file dialog or run an action

Usage guidelines

Do

  • State the limits (types, size) in hint, before people pick files.
  • Validate again on the server — client checks are for feedback.

Don’t

  • Don’t make drag and drop the only way to add files.