Dropzone

A file upload that supports dragging and dropping.

Preview
Code

Basic Example

<script>
	import { Dropzone, DropzoneInput } from 'lithesome';

	let files = $state([]);
</script>

<Dropzone bind:files>
	<DropzoneInput />
</Dropzone>

{#each files as file}
	<p>{file.name}</p>
{/each}

API Reference

<Dropzone />

PropertyTypeDescription
files File[]

The current accepted files of the dropzone.

multiple boolean

Allow for more than 1 file to be present at once.

maxSize number

The maximum size of the file to be added. If the provided file is above this number, the `onError` callback will be fired.

accept string

The types of files allowed to be added. If the provided file does not match these requirements, the `onError` callback will be fired.

disabled boolean

Disables the entire component from firing events.

validate (file: File, files: File[]) => boolean

Custom validation for each file picked. For the file to pass this validation, the return statement must be truthy.

onError (data: DropzoneErrorEvents) => void

If any errors are found through `allowed`, `maxSize` props, or the custom `validation` callback,\ this callback will be fired with the related type of error, file, and depending on the error, some extra information.

onSuccess (file: File) => void

If no errors were found during validation, this callback will be fired.

onChange (files: File[]) => void

When files are successfully added or removed to the `files` prop, this event will be fired.

ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
draggingbooleanTrue if the dropzone is currently being hovered with a file.
errorsbooleanTrue if any validation errors are found.

<DropzoneInput />

PropertyTypeDescription
ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.