PhoenixKitDocumentCreator.Web.Components.ImagePicker (PhoenixKitDocumentCreator v0.4.0)

Copy Markdown View Source

Generic image picker LiveComponent.

Inputs (assigns):

  • :id — required
  • :picker_id — required String.t(); echoed back to the host in every change message so a single LiveView can host multiple pickers
  • :scope_type — opaque string (used by the host to resolve files)
  • :scope_id — opaque string (used by the host to resolve files)
  • :mode:single or :list
  • :current_selection[file_uuid] (OPTIONAL). Selection mode contract:
    • If the host wants to control selection externally, it MUST echo back the latest selection on every render (e.g. on receipt of the :image_picker_changed message). Otherwise an unrelated host re-render would clobber internal state.
    • If the host omits :current_selection, the component manages selection internally via assign_new/2 (default []).
  • :files[%{uuid: String.t(), name: String.t(), url: String.t()}] provided by the host (host resolves storage scope to files)

Output: on selection change the component calls send(self(), {:image_picker_changed, picker_id, selection}) The host LiveView must implement handle_info({:image_picker_changed, _, _}, socket).