File uploads built on LiveView uploads: the drop panel with each file's progress, errors and cancel button, and the styled "Choose File" button.
# mount
socket |> allow_upload(:photos, accept: ~w(.jpg .png), max_entries: 4)
<.form for={@form} phx-change="validate" phx-submit="save">
<.upload upload={@uploads.photos} on_cancel="cancel-upload" columns={2}
hint="PDF, XML ou CSV · até 10 MB cada" />
</.form>
def handle_event("cancel-upload", %{"ref" => ref}, socket),
do: {:noreply, cancel_upload(socket, :photos, ref)}upload/1 renders live_file_input itself, so it must sit inside the form that has the
phx-change LiveView uploads need. Dropping files on the panel works through phx-drop-target;
the LedgerUI.Upload hook (priv/static/ledger_ui/hooks/upload.js) only paints the over
state while files are dragged over it.
The pieces it is made of are public and stateless, for custom layouts and for the design
gallery: upload_drop/1 (the dashed drop area), upload_zone/1 (the compact zone with the
kit's variants), upload_file/1 (a file card), upload_thumbs/1 and upload_button/1.
Deviation from the README: upload_button/1 is a <label> around the file input (as the
README says), so the design's <button> is not reproduced byte for byte; variant accepts the
design's zone variants too (solid glow outline soft bordered flat glass dim).
Summary
Functions
Renders the drop panel and the list of chosen files.
A button that opens the file chooser: a <label> with the button classes holding an invisible
file input. With upload it renders live_file_input; otherwise a plain <input type="file">.
The dashed drop area: icon, label with the browse link, and a hint.
A file card: badge, name, status, progress bar and the remove (or retry) button.
The grid of 64px thumbnails.
The compact drop zone (lu-upz) with the kit's variants, colors, shapes and sizes.
Functions
Renders the drop panel and the list of chosen files.
Attributes
upload(Phoenix.LiveView.UploadConfig) (required)id(:string) - Defaults tonil.bordered(:boolean) - Defaults tofalse.filled(:boolean) - Defaults tofalse.columns(:integer) - Defaults to1. Must be one of1,2,3, or4.variant(:string) - Defaults to"canvas". Must be one of"canvas","pond","solid","glow","outline","soft","bordered","flat","glass", or"dim".color(:string) - Defaults to"primary". Must be one of"neutral","primary","secondary","info","success","warning","error","mono","white", or"current".shape(:string) - Defaults to"rounded". Must be one of"rounded","pill", or"square".size(:string) - Defaults tonil.Must be one ofnil,"md", or"xl".layout(:string) - Defaults to"panel". Must be one of"panel","circle", or"thumbs".hint(:string) - Defaults tonil.browse(:string) - Defaults tonil.icon_path(:string) - Defaults tonil.drop_class(:any) - Defaults tonil.on_cancel(:any) - Defaults tonil.target(:any) - Defaults tonil.previews(:boolean) - Defaults totrue.error_texts(:map) - Defaults to%{too_large: "File is too large", too_many_files: "Too many files", external_client_failure: "Upload failed", not_accepted: "File of invalid type"}.browse_label(:string) - Defaults to"Browse".drop_label(:string) - Defaults to"Drag & Drop your files or".remove_label(:string) - Defaults to"Remove".uploading_label(:string) - Defaults to"Uploading".complete_label(:string) - Defaults to"Upload complete".class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
label- Replaces the text of the drop panel.
A button that opens the file chooser: a <label> with the button classes holding an invisible
file input. With upload it renders live_file_input; otherwise a plain <input type="file">.
<.upload_button upload={@uploads.avatar}>Choose File</.upload_button>
<.upload_button name="doc" variant="outline" size="sm">Attach</.upload_button>Attributes
upload(Phoenix.LiveView.UploadConfig) - Defaults tonil.name(:string) - Defaults tonil.multiple(:boolean) - Defaults tofalse.accept(:string) - Defaults tonil.disabled(:boolean) - Defaults tofalse.color(:string) - Defaults to"neutral". Must be one of"neutral","primary","secondary","info","success","warning","error","mono","white", or"current".variant(:string) - Defaults to"solid". Must be one of"solid","glow","outline","soft","bordered","flat","glass","ghost", or"dim".size(:string) - Defaults tonil.Must be one ofnil,"","xs","sm","md","lg", or"xl".shape(:string) - Defaults to"rounded". Must be one of"rounded","pill", or"square".icon(:boolean) - Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
The dashed drop area: icon, label with the browse link, and a hint.
Attributes
drop_label(:string) - Defaults to"Drag & Drop your files or".browse_label(:string) - Defaults to"Browse".hint(:string) - Defaults tonil.over(:boolean) - Draws the drag-over state. Defaults tofalse.error(:boolean) - Defaults tofalse.for(:string) - Id of the file input: the area becomes its<label>. Defaults tonil.icon_path(:string) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
label- Replaces the text of the area.
A file card: badge, name, status, progress bar and the remove (or retry) button.
Attributes
name(:string) (required)ext(:string) - The badge text (XML); the extension ofnameby default. Defaults tonil.status(:string) - The line under the name. Defaults tonil.progress(:integer) - Defaults to0.state(:string) - Defaults to"progress". Must be one of"progress","done", or"error".remove_label(:string) - Defaults to"Remove".retry_label(:string) - On an error: a retry button with this text. Defaults tonil.removable(:boolean) - Defaults totrue.on_remove(:any) - An event name or a%JS{}for the remove button. Defaults tonil.on_retry(:any) - Defaults tonil.ref(:string) - Sent asphx-value-refwith the events. Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
preview- Replaces the extension badge (an image preview).
The grid of 64px thumbnails.
Attributes
count(:integer) - Defaults to3.columns(:integer) ---cols(3 by default in the stylesheet). Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block- Your own tiles instead ofcountplaceholders.
The compact drop zone (lu-upz) with the kit's variants, colors, shapes and sizes.
Attributes
variant(:string) - Defaults to"canvas". Must be one of"canvas","pond","solid","glow","outline","soft","bordered","flat","glass", or"dim".color(:string) - Defaults to"primary". Must be one of"neutral","primary","secondary","info","success","warning","error","mono","white", or"current".shape(:string) - Defaults to"rounded". Must be one of"rounded","pill", or"square".size(:string) - Defaults tonil.Must be one ofnil,"md", or"xl".for(:string) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)