Hoppa till huvudinnehåll

FileUpload

Filuppladdning, filväljare

Komponent som används när användaren behöver ladda upp filer från det egna filsystemet.

import { FileUpload } from '@midas-ds/components'
<FileUpload
label='Välj en fil att ladda upp'
description='Du kan välja en fil'
/>
Du kan välja en fil

Varianter

Välj flera filer

För att tillåta användaren att ladda upp flera filer på samma gång, använd attributet allowsMultiple

<FileUpload
allowsMultiple
label='Välj filer att ladda upp'
description='Du kan välja flera filer'
/>
Du kan välja flera filer

Kontrollerat val av filer

Om du vill kontrollera vilka filer användaren laddar upp kan du använda useState

import React from 'react'
const [files, setFiles] = React.useState<string[]>([])

return (
<FileUpload
allowsMultiple
label='Välj filer att ladda upp'
description='Du kan välja flera filer'
onSelect={e => {
if (e) {
const files = Array.from(e)
const filenames = files.map(file => file.name)
setFiles(filenames)
}
}}
/>
)
Du kan välja flera filer
Valda filer:

API

NameTypeDefaultDescription
labelstring-

Label for the file upload button

descriptionstring-

Additional description field

dropzone-

Use DropZone version

popoverInfoPopoverProps-

An assistive text that helps the user understand the field better. Will be hidden in a popover with an info icon button.

acceptedFileTypesstring[]-

Specifies what mime type of files are allowed.

allowsMultiple-

Whether multiple files can be selected.

defaultCamera-

Specifies the use of a media capture mechanism to capture the media on the spot.

children-

The children of the component. A function may be provided to alter the children based on component state.

acceptDirectory-

Enables the selection of directories instead of individual files.