Components

File Upload

Takes files from a drop zone, the system picker or a paste, checks them, and hands them to your app to upload.

Usage

import {
  FileUpload,
  FileUploadDescription,
  FileUploadDropzone,
  FileUploadIcon,
  FileUploadTitle,
  FileUploadTrigger,
} from 'nyctoui/file-upload'

<FileUpload multiple maxSize={10_000_000} onValueChange={(files) => upload(files)}>
  <FileUploadDropzone>
    <FileUploadIcon />
    <FileUploadTitle>Drop files here or click to browse</FileUploadTitle>
    <FileUploadDescription>Up to 10 MB each</FileUploadDescription>
    <FileUploadTrigger>Choose files</FileUploadTrigger>
  </FileUploadDropzone>
</FileUpload>

FileUpload holds the files and checks them; it doesn’t send them anywhere. The drop zone is its empty state. It shows no file details of its own: draw each file with an Attachment, which shows the name, size, upload progress and errors, so the two never repeat each other.

Good for

  • Attaching files to a message or a support ticket.
  • Uploading a profile photo or a company logo in settings.
  • Importing a CSV of contacts into a CRM.
  • Adding receipts to an expense report, with a drop zone.

Examples

With attachments

The demo at the top of the page. The app keeps an upload per file, with its progress and status, and passes the files back as a controlled value, so maxFiles counts the files already there. Each file is drawn as an Attachment inside a FileUploadItem, which makes the list one Tab stop: the arrow keys move between files and Delete removes one. Progress here is simulated, and every third file fails once so the retry shows.

Message composer

The plain drop zone draws nothing until files are dragged over it, so it can wrap a composer. With pasteTarget, files pasted into the text area attach too, and text pastes stay text. Attachments sit above the message as cards and Send waits for them to finish.

Validation

accept, maxFiles and maxSize check every file, however it arrives. Rejected files never join the value; read them from onReject and show them as Attachments with status="error". A function as the drop zone’s children gets its drag state, here to warn while files that won’t be accepted are over it.

Button only

A trigger alone opens the picker. Without multiple, a new file replaces the one held. A function as the root’s children gets the files.

Disabled

A disabled file upload ignores drops and pastes, and its trigger can’t be focused.

Best practices

Do
  • Set accept to the file types that work, so the system picker shows only those.
  • Set maxSize and maxFiles, and say the limits in FileUploadDescription.
  • Show each chosen file as an attachment with its progress and a remove button.
  • Handle onReject and say why a file was turned away: too large, wrong type, too many.
Don’t
  • Leave out the drop zone when there’s room for it. Dragging files in is what people try first.
  • Use it for one short text value. An input is enough.

API reference

FileUpload

Wraps ui-sdk’s FileInput and takes its props, including name, required, validate and directory. Its children can be a function of its state.

PropTypeDefault
multiple
Holds more than one file. Without it, a new file replaces the one held.
booleanfalse
accept
MIME types, wildcards and extensions to accept, such as image/* and .pdf.
string | string[]—
maxFiles
The most files held at once.
number—
maxSize
The largest file accepted, in bytes.
number—
value
The files, to control the upload.
File[]—
defaultValue
The files at first, when uncontrolled.
File[]—
onValueChange
Runs when files are added or removed. details has the added and removed files.
(value: File[], details) => void—
onReject
Runs with each file that failed the checks, and its reasons.
(rejected: FileRejection[]) => void—
disabled
Ignores drops, pastes and the trigger.
booleanfalse
controller
Opens the picker, adds or removes files from anywhere. Create one with createFileUploadController().
FileUploadController—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadDropzone

Where files are dropped or pasted. Sets data-dragging, data-drag-accept and data-drag-reject; its children can be a function of that state.

PropTypeDefault
variant
dashed is a drop area of its own; plain shows only while files are dragged over, to wrap other content.
'dashed' | 'plain''dashed'
openOnClick
Opens the picker on a press anywhere in the zone that isn’t on a control.
booleantrue for dashed
pasteTarget
Another place to take pasted files from, such as a text area.
'document' | Element | string | () => Element—
target
Takes files dropped anywhere on the page.
'document'—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadIcon

A 32px tile above the title. Decorative.

PropTypeDefault
children
A 16px icon.
ReactNodeupload arrow
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadTitle

A <p> saying what to do.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadDescription

A <p> saying what’s accepted.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadTrigger

A Button that opens the file picker. Keep one inside every drop zone for keyboard users.

PropTypeDefault
variant
Button treatment.
ButtonVariant'secondary'
size
Button height.
'sm' | 'md' | 'lg''sm'
iconOnly
Square for a single icon. Pass an aria-label.
booleanfalse
controller
Connects a trigger outside the FileUpload.
FileUploadController—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadList

The files, one item each, as a single Tab stop. Name it with an aria-label.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadItem

One file in the list. Its children can be a function of { file, index }.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FileUploadItemRemove

An AttachmentRemove that removes its item’s file, named for the file and out of the Tab order.