Forms & Inputs
Dropzone
Where files are dropped or picked — a signed lease, photographs of a meter, a bank statement. It checks each file against accept, max-size and max-files as it arrives, keeps those that pass and says plainly why the others were turned away.
The kept files submit with the form under name. Show them with
nana-file, listening for nana-change, and call removeFile() when one
is taken out.
The zone is a button: Enter or Space opens the file browser, so it works without a mouse.
Preview
Section titled “Preview”Drop a PDF or a photograph, or press the zone to browse. Anything larger than 5 MB, or of another type, is turned away with the reason.
<div
style="
display: flex;
flex-direction: column;
gap: 0.75rem;
width: 100%;
max-width: 28rem;
"
>
<nana-dropzone
id="evidence"
label="Evidence for the deposit claim"
name="evidence"
multiple
accept=".pdf,image/*"
max-size="5242880"
max-files="4"
></nana-dropzone>
<div
id="evidence-files"
style="display: flex; flex-direction: column; gap: 0.5rem"
></div>
</div> <script lang="ts">
import { NanaDropzone } from '$lib/components/ui/dropzone';
import { NanaFile } from '$lib/components/ui/file';
let files = $state<NanaFile[]>([]);
</script>
<div class="flex w-full max-w-md flex-col gap-3">
<NanaDropzone
label="Meter photographs"
name="photos"
accept="image/*,.pdf"
maxSize={10_000_000}
multiple
maxFiles={3}
bind:files
/>
{#each files as file (file.name)}
<NanaFile
name={file.name}
size={file.size}
type={file.type}
removable
noDownload
onRemove={() => (files = files.filter((kept) => kept !== file))}
/>
{/each}
</div> Installation
Section titled “Installation”npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add dropzone --framework web-componentsnpx @nana-tec/ui add dropzone --framework svelteLands in src/lib/components/ui/dropzone/ as NanaDropzone.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/dropzone";
Copied in with npx @nana-tec/ui add dropzone? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<nana-dropzone label="Signed lease" name="lease" accept=".pdf" max-size="10485760"></nana-dropzone>const el = document.querySelector("nana-dropzone");el.addEventListener("nana-change", (e) => console.log(e.detail));<script lang="ts"> import { NanaDropzone } from '$lib/components/ui/dropzone';
let files = $state<File[]>([]);</script>
<NanaDropzone label="Signed lease" name="lease" accept=".pdf" maxSize={10_485_760} bind:files />Each file is checked against accept, maxSize and maxFiles as it arrives; those that
pass are kept in files, and the zone says plainly why any others were turned away. The kept
files submit with the form under name. Remove one by writing files without it. The zone is
a button: Enter or Space opens the file browser.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
accept | accept | string | '' | File types to take, as on <input type="file">: .pdf, image/*, application/pdf |
disabled | disabled | boolean | false | Blocks dropping and browsing. |
helperText | helper-text | string | '' | Help below the zone |
invalid | invalid | boolean | false | Marks the drop area invalid. |
label | label | string | '' | Label above the zone |
maxFiles | max-files | number | undefined | — | Most files to hold at once |
maxSize | max-size | number | undefined | — | Largest file to take, in bytes |
multiple | multiple | boolean | false | Take more than one file |
name | name | string | '' | Name the value is submitted under in a form. |
required | required | boolean | false | The form will not submit while this has no value. |
value | value | string | — | The names of the kept files; set it to '' to clear them |
Methods
| Method | Description |
|---|---|
addFiles(files: Iterable<File>): void | Offer files as if they had been dropped |
browse(): void | Open the file browser |
clear(): void | Take every file out |
removeFile(file: File): void | Take a file out |
Events
| Event | Description |
|---|---|
nana-change | The kept files changed (detail.files, and detail.rejected for any turned away) |
Slots
| Slot | Description |
|---|---|
(default) | The prompt inside the zone |
CSS parts
| Part | Description |
|---|---|
::part(base) | The field |
::part(zone) | The area files are dropped on |
::part(hint) | The line naming what is accepted |
::part(errors) | The reasons files were turned away |
::part(label) | The label |
::part(req) | The required marker |
::part(icon) | The icon |
::part(prompt) | The prompt |
::part(browse) | The browse |
::part(help) | The help |
::part(error) | One reason a file was turned away |
CSS custom properties
| Property | Description |
|---|---|
--nana-dropzone-accent | The colour of the zone while a file is over it |
--nana-dropzone-bg | The zone's background |
NanaDropzone
| Prop | Type | Default |
|---|---|---|
filesbind: | File[] | [] |
name | string | |
accept | string | '' |
multiple | boolean | false |
maxSize | number | |
maxFiles | number | |
label | string | |
helperText | string | |
required | boolean | false |
disabled | boolean | false |
children | Snippet | |
onFilesChange | (files: File[], rejected: DropzoneRejected[]) => void |
Also accepts Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>.