Files
FileUploader
Pick or drop files, validate them, and upload through your own adapter with progress, cancel and retry. Works with any backend — presigned URLs, tus, or a plain POST.
import '@reactloom/files/styles.css';
import { FileUploader, FileDropZone, FileList, useFileUpload } from '@reactloom/files';Examples
Uploader
Demo adapter: progress is simulated. Try a file named “fail.pdf”.
Attachments
Drag files here or
PDF, images or spreadsheets, up to 10 MB each. Name a file “fail…” to try Retry.
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
Drop a photo or
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.
Drag files here or
CSV or Excel
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.
See the code: an adapter is one function from a file to a promise.
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
| Prop | Type | Default |
|---|---|---|
uploadrequiredYour transport. | (file, { signal, onProgress }) => Promise<unknown> | — |
acceptMIME types, wildcards, extensions: image/*,.pdf | string | — |
maxSize · minSizeBytes, per file. | number | — |
maxFilesTotal files; the drop zone disables when reached. | number | — |
multiple | boolean | true |
concurrencyUploads in parallel. | number | 3 |
autoStart | boolean | true |
onStatusChangeCollect uploaded URLs on success. | (item) => void | — |
label · hinthint describes the Browse button. | ReactNode | — |
size | 'sm' | 'md' | 'md' |
messagesOverride any text (translation). | Partial<FileMessages> | — |
renderListCustom list UI. | (queue) => ReactNode | — |
Also exported
| Prop | Type | Default |
|---|---|---|
FileDropZonePicking + validation only. | component | — |
FileListItems with progress and actions. | component | — |
useFileUploadThe 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.
| Attribute | Values |
|---|---|
[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.
| Attribute | Values |
|---|---|
[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.
| Attribute | Values |
|---|---|
[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”).
| Key | Action |
|---|---|
| Tab | Browse button, then each file’s actions |
| Enter / Space | Open 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.