2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.ModalComponent do
|
|
|
|
use LivebookWeb, :live_component
|
2021-02-11 19:42:17 +08:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
|
|
|
~L"""
|
2021-03-20 21:10:15 +08:00
|
|
|
<div class="fixed z-40 inset-0"
|
2021-02-11 19:42:17 +08:00
|
|
|
id="<%= @id %>">
|
|
|
|
|
|
|
|
<!-- Modal container -->
|
|
|
|
<div class="h-screen flex items-center justify-center p-4">
|
|
|
|
<!-- Overlay -->
|
|
|
|
<div class="absolute inset-0 bg-gray-500 opacity-75 z-0"
|
|
|
|
aria-hidden="true"
|
|
|
|
phx-capture-click="close"
|
|
|
|
phx-window-keydown="close"
|
|
|
|
phx-key="escape"
|
|
|
|
phx-target="#<%= @id %>"
|
|
|
|
phx-page-loading></div>
|
|
|
|
|
|
|
|
<!-- Modal box -->
|
2021-03-12 18:57:01 +08:00
|
|
|
<div class="relative max-h-full overflow-y-auto bg-white rounded-lg shadow-xl"
|
2021-02-11 19:42:17 +08:00
|
|
|
role="dialog"
|
|
|
|
aria-modal="true">
|
|
|
|
|
2021-03-12 18:57:01 +08:00
|
|
|
<%= live_patch to: @return_to, class: "absolute top-6 right-6 text-gray-400 flex space-x-1 items-center" do %>
|
|
|
|
<span class="text-sm">(esc)</span>
|
|
|
|
<%= remix_icon("close-line", class: "text-2xl") %>
|
|
|
|
<% end %>
|
|
|
|
|
2021-02-11 19:42:17 +08:00
|
|
|
<%= live_component @socket, @component, @opts %>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def handle_event("close", _params, socket) do
|
|
|
|
{:noreply, push_patch(socket, to: socket.assigns.return_to)}
|
|
|
|
end
|
|
|
|
end
|