defmodule LivebookWeb.SidebarHelpers do
use Phoenix.Component
import LivebookWeb.LiveHelpers
import LivebookWeb.UserHelpers
alias Phoenix.LiveView.JS
alias LivebookWeb.Router.Helpers, as: Routes
@doc """
Renders the mobile toggle for the sidebar.
"""
def toggle(assigns) do
assigns = assign_new(assigns, :inner_block, fn -> [] end)
~H"""
<% # TODO: Use render_slot(@inner_block) || default() on LiveView 0.18 %>
<%= if @inner_block == [] do %>
<%= live_redirect to: Routes.home_path(@socket, :page), class: "flex items-center", aria: [label: "go to home"] do %>
<.remix_icon icon="home-6-line" />
Home
<% end %>
<% else %>
<%= render_slot(@inner_block) %>
<% end %>
"""
end
@doc """
Renders sidebar container.
"""
def sidebar(assigns) do
~H"""
"""
end
defp sidebar_link(assigns) do
~H"""
<%= live_redirect to: @to, class: "h-7 flex items-center hover:text-white #{sidebar_link_text_color(@to, @current)} border-l-4 #{sidebar_link_border_color(@to, @current)} hover:border-white" do %>
<.remix_icon icon={@icon} class="text-lg leading-6 w-[56px] flex justify-center" />
<%= @title %>
<% end %>
"""
end
defp sidebar_link_text_color(to, current) when to == current, do: "text-white"
defp sidebar_link_text_color(_to, _current), do: "text-gray-400"
defp sidebar_link_border_color(to, current) when to == current, do: "border-white"
defp sidebar_link_border_color(_to, _current), do: "border-transparent"
def sidebar_handlers(socket) do
if Livebook.Config.shutdown_enabled?() do
attach_hook(socket, :shutdown, :handle_event, fn
"shutdown", _params, socket ->
System.stop()
{:halt, put_flash(socket, :info, "Livebook is shutting down. You can close this page.")}
_event, _params, socket ->
{:cont, socket}
end)
else
socket
end
end
end