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
|
|
|
|
~L"""
|
2021-03-03 16:07:59 -05:00
|
|
|
<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="#<%= @id %>"
|
|
|
|
phx-page-loading>
|
|
|
|
|
2021-03-05 15:32:01 -05:00
|
|
|
<div class="modal-dialog modal-dialog-centered">
|
2021-03-03 16:07:59 -05:00
|
|
|
<div class="modal-content">
|
|
|
|
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title"><%= Keyword.get(@opts, :title, "Modal title") %></h5>
|
2021-03-19 16:38:52 -04:00
|
|
|
<button type="button" class="btn-close" phx-click="hide" phx-target="<%= @myself %>" aria-label="Close"></button>
|
2021-03-03 16:07:59 -05:00
|
|
|
</div>
|
|
|
|
|
2021-03-19 16:38:52 -04:00
|
|
|
<%= live_component @socket, @component, Keyword.put(@opts, :modal_id, @id) %>
|
2021-03-03 16:07:59 -05:00
|
|
|
|
|
|
|
</div>
|
2020-09-14 12:22:25 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-03-19 16:38:52 -04:00
|
|
|
@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
|
2021-03-04 22:03:27 -05:00
|
|
|
send(self(), {:close_modal, true})
|
|
|
|
live_noreply(socket)
|
2020-09-14 12:22:25 -04:00
|
|
|
end
|
2021-03-03 16:07:59 -05:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def handle_event("hide", _, socket) do
|
2021-03-19 16:38:52 -04:00
|
|
|
socket |> push_event("modal-please-hide", %{}) |> live_noreply()
|
2021-03-03 16:07:59 -05:00
|
|
|
end
|
2020-09-14 12:22:25 -04:00
|
|
|
end
|