- File dropzone
- Examples
- Disabled
- Disabled drag & drop
- Closable
- Hide button
- Button only
- Customizing labels
- No file list
- Maximum file size
- Maximum number of files
- Accepted file types
- Upload files
- Upload method
- Upload headers
- Custom Icon
- Custom Content
- Importing
- Slots
- Properties
- Events
- Custom Properties
- Parts
- Dependencies
File Dropzone
<mo-file-dropzone> | MOFileDropzone
File Dropzone provides an area where files can be dragged and dropped onto from the Operating System to be uploaded or to be used for other tasks. It also provides a button to open a file dialog and select files from the file system. Per default the File Dropzone shows a list of all selected files below the dropzone.
<mo-file-dropzone closable max-files="5"></mo-file-dropzone>
import { MOFileDropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MOFileDropzone closable max-files={5}></MOFileDropzone>;
Examples
Disabled
Set the disabled
attribute to disable the dropzone.
<mo-file-dropzone disabled></mo-file-dropzone>
import { MOFileDropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MOFileDropzone disabled></MOFileDropzone>;
Disabled drag & drop
Set the no-drag
attribute to disable drag and drop.
<mo-file-dropzone no-drag></mo-file-dropzone>
import { MOFileDropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MOFileDropzone no-drag></MOFileDropzone>;
Closable
Set the closable
attribute to enable closing/removing of a file.
<mo-file-dropzone closable></mo-file-dropzone>
import { MOFileDropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MOFileDropzone closable></MOFileDropzone>;
Hide button
Set the no-button
attribute to hide the button in the dropzone.
<mo-file-dropzone no-button></mo-file-dropzone>
import { MOFileDropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MOFileDropzone no-button></MOFileDropzone>;
Button only
Set the button-only
attribute to show only a file input button instead of a dropzone.
<mo-file-dropzone button-only></mo-file-dropzone>
import { MOFileDropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MOFileDropzone button-only></MOFileDropzone>;
Customizing labels
Set the label
and button-label
attribute to override the default labels.
<mo-file-dropzone label="Please combine all documents into one PDF file. The maximum file size is 3MB." button-label="Upload your CV or Resume" ></mo-file-dropzone>
import { MOFileDropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => ( <MOFileDropzone label="Please combine all documents into one PDF file. The maximum file size is 3MB." button-label="Upload your CV or Resume" ></MOFileDropzone> );
No file list
Set the no-file-list
attribute to hide the file list.
<mo-file-dropzone no-file-list></mo-file-dropzone>
import { MODropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MODropzone no-file-list></MODropzone>;
Maximum file size
Set the max-file-size
attribute to set a maximum file size limit. The user will receive a
warning, when the selected file is too large.
<mo-file-dropzone label="Drag and drop to upload (< 10kB)" max-file-size="10000"></mo-file-dropzone>
import { MODropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MODropzone label="Drag and drop to upload (< 10kB)" max-file-size={100}></MODropzone>;
Maximum number of files
Set the max-files
attribute to limit the number of files that can be added.
<mo-file-dropzone label="Drag and drop to upload (max. 2 files)" max-files="2"></mo-file-dropzone>
import { MODropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MODropzone label="Drag and drop to upload (max. 2 files)" max-files={2}></MODropzone>;
Accepted file types
Set the accept
attribute to set the accept MIME-Type of the files. This attribute is consistent
with the native file input. Visit the
MDN documentation for the accept attribute
for more information.
<mo-file-dropzone accept="image/*"></mo-file-dropzone>
import { MODropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MODropzone accept="image/*"></MODropzone>;
Upload files
Set the url
attribute to upload the files to the specified URL.
<mo-file-dropzone url="http://localhost:8080"></mo-file-dropzone>
import { MODropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MODropzone url="http://localhost:8080"></MODropzone>;
Upload method
Set the method
attribute to set the transfer method.
<mo-file-dropzone url="http://localhost:8080" method="PUT"></mo-file-dropzone>
import { MODropzone } from '@metsooutotec/modes-web-components/dist/react'; const App = () => <MODropzone url="http://localhost:8080" method="PUT"></MODropzone>;
Upload headers
Set the headers
property to define specific headers to be used for the file transfer.
<mo-file-dropzone class="dropzone" url="http://localhost:8080"></mo-file-dropzone> <script> const dropzone = document.querySelector('.dropzone'); dropzone.headers = { 'My-Awesome-Header': 'header value' }; </script>
import { MODropzone } from '@metsooutotec/modes-web-components/dist/react'; const headers = { 'My-Awesome-Header': 'header value' }; const App = () => <MODropzone url="http://localhost:8080" headers={headers}></MODropzone>;
Custom Icon
Set the icon
slot to customize the appearance of the icon within the dropzone.
<mo-file-dropzone> <mo-qr-code slot="icon" value="https://www.metso.com/"></mo-qr-code> </mo-file-dropzone>
import { MODropzone, MOQrCode } from '@metsooutotec/modes-web-components/dist/react'; const App = () => ( <MODropzone> <MOQrCode slot="icon" value="https://www.metso.com/" />; </MODropzone> );
Custom Content
Set the content
slot to customize the appearance of the dropzone.
<mo-file-dropzone> <mo-card slot="content" class="card-footer"> This card is a dropzone. You can drag all sorts of things in it! <div slot="footer"> <mo-rating></mo-rating> </div> </mo-card> </mo-file-dropzone> <style> .card-footer { max-width: 300px; } .card-footer [slot='footer'] { display: flex; justify-content: space-between; align-items: center; } </style>
import { MODropzone, MOCard, MORating } from '@metsooutotec/modes-web-components/dist/react'; const css = ` .card-footer { max-width: 300px; } .card-footer [slot="footer"] { display: flex; justify-content: space-between; align-items: center; } `; const App = () => ( <> <MODropzone> <MOCard slot="content" className="card-footer"> This card is a dropzone. You can drag all sorts of things in it! <div slot="footer"> <MORating></MORating> </div> </MOCard> </MODropzone> <style>{css}</style> </> );
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component using a bundler:
import '@metsooutotec/modes-web-components/dist/components/file-dropzone/file-dropzone.js';
To import this component as a React component:
import MOFileDropzone from '@metsooutotec/modes-web-components/dist/react/file-dropzone/';
To import this component using a script tag:
<script type="module" src="https://modes-web.metso.com/dist/components/cdn/components/file-dropzone/file-dropzone.js"></script>
Slots
Name | Description |
---|---|
content
|
The dropzone’s content. Alternatively, you can use the icon slot and label prop. |
icon
|
The dropzone’s icon. |
Learn more about using slots.
Properties
Name | Description | Reflects | Type | Default |
---|---|---|---|---|
warning
|
Internal property to show a warning in the dropzone |
string | undefined
|
- | |
disabled
|
Disables the dropzone. |
|
boolean
|
false
|
noButton
no-button
|
If true, hides button to open the native file selection dialog |
|
boolean
|
false
|
buttonOnly
button-only
|
If true, shows only a button as a file input |
|
boolean
|
false
|
noDrag
no-drag
|
If true, disables drag ‘n’ drop |
|
boolean
|
false
|
noFileList
no-file-list
|
If true, no file list will be shown |
|
boolean
|
false
|
closable
|
Indicates whether file list items are closable |
|
boolean
|
false
|
label
|
An optional overwrite for the upload label |
string | undefined
|
- | |
buttonLabel
button-label
|
An optional overwrite for the preview button label |
string | undefined
|
- | |
lang
|
The locale to render the component in. |
string
|
- | |
accept
|
A string that defines the file types the file dropzone should accept. Defaults to ‘*’ |
|
string
|
'*'
|
maxFileSize
max-file-size
|
An optional maximum size of a file that will be considered valid. |
number | undefined
|
- | |
maxFiles
max-files
|
The maximum amount of files that are allowed. |
number
|
1
|
|
url
|
Specifies a URL where the files should be uploaded to |
string | undefined
|
- | |
method
|
Specifies the method to be used for the file transfer request |
HttpMethod
|
- | |
headers
|
Specifies headers to be used for the file transfer request |
Record
|
- | |
withCredentials
with-credentials
|
Specifies whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates |
|
boolean
|
false
|
binaryBody
binary-body
|
Indicates whether the files should be send as binary data. Per default files will be send as FormData. |
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
Name | React Event | Description | Event Detail |
---|---|---|---|
mo-drop |
onMoDrop |
Emitted when dragged files have been dropped on the dropzone area. | - |
mo-change |
onMoChange |
Emitted when files have been selected via the file dialog. | - |
mo-transfer-load |
onMoTransferLoad |
Emitted when a file transfer was finished |
{ response: unknown }
|
mo-transfer-error |
onMoTransferError |
Emitted when a file transfer threw an error |
{ event: ProgressEvent }
|
mo-transfer-abort |
onMoTransferAbort |
Emitted when a file transfer was aborted by the user |
{ event: ProgressEvent }
|
mo-remove |
onMoRemove |
Emitted when a file was removed |
{ file: FileInfo }
|
Learn more about events.
Custom Properties
Name | Description | Default |
---|---|---|
--border-radius |
The border radius of the dropzone borders. | |
--border-width |
The width of the dropzone borders. | |
--border-style |
The style of the dropzone borders. |
Learn more about customizing CSS custom properties.
Parts
Name | Description |
---|---|
base |
The component’s internal wrapper. |
content |
The dropzone container. |
icon |
The dropzone icon. |
button |
The dropzone button. |
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.