Components
File Upload
NativeA drop area that is also a button, with a list of the chosen files.
Installation
npx nook-ui@latest add file-uploadPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "File Upload" component to this project, exactly as Nook ships it.
A drop area that is also a button, with a list of the chosen files.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add file-upload`. It writes `components/ui/file-upload.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/file-upload.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
import { FileUpload } from "@/components/ui/file-upload";
export default function FileUploadDefault() {
return <FileUpload className="max-w-sm" aria-label="Attachments" name="attachments" multiple accept="image/*,.pdf" maxSize={5 * 1024 * 1024} hint="Images or PDF, up to 5 MB each" />;
}
```
API
- `FileUpload`: The drop area and the list.
- `accept` (`string`): File types to offer, such as "image/*,.pdf".
- `multiple` (`boolean`): Allow more than one file.
- `maxSize` (`number`): The largest file allowed, in bytes.
- `onFilesChange` (`(files: File[]) => void`): Called when the list changes.
- `label` (`string`): The main line in the drop area.
- `hint` (`string`): A second line for the rules.
- `name` (`string`): Name submitted with a form.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: A real file input sits inside the drop area, so it works from the keyboard and in forms. Refused files are explained in an alert. Each file has a labelled remove button.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { FileUpload } from "@/components/ui/file-upload";
export default function FileUploadDefault() {
return <FileUpload className="max-w-sm" aria-label="Attachments" name="attachments" multiple accept="image/*,.pdf" maxSize={5 * 1024 * 1024} hint="Images or PDF, up to 5 MB each" />;
}Examples
Several images with a size limit
One PDF
Disabled
Inside a form
The chosen files are submitted with the form.
Small size limit
Long label and hint
Props
FileUpload
The drop area and the list.
| Prop | Type | Default | Description |
|---|---|---|---|
| accept | string | – | File types to offer, such as "image/*,.pdf". |
| multiple | boolean | – | Allow more than one file. |
| maxSize | number | – | The largest file allowed, in bytes. |
| onFilesChange | (files: File[]) => void | – | Called when the list changes. |
| label | string | – | The main line in the drop area. |
| hint | string | – | A second line for the rules. |
| name | string | – | Name submitted with a form. |
Accessibility
A real file input sits inside the drop area, so it works from the keyboard and in forms. Refused files are explained in an alert. Each file has a labelled remove button.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.