MishkaGervaz.Form.Entities.Upload (MishkaGervaz v0.0.1-alpha.3)

Copy Markdown View Source

File upload configuration — accept rules, count and size limits, plus optional dropzone text and preview UI.

An upload entity is paired with a field :name, :upload of the matching name, which binds the LiveView upload config to the rendered control. Three rendering styles are supported (:dropzone, :file_input, :custom), and external uploaders / chunked transports / custom upload writers are all available for production workloads.

Example

uploads do
  upload :cover do
    accept "image/*"
    max_entries 1
    max_file_size 5_000_000
    show_preview true
    auto_upload true
    dropzone_text "Drop image here"

    ui do
      label "Cover Image"
      icon "hero-photo"
      preview_class "w-32 h-32"
    end
  end
end

See MishkaGervaz.Form.Dsl.Uploads for the surrounding section and MishkaGervaz.Form.Entities.Upload.Ui for the ui sub-entity.

Summary

Functions

Transform the upload after DSL compilation.

Types

t()

@type t() :: %MishkaGervaz.Form.Entities.Upload{
  __identifier__: term(),
  __spark_metadata__: map() | nil,
  accept: String.t() | [String.t()] | nil,
  auto_upload: boolean(),
  chunk_size: pos_integer() | nil,
  chunk_timeout: pos_integer() | nil,
  dropzone_text: String.t() | (-> String.t()) | nil,
  existing: atom() | (map() -> list()) | nil,
  external: (map(), Phoenix.LiveView.Socket.t() -> any()) | atom() | nil,
  field: atom() | nil,
  max_entries: pos_integer(),
  max_file_size: pos_integer(),
  name: atom(),
  show_preview: boolean(),
  style: :dropzone | :file_input | :custom,
  ui: MishkaGervaz.Form.Entities.Upload.Ui.t() | nil,
  writer: atom() | nil
}

Functions

transform(upload)

Transform the upload after DSL compilation.

Extracts the nested ui entity from the list wrapper.