Dropzone
Capture files from user with drag and drop
Source
Docs
Package
License
Installation
After installation import package styles at the root of your application:
Usage
Dropzone lets you capture one or more files from user.
Component is based on react-dropzone and support all of its core features:
- Accepts/rejects files based on provided mime types
- Limits individual file size
- Renders given children and provides context based component to display elements based on current status
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
Dropzone.Accept, Dropzone.Reject and Dropzone.Idle
Dropzone.Accept, Dropzone.Reject and Dropzone.Idle components are visible only when the user performs certain action:
Dropzone.Acceptis visible only when the user drags file that can be accepted over the dropzoneDropzone.Rejectis visible only when the user drags file that cannot be accepted over the dropzoneDropzone.Idleis visible when the user does not drag anything over dropzone
Loading state
Set loading prop to indicate loading state with LoadingOverlay component.
When loading props is true user cannot drop or select new files (Dropzone becomes disabled):
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
Disabled state
If you want to implement your own loading state you can disable Dropzone without LoadingOverlay.
Same as with loading, when Dropzone is disabled user cannot drop or select new files:
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
Open file browser manually
To open files browser from outside of component use openRef prop to get function that will trigger file browser:
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
Enable child pointer event
By default, Dropzone disables pointer events on its children for dragging events to work. When activateOnClick={false},
clicking on any children inside Dropzone will not do anything.
However, you can set style pointerEvents: 'all' to make children clickable.
Note that you need to set these styles only on interactive elements, such as buttons or links.
Mime types
To specify file types provide an object with the keys set to the mime type and the values as an array of file extensions. Find more examples of accepting specific file types in the react-dropzone documentation.
You can also specify file types by providing an array of mime types to accept prop:
To save some research time you can use MIME_TYPES variable exported from @mantine/dropzone:
MIME_TYPES includes following data:
Additionally you can use grouped mime types:
Styles API
Dropzone root element has the following data attributes to change styles based on current status:
data-loading– whenloadingprop istruedata-accept– when user drags files that can be accepted over the dropzonedata-reject– when user drags files that cannot be accepted over the dropzonedata-idle– default state – user does not drag any files over dropzone
Drop images here
Images previews
Drop images here
Get ref
Dropzone.FullScreen component
Dropzone.FullScreen lets you capture files dropped to browser window instead of specific area.
It supports the same props as Dropzone component.
To preview component click button and drop images to browser window: