defmodule LivebookWeb.LayoutHelpers do use Phoenix.Component import LivebookWeb.LiveHelpers import LivebookWeb.UserHelpers alias Phoenix.LiveView.JS alias LivebookWeb.Router.Helpers, as: Routes @doc """ The layout used in the non-session pages. """ def layout(assigns) do assigns = assign_new(assigns, :topbar_action, fn -> [] end) ~H"""
<.live_region role="alert" /> <.sidebar socket={@socket} current_page={@current_page} current_user={@current_user} saved_hubs={@saved_hubs} />
<.topbar_sidebar_toggle />
<% # TODO: Use render_slot(@topbar_action) || default() on LiveView 0.18 %> <%= if @topbar_action == [] 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(@topbar_action) %> <% end %>
<%= render_slot(@inner_block) %>
<.current_user_modal current_user={@current_user} /> """ end defp topbar_sidebar_toggle(assigns) do ~H"""
""" end defp sidebar(assigns) do ~H""" """ end defp sidebar_link(assigns) do assigns = assign_new(assigns, :icon_style, fn -> nil end) ~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" style={@icon_style} /> <%= @title %> <% end %> """ end defp hub_section(assigns) do ~H""" <%= if Livebook.Config.feature_flag_enabled?(:hub) do %>
HUBS
<%= for hub <- @hubs do %> <.sidebar_link title={hub.name} icon="checkbox-blank-circle-fill" icon_style={"color: #{hub.color}"} to={Routes.hub_path(@socket, :edit, hub.id)} current={@current_page} /> <% end %> <.sidebar_link title="Add Hub" icon="add-line" to={Routes.hub_path(@socket, :new)} current={@current_page} />
<% 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" end