MediaBrowser LiveComponent — embeddable media management UI.
Provides a full media browser with folder navigation, file upload, search, and selection tools. Operates in two modes:
- Uncontrolled (default): all navigation state is owned internally. No URL sync.
- Controlled (opt-in): when
on_navigateis set to a truthy value, navigation events (navigate_folder,search,clear_search,set_page) emit{PhoenixKitWeb.Components.MediaBrowser, id, {:navigate, params}}to the parent LiveView process instead of mutating local state. The parent must callpush_patchand feed URL params back viasend_updatewith a:nav_paramskey.
Enabling uploads
The fastest path is the Embed helper — one use line gives you
uploads, the validate-channel stub, and the message delegator:
defmodule MyAppWeb.MediaPage do
use MyAppWeb, :live_view
use PhoenixKitWeb.Components.MediaBrowser.Embed
endManual setup (if you prefer explicit wiring) is three calls:
def mount(_params, _session, socket) do
{:ok, PhoenixKitWeb.Components.MediaBrowser.setup_uploads(socket)}
end
def handle_event("validate", _params, socket), do: {:noreply, socket}
def handle_info({__MODULE__, _, _} = msg, socket) do
PhoenixKitWeb.Components.MediaBrowser.handle_parent_info(msg, socket)
endUsage (uncontrolled)
<.live_component
module={PhoenixKitWeb.Components.MediaBrowser}
id="media-browser"
phoenix_kit_current_user={@phoenix_kit_current_user}
/>Usage (controlled — URL-sync driven by parent)
<.live_component
module={PhoenixKitWeb.Components.MediaBrowser}
id="media-browser"
phoenix_kit_current_user={@phoenix_kit_current_user}
on_navigate={true}
/>The parent LiveView must implement:
def handle_info({PhoenixKitWeb.Components.MediaBrowser, "media-browser",
{:navigate, params}}, socket) do
# push_patch to update URL, handle_params will send_update back
endRequired attributes
id— unique DOM id (required by LiveComponent)
Optional attributes
phoenix_kit_current_user— logged-in user struct (for upload attribution)scope_folder_id— constrain the browser to a virtual root folderon_navigate— when truthy, enables controlled mode (URL-sync via parent)admin— whentrue, clicking a file opens the admin detail page at/admin/media/:uuid. Whenfalse(default), clicks toggle selection instead, so the component behaves as a picker when embedded outside the admin UI.
Summary
Functions
Callback implementation for Phoenix.LiveComponent.handle_event/3.
Catch-all handler for parent LiveViews to delegate MediaBrowser messages.
Callback implementation for Phoenix.LiveComponent.render/1.
Handles the upload setup message from the MediaBrowser component.
Callback implementation for Phoenix.LiveComponent.update/2.
Functions
Attributes
node(:map) (required)current_folder(:any) (required)expanded_folders(:any) (required)renaming_folder(:any) (required)renaming_text(:string) - Defaults to"".show_new_folder(:boolean) - Defaults tofalse.renaming_source(:any) (required)depth(:integer) - Defaults to0.myself(:any) (required)
Callback implementation for Phoenix.LiveComponent.handle_event/3.
Catch-all handler for parent LiveViews to delegate MediaBrowser messages.
Attributes
node(:map) (required)depth(:integer) - Defaults to0.myself(:any) (required)
Callback implementation for Phoenix.LiveComponent.render/1.
Handles the upload setup message from the MediaBrowser component.
Parent LiveViews embedding MediaBrowser should add this to their handle_info:
def handle_info({PhoenixKitWeb.Components.MediaBrowser, _id, :setup_uploads}, socket) do
{:noreply, PhoenixKitWeb.Components.MediaBrowser.setup_uploads(socket)}
endOr use the catch-all delegator:
def handle_info({PhoenixKitWeb.Components.MediaBrowser, _, _} = msg, socket) do
PhoenixKitWeb.Components.MediaBrowser.handle_parent_info(msg, socket)
end
Callback implementation for Phoenix.LiveComponent.update/2.