The place to drop a file: a dashed area with an icon, what it takes and the limits. It wraps a LiveView
upload (allow_upload/3), so the same area takes a drop and a click, and highlights while a file is
over it (DevactionUI.Dropzone hook). What went wrong with a file is shown under it, from errors, tied to
the file field with aria-describedby, and the errors of the upload itself (upload_errors/1, such as too
many files) are added to them, written with the texts of error_labels.
The limits the browser already knows are in the upload config: limits_label (such as
"%{types} · up to %{size}") writes them as the hint, from the accept list and the max_file_size of the
upload, so they cannot drift from what is enforced; limits/1 and size_text/1 give the pieces to write
them by hand. The accept list also goes to the file input, so the file picker filters by it.
The files chosen are listed under the area. By default each is a row with the name, a DevactionUI.Progress
bar that fills as it goes up, its own errors (upload_errors/2) and, with cancel_event, a button that
removes it (the event gets phx-value-ref, to call cancel_upload/3). To draw the row yourself give the
entry slot, which gets the Phoenix.LiveView.UploadEntry; the cancel button is still added beside it.
over_label is announced politely while a file is dragged over the area, so the state is not only colour.
queue/1 is the same drop area with a gridded face and, under it, the whole queue: one row per file with its
state (sent, uploading, stopped, waiting, refused), a progress bar, the size, a "Try again" button for a file that
stopped and a button that cancels or removes it, above a summary line with a "Clear finished" action. The rows
come from the entries of a LiveView upload (upload) or, for a queue of your own, from plain maps (entries).
Summary
Functions
The limits of an upload as text: types (such as .txt, .mp3; blank for any) and size (such as 200 MB).
A size in bytes as text in decimal units, such as 200 MB or 1.5 KB.
Functions
Attributes
id(:string) (required)upload(Phoenix.LiveView.UploadConfig) (required)title(:string) (required) - what to drop, e.g.Drop the transcript or the audio.hint(:string) - what it takes, e.g..mp3, .m4a, .txt · up to 200 MB. Defaults tonil.limits_label(:string) - the hint written from the upload's own limits when there is nohint;%{types}and%{size}are filled in, as in"%{types} · up to %{size}". Defaults tonil.errors(:list) - messages about the files, already translated. Defaults to[].error_labels(:map) - the text of each upload error (%{too_large: "Too large", not_accepted: "Not accepted", too_many_files: "Too many"}); an error with no text shows its name. Defaults to%{}.disabled(:boolean) - takes neither a click nor a drop. Defaults tofalse.over_label(:string) - announced while a file is dragged over the area, such asDrop to upload. Defaults tonil.cancel_event(:string) - shows a button on each file that sends this event withphx-value-ref, forcancel_upload/3. Defaults tonil.cancel_label(:string) - names the cancel button of a file, as in"Remove %{name}". Defaults tonil.target(:any) - aphx-target(a@myself) when used inside a LiveComponent. Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
icon- the upload icon, drawn by the caller; it gets a box of 22px.cancel_icon- replaces the typographic × of the cancel button.entry- one chosen file, drawn by the caller instead of the default row; gets theUploadEntry, withprogressfrom 0 to 100.
@spec limits(Phoenix.LiveView.UploadConfig.t()) :: %{ types: String.t(), size: String.t() }
The limits of an upload as text: types (such as .txt, .mp3; blank for any) and size (such as 200 MB).
Attributes
id(:string) (required)upload(Phoenix.LiveView.UploadConfig) - the upload whoseentriesare the rows, and whose input takes the click and the drop; leave it out for a queue of your own. Defaults tonil.entries(:list) - the rows when there is noupload: maps withnameand, as they apply,ref,size(bytes or text),progress(0 to 100),state(:sent,:uploading,:failed,:queuedor:rejected),message(replaces the state's text) andhint(replaces the line under a refused file). Defaults to[].failed(:list) - therefs of the upload entries that stopped (LiveView does not know a connection dropped; the server does). Defaults to[].title(:string) (required) - what to drop, e.g.Drop files or click to choose.hint(:string) - what it takes, e.g.PDF, PNG or JPG · up to 25 MB each. Defaults tonil.over_title(:string) - replaces the title while a file is over the area, e.g.Release to upload. Defaults tonil.over_hint(:string) - replaces the hint while a file is over the area, e.g.3 files · 4.2 MB. Defaults tonil.dragging(:boolean) - draws the area as if a file were over it (for a page that shows the state). Defaults tofalse.summary(:string) - the line over the rows, written by the caller:5 files · 1 uploading · 1 with an error. Defaults tonil.clear_label(:string) - the action beside the summary, e.g.Clear finished; it shows withclear_event. Defaults tonil.labels(:map) (required) - the words of the rows, by key:sent,uploading(uploading · %{size}),queued,failed,stopped(stopped at %{percent}%),rejected,rejected_hint,retry,cancelandremove(Cancel %{name},Remove %{name}).error_labels(:map) - the text of each upload error, as indropzone/1; the text of a refused file comes from here. Defaults to%{}.retry_event(:any) - sent withphx-value-refby the button of a stopped file: a string or a%JS{}. Defaults tonil.cancel_event(:any) - sent withphx-value-refby the button that cancels a file that is not sent and removes one that is (cancel_upload/3). Defaults tonil.clear_event(:any) - sent by the clear action. Defaults tonil.target(:any) - aphx-target(a@myself) when used inside a LiveComponent. Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
icon- the upload icon in the box of the area; it gets 22px.retry_icon- before the text of the retry button; a↻when empty.cancel_icon- the icon of the cancel button; a×when empty.remove_icon- the icon of the remove button of a sent file; a×when empty.
@spec size_text(non_neg_integer()) :: String.t()
A size in bytes as text in decimal units, such as 200 MB or 1.5 KB.