This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
temple/priv/templates/temple.gen.live/live_helpers.ex
2020-06-30 20:43:04 -04:00

23 lines
963 B
Elixir

defmodule <%= inspect context.web_module %>.LiveHelpers do
import Phoenix.LiveView.Helpers
@doc """
Renders a component inside the `<%= inspect context.web_module %>.ModalComponent` component.
The rendered modal receives a `:return_to` option to properly update
the URL when the modal is closed.
## Examples
<%%= live_modal @socket, <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent,
id: @<%= schema.singular %>.id || :new,
action: @live_action,
<%= schema.singular %>: @<%= schema.singular %>,
return_to: Routes.<%= schema.singular %>_index_path(@socket, :index) %>
"""
def live_modal(socket, component, opts) do
path = Keyword.fetch!(opts, :return_to)
modal_opts = [id: :modal, return_to: path, component: component, opts: opts]
live_component(socket, <%= inspect context.web_module %>.ModalComponent, modal_opts)
end
end