shift73k/lib/shift73k_web/live/modal_component.ex

46 lines
1.1 KiB
Elixir
Raw Permalink Normal View History

2021-03-05 19:23:32 -05:00
defmodule Shift73kWeb.ModalComponent do
use Shift73kWeb, :live_component
2020-09-14 12:22:25 -04:00
@impl true
def render(assigns) do
~H"""
<div id={@id} class="modal fade"
phx-hook="BsModal"
phx-window-keydown="hide"
2020-09-14 12:22:25 -04:00
phx-key="escape"
phx-target={"#" <> to_string(@id)}
2020-09-14 12:22:25 -04:00
phx-page-loading>
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= Keyword.get(@opts, :title, "Modal title") %></h5>
<button type="button" class="btn-close" phx-click="hide" phx-target={@myself} aria-label="Close"></button>
</div>
<%= live_component @component, Keyword.put(@opts, :modal_id, @id) %>
</div>
2020-09-14 12:22:25 -04:00
</div>
</div>
"""
end
@impl true
def update(assigns, socket) do
socket |> assign(assigns) |> live_okreply()
end
2020-09-14 12:22:25 -04:00
@impl true
def handle_event("close", _, socket) do
send(self(), {:close_modal, true})
live_noreply(socket)
2020-09-14 12:22:25 -04:00
end
@impl true
def handle_event("hide", _, socket) do
socket |> push_event("modal-please-hide", %{}) |> live_noreply()
end
2020-09-14 12:22:25 -04:00
end