Skip to content

Upload ​

File uploads by drag and drop or from the file picker.

Drop files here

JPEG or PNG up to 5 MB, five photos at most

Your upload function sends each file to the server:

ts
type NuiUploadAdapter<R> = ( file: File, context: { onProgress: (fraction: number) => void; signal: AbortSignal },) => Promise<R>;

Report the uploaded share from 0 to 1 to onProgress, and pass signal to fetch so a canceled file stops its request. The returned value becomes the result of the file in the model.

Installation ​

ts
import { NuiUpload } from '@numior/kit';

Usage ​

Add a few photos, then change the look of the field and the layout of the files.

Drop files here

The first photo goes on the product card

layout
Shows the files as a list of rows or a grid of thumbnails.
variant
zone for an area that accepts dragged files, button for a browse button only.
size
Changes the size of the control: sm, md or lg. The theme density shifts the height of each size.

Label of the control. Inside NuiField the field provides the label.

Hint below the control. Screen readers announce it with the control.

Error text below the control. Puts the control into the error state.

Examples ​

Show thumbnails ​

Set layout="grid".

Drop photos here

Up to eight photos, the first one becomes the card cover

An image shows as a thumbnail as soon as it is picked, before the upload ends. Files that are already on the server take the thumbnail from their url.

Upload on a button press ​

Turn off auto and start the upload yourself.

Drop files here

Check the list, then press Upload

Picked files wait in the queued status until you call start() on the component ref.

Keep only a button ​

Set variant="button".

A CSV table with SKUs and quantities

Such a field takes no dropped files, and the file list stays below the button.

Upload an avatar ​

Use NuiAvatarUpload.

PNG or JPEG up to 2 MB

Click the avatar or drop an image on it to replace the photo. A file that fails the checks shows the reason and leaves the current photo in place.

Behavior ​

  • Each file goes through the checks: the type against accept, the size against maxSize, the count against maxFiles, then your validate. A rejected file stays in the list with the reason, and with rejected="drop" it never gets there.
  • At most concurrency files upload at once, and the rest wait in the queue.
  • Canceling stops the request through signal and takes the file off the list. A failed upload gets a retry button that sends the same file again.
  • Removing a file emits remove, so delete an uploaded file on the server in its handler. With :multiple="false" a new file takes the place of the old one, and disabled blocks both adding and removing.

Accessibility ​

A click anywhere in the zone opens the file picker, and on the keyboard the browse button does the same. The label, the hint and the error are linked to that button.

Each row shows the upload progress, and a screen reader announces when a file is uploaded or fails. The cancel, retry and remove buttons have names for screen readers.

Keys
Action
↵
On the browse button, opens the file picker.
Space
On the browse button, opens the file picker.

API ​

Props

Name
Type
Default
Description
uploadrequired
NuiUploadAdapter<R>
—
Function that sends the file to the server. Receives the File, onProgress and signal, returns a promise with the response.
accept
string
—
Files to accept: extensions, types or masks, such as .pdf,image/*.
multiple
boolean
true
Lets the user add several files. Without it, a new file replaces the previous one.
maxSize
number
—
Largest file size in bytes, such as 5_000_000.
maxFiles
number
—
Total number of files allowed, counting those already added.
validate
((file: File) => string | undefined)
—
Custom file check. Returns an error text, or undefined when the file is fine.
rejected
NuiUploadRejected
"list"
What to do with rejected files: list shows them with the reason, drop discards them.
auto
boolean
true
Starts uploading right after the files are chosen. Turn it off to queue them until start is called.
concurrency
number
3
Number of files that upload at the same time.
layout
NuiUploadLayout
"list"
Shows the files as a list of rows or a grid of thumbnails.
variant
NuiUploadVariant
"zone"
zone for an area that accepts dragged files, button for a browse button only.
dropLabel
string
—
Drop zone text. Defaults to "Drop files here" from the dictionary.
browseLabel
string
—
Browse button text. Defaults to "Choose files" from the dictionary.
cancelLabel
string
—
Cancel button label for screen readers. Defaults to "Cancel upload".
retryLabel
string
—
Retry button label for screen readers. Defaults to "Retry" from the dictionary.
removeLabel
string
—
Remove button label for screen readers. Defaults to "Remove" from the dictionary.
doneLabel
string
—
Status of an uploaded file. Defaults to "Uploaded" from the dictionary.
errorLabel
((error: UploadError, item: NuiUploadItem<R>) => string)
—
Function that builds the error text from the reason and the file.
id
string
—
Id of the control. Defaults to the one from NuiField or is generated automatically.
size
NuiSize
"md"
Changes the size of the control: sm, md or lg. The theme density shifts the height of each size.
disabled
boolean
—
Disables the control. Inside NuiField it defaults to the field value.
readonly
boolean
—
Prevents changes to the value, which stays selectable and copyable. Inside NuiField it defaults to the field value.
required
boolean
—
Marks the control as required. Inside NuiField it defaults to the field value.
invalid
boolean
—
Shows the error state without a text. With error it turns on by itself.
label
string
—
Label of the control. Inside NuiField the field provides the label.
description
string
—
Hint below the control. Screen readers announce it with the control.
error
string
—
Error text below the control. Puts the control into the error state.
reserveError
boolean
false
Reserves space for the error so the form does not shift when it appears.

Models

Name
Type
Default
Description
v-model
NuiUploadItem<R>[]
[]
List of files, each with a status: queued, uploading, done or error.

Events

Name
Payload
Description
done
[item: NuiUploadItem<R>]
Fires when a file is uploaded, with the file and the server response.
error
[item: NuiUploadItem<R>]
Fires when an upload fails, with the file and the error.
reject
[rejections: FileRejection[]]
Fires when a file fails a check, with the file and the reason.
remove
[item: NuiUploadItem<R>]
Fires when a file is removed from the list.

Slots

Name
Slot props
Description
button
{}
Button content when variant is button.
default
{ open: () => void; dragging: boolean; }
Custom zone content. Receives open and dragging.
item
{ item: NuiUploadItem<R>; preview: string | undefined; cancel: () => void; retry: () => void; remove: () => void; }
Custom file row markup. Receives item, preview and the cancel, retry and remove actions.

Texts

Key
Russian
English
browse
Выбрать файлы
Choose files
cancel
Отменить загрузку
Cancel upload
changeImage
Сменить изображение
Change the image
chooseImage
Выбрать изображение
Choose an image
done
Загружено
Uploaded
drop
Перетащите файлы сюда
Drop files here
failed
Не удалось загрузить
Upload failed
largerThan
({ size }) => `Файл больше ${size}`
({ size }) => `Larger than ${size}`
moreThan
({ count }) => `Не больше ${count} ${plural('ru', count, { one: 'файла', few: 'файлов', many: 'файлов', other: 'файла' })}`
({ count }) => `More than ${count} ${plural('en', count, { one: 'file', other: 'files' })}`
rejected
Файл отклонён
File rejected
remove
Удалить
Remove
removeImage
Удалить изображение
Remove the image
retry
Повторить
Retry
tooLarge
Файл слишком большой
File is too large
tooMany
Слишком много файлов
Too many files
typeError
Неподдерживаемый тип файла
Unsupported file type

Props

Name
Type
Default
Description
uploadrequired
NuiUploadAdapter<R>
—
Function that sends the file to the server. Receives the File, onProgress and signal, returns a promise with the response.
accept
string
"image/*"
Image types to accept. Defaults to image/*.
maxSize
number
—
Largest file size in bytes, such as 5_000_000.
validate
((file: File) => string | undefined)
—
Custom file check. Returns an error text, or undefined when the file is fine.
name
string
—
Name of the person. Its initials show until an image is set.
shape
NuiAvatarShape
"circle"
Shape of the avatar: circle or square.
size
NuiAvatarSize
"xl"
Size of the avatar: sm, md, lg or xl.
chooseLabel
string
—
Button label while there is no image. Defaults to "Choose an image".
changeLabel
string
—
Button label when an image is set. Defaults to "Change the image".
retryLabel
string
—
Retry button label for screen readers. Defaults to "Retry" from the dictionary.
removeLabel
string
—
Remove button label for screen readers. Defaults to "Remove the image".
errorLabel
((error: UploadError, item: NuiUploadItem<R>) => string)
—
Function that builds the error text from the reason and the file.
disabled
boolean
—
Disables the control. Inside NuiField it defaults to the field value.
error
string
—
Error text below the control. Puts the control into the error state.
label
string
—
Label of the control. Inside NuiField the field provides the label.
required
boolean
—
Marks the control as required. Inside NuiField it defaults to the field value.
id
string
—
Id of the control. Defaults to the one from NuiField or is generated automatically.
description
string
—
Hint below the control. Screen readers announce it with the control.
invalid
boolean
—
Shows the error state without a text. With error it turns on by itself.
readonly
boolean
—
Prevents changes to the value, which stays selectable and copyable. Inside NuiField it defaults to the field value.
reserveError
boolean
false
Reserves space for the error so the form does not shift when it appears.

Models

Name
Type
Default
Description
v-model
NuiUploadItem<R> | null
null
The image with its upload status, or null.

Events

Name
Payload
Description
done
[item: NuiUploadItem<R>]
Fires when the image is uploaded.
error
[item: NuiUploadItem<R>]
Fires when the image upload fails.
reject
[error: UploadError]
Fires when the file fails a check, with the reason.
remove
[item: NuiUploadItem<R>]
Fires when the image is removed.

Texts

Key
Russian
English
browse
Выбрать файлы
Choose files
cancel
Отменить загрузку
Cancel upload
changeImage
Сменить изображение
Change the image
chooseImage
Выбрать изображение
Choose an image
done
Загружено
Uploaded
drop
Перетащите файлы сюда
Drop files here
failed
Не удалось загрузить
Upload failed
largerThan
({ size }) => `Файл больше ${size}`
({ size }) => `Larger than ${size}`
moreThan
({ count }) => `Не больше ${count} ${plural('ru', count, { one: 'файла', few: 'файлов', many: 'файлов', other: 'файла' })}`
({ count }) => `More than ${count} ${plural('en', count, { one: 'file', other: 'files' })}`
rejected
Файл отклонён
File rejected
remove
Удалить
Remove
removeImage
Удалить изображение
Remove the image
retry
Повторить
Retry
tooLarge
Файл слишком большой
File is too large
tooMany
Слишком много файлов
Too many files
typeError
Неподдерживаемый тип файла
Unsupported file type

Edit this page

Search

Esc