Search documentation of phoenix_kit

# PhoenixKitWeb.Live.Components.MediaSelectorModal (phoenix_kit v1.6.19)

View Source

Media selector modal component.

A reusable modal component for selecting media files from anywhere in the admin panel. Supports both single and multiple selection modes.

## Usage

    # In parent LiveView, add to socket assigns
    socket
    |> assign(:show_media_selector, false)
    |> assign(:media_selection_mode, :single)
    |> assign(:media_selected_ids, [])

    # In template (IMPORTANT: Must pass phoenix_kit_current_user for uploads to work)
    <.live_component
      module={PhoenixKitWeb.Live.Components.MediaSelectorModal}
      id="media-selector-modal"
      show={@show_media_selector}
      mode={@media_selection_mode}
      selected_ids={@media_selected_ids}
      phoenix_kit_current_user={@phoenix_kit_current_user}
    />

    # To open the modal
    def handle_event("open_media_selector", _params, socket) do
      {:noreply, assign(socket, :show_media_selector, true)}
    end

    # To receive selected media
    def handle_info({:media_selected, file_ids}, socket) do
      # Handle the selected file IDs
      {:noreply, socket |> assign(:gallery_ids, file_ids)}
    end

# Summary

## Functions

handle_event(binary, arg2, socket)

Callback implementation for `Phoenix.LiveComponent.handle_event/3`.

render(assigns)

Callback implementation for `Phoenix.LiveComponent.render/1`.

update(assigns, socket)

Callback implementation for `Phoenix.LiveComponent.update/2`.

# Functions

# handle_event(binary, arg2, socket)

Callback implementation for `Phoenix.LiveComponent.handle_event/3`.

# render(assigns)

Callback implementation for `Phoenix.LiveComponent.render/1`.

# update(assigns, socket)

Callback implementation for `Phoenix.LiveComponent.update/2`.