diff --git a/lib/phoenix_component.ex b/lib/phoenix_component.ex index 1e3f7fc918..5f753798fd 100644 --- a/lib/phoenix_component.ex +++ b/lib/phoenix_component.ex @@ -2582,6 +2582,46 @@ defmodule Phoenix.Component do raise ArgumentError, "missing required :entry attribute to <.live_img_preview/>" end + @doc """ + Generates a video preview on the client for a selected file. + + ## Examples + + ```heex + <%= for entry <- @uploads.avatar.entries do %> + <.live_video_preview entry={entry} width="400" /> + <% end %> + ``` + """ + @doc type: :component + def live_video_preview(assigns) + + # attr :entry, Phoenix.LiveView.UploadEntry, required: true + # attr :rest, :global + def live_video_preview(%{entry: %Phoenix.LiveView.UploadEntry{ref: ref} = entry} = assigns) do + rest = + assigns + |> assigns_to_attributes([:entry]) + |> Keyword.put_new_lazy(:id, fn -> "phx-preview-#{ref}" end) + + assigns = assign(assigns, entry: entry, ref: ref, rest: rest) + + ~H""" +